| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_ | 5 #ifndef NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_ |
| 6 #define NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_ | 6 #define NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // Using the provided PrefDelegate, NetworkQualitiesPrefsManager creates and | 36 // Using the provided PrefDelegate, NetworkQualitiesPrefsManager creates and |
| 37 // updates network quality information that is stored in prefs. Instances of | 37 // updates network quality information that is stored in prefs. Instances of |
| 38 // this class must be constructed on the pref thread, and should later be moved | 38 // this class must be constructed on the pref thread, and should later be moved |
| 39 // to the network thread by calling InitializeOnNetworkThread. | 39 // to the network thread by calling InitializeOnNetworkThread. |
| 40 // | 40 // |
| 41 // This class interacts with both the pref thread and the network thread, and | 41 // This class interacts with both the pref thread and the network thread, and |
| 42 // propagates network quality pref changes from the network thread to the | 42 // propagates network quality pref changes from the network thread to the |
| 43 // provided pref delegate on the pref thread. | 43 // provided pref delegate on the pref thread. |
| 44 // | 44 // |
| 45 // ShutdownOnPrefThread must be called from the pref thread before destruction. | 45 // ShutdownOnPrefSequence must be called from the pref thread before |
| 46 // destruction. |
| 46 class NET_EXPORT NetworkQualitiesPrefsManager | 47 class NET_EXPORT NetworkQualitiesPrefsManager |
| 47 : public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver { | 48 : public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver { |
| 48 public: | 49 public: |
| 49 // Provides an interface that must be implemented by the embedder. | 50 // Provides an interface that must be implemented by the embedder. |
| 50 class NET_EXPORT PrefDelegate { | 51 class NET_EXPORT PrefDelegate { |
| 51 public: | 52 public: |
| 52 virtual ~PrefDelegate() {} | 53 virtual ~PrefDelegate() {} |
| 53 | 54 |
| 54 // Sets the persistent pref to the given value. | 55 // Sets the persistent pref to the given value. |
| 55 virtual void SetDictionaryValue(const base::DictionaryValue& value) = 0; | 56 virtual void SetDictionaryValue(const base::DictionaryValue& value) = 0; |
| 56 | 57 |
| 57 // Returns a copy of the persistent prefs. | 58 // Returns a copy of the persistent prefs. |
| 58 virtual std::unique_ptr<base::DictionaryValue> GetDictionaryValue() = 0; | 59 virtual std::unique_ptr<base::DictionaryValue> GetDictionaryValue() = 0; |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 // Creates an instance of the NetworkQualitiesPrefsManager. Ownership of | 62 // Creates an instance of the NetworkQualitiesPrefsManager. Ownership of |
| 62 // |pref_delegate| is taken by this class. Must be constructed on the pref | 63 // |pref_delegate| is taken by this class. Must be constructed on the pref |
| 63 // thread, and then moved to network thread. | 64 // thread, and then moved to network thread. |
| 64 explicit NetworkQualitiesPrefsManager( | 65 explicit NetworkQualitiesPrefsManager( |
| 65 std::unique_ptr<PrefDelegate> pref_delegate); | 66 std::unique_ptr<PrefDelegate> pref_delegate); |
| 66 ~NetworkQualitiesPrefsManager() override; | 67 ~NetworkQualitiesPrefsManager() override; |
| 67 | 68 |
| 68 // Initialize on the Network thread. | 69 // Initialize on the Network thread. |
| 69 void InitializeOnNetworkThread( | 70 void InitializeOnNetworkThread( |
| 70 NetworkQualityEstimator* network_quality_estimator); | 71 NetworkQualityEstimator* network_quality_estimator); |
| 71 | 72 |
| 72 // Prepare for shutdown. Must be called on the pref thread before destruction. | 73 // Prepare for shutdown. Must be called on the pref thread before destruction. |
| 73 void ShutdownOnPrefThread(); | 74 void ShutdownOnPrefSequence(); |
| 74 | 75 |
| 75 // Clear the network quality estimator prefs. | 76 // Clear the network quality estimator prefs. |
| 76 void ClearPrefs(); | 77 void ClearPrefs(); |
| 77 | 78 |
| 78 // Reads the prefs again, parses them into a map of NetworkIDs and | 79 // Reads the prefs again, parses them into a map of NetworkIDs and |
| 79 // CachedNetworkQualities, and returns the map. | 80 // CachedNetworkQualities, and returns the map. |
| 80 ParsedPrefs ForceReadPrefsForTesting() const; | 81 ParsedPrefs ForceReadPrefsForTesting() const; |
| 81 | 82 |
| 82 private: | 83 private: |
| 83 // Pref thread members: | 84 // Pref thread members: |
| 84 // Called on pref thread when there is a change in the cached network quality. | 85 // Called on pref thread when there is a change in the cached network quality. |
| 85 void OnChangeInCachedNetworkQualityOnPrefThread( | 86 void OnChangeInCachedNetworkQualityOnPrefSequence( |
| 86 const nqe::internal::NetworkID& network_id, | 87 const nqe::internal::NetworkID& network_id, |
| 87 const nqe::internal::CachedNetworkQuality& cached_network_quality); | 88 const nqe::internal::CachedNetworkQuality& cached_network_quality); |
| 88 | 89 |
| 89 // Responsible for writing the persistent prefs to the disk. | 90 // Responsible for writing the persistent prefs to the disk. |
| 90 std::unique_ptr<PrefDelegate> pref_delegate_; | 91 std::unique_ptr<PrefDelegate> pref_delegate_; |
| 91 | 92 |
| 92 scoped_refptr<base::SequencedTaskRunner> pref_task_runner_; | 93 scoped_refptr<base::SequencedTaskRunner> pref_task_runner_; |
| 93 | 94 |
| 94 // Current prefs on the disk. Should be accessed only on the pref thread. | 95 // Current prefs on the disk. Should be accessed only on the pref thread. |
| 95 std::unique_ptr<base::DictionaryValue> prefs_; | 96 std::unique_ptr<base::DictionaryValue> prefs_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 115 | 116 |
| 116 // Used to get |weak_ptr_| to self on the pref thread. | 117 // Used to get |weak_ptr_| to self on the pref thread. |
| 117 base::WeakPtrFactory<NetworkQualitiesPrefsManager> pref_weak_ptr_factory_; | 118 base::WeakPtrFactory<NetworkQualitiesPrefsManager> pref_weak_ptr_factory_; |
| 118 | 119 |
| 119 DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesPrefsManager); | 120 DISALLOW_COPY_AND_ASSIGN(NetworkQualitiesPrefsManager); |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 } // namespace net | 123 } // namespace net |
| 123 | 124 |
| 124 #endif // NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_ | 125 #endif // NET_NQE_NETWORK_QUALITIES_PREFS_MANAGER_H_ |
| OLD | NEW |