network_qualities_pref_delegate.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_NETWORK_NETWORK_QUALITIES_PREF_DELEGATE_H_
  5. #define SERVICES_NETWORK_NETWORK_QUALITIES_PREF_DELEGATE_H_
  6. #include <map>
  7. #include "base/component_export.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "base/sequence_checker.h"
  11. #include "net/nqe/cached_network_quality.h"
  12. #include "net/nqe/network_id.h"
  13. #include "net/nqe/network_qualities_prefs_manager.h"
  14. namespace net {
  15. class NetworkQualityEstimator;
  16. }
  17. class PrefRegistrySimple;
  18. class PrefService;
  19. namespace network {
  20. // UI service to manage storage of network quality prefs.
  21. class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkQualitiesPrefDelegate {
  22. public:
  23. NetworkQualitiesPrefDelegate(
  24. PrefService* pref_service,
  25. net::NetworkQualityEstimator* network_quality_estimator);
  26. NetworkQualitiesPrefDelegate(const NetworkQualitiesPrefDelegate&) = delete;
  27. NetworkQualitiesPrefDelegate& operator=(const NetworkQualitiesPrefDelegate&) =
  28. delete;
  29. ~NetworkQualitiesPrefDelegate();
  30. // Registers the profile-specific network quality estimator prefs.
  31. static void RegisterPrefs(PrefRegistrySimple* registry);
  32. // Clear the network quality estimator prefs.
  33. void ClearPrefs();
  34. // Reads the prefs from the disk, parses them into a map of NetworkIDs and
  35. // CachedNetworkQualities, and returns the map.
  36. std::map<net::nqe::internal::NetworkID,
  37. net::nqe::internal::CachedNetworkQuality>
  38. ForceReadPrefsForTesting() const;
  39. private:
  40. // Called when pref service is initialized.
  41. void OnPrefServiceInitialized(bool success);
  42. // Prefs manager that is owned by this service. Created on the UI thread, but
  43. // used and deleted on the IO thread.
  44. net::NetworkQualitiesPrefsManager prefs_manager_;
  45. // Guaranteed to be non-null during the lifetime of |this|.
  46. raw_ptr<net::NetworkQualityEstimator> network_quality_estimator_;
  47. SEQUENCE_CHECKER(sequence_checker_);
  48. base::WeakPtrFactory<NetworkQualitiesPrefDelegate> weak_ptr_factory_{this};
  49. };
  50. } // namespace network
  51. #endif // SERVICES_NETWORK_NETWORK_QUALITIES_PREF_DELEGATE_H_