OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ | 5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ |
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ | 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/prefs/pref_change_registrar.h" | |
19 #include "base/timer/timer.h" | 18 #include "base/timer/timer.h" |
20 #include "base/values.h" | 19 #include "base/values.h" |
21 #include "net/base/host_port_pair.h" | 20 #include "net/base/host_port_pair.h" |
22 #include "net/http/http_server_properties.h" | 21 #include "net/http/http_server_properties.h" |
23 #include "net/http/http_server_properties_impl.h" | 22 #include "net/http/http_server_properties_impl.h" |
24 | 23 |
25 class PrefService; | 24 class PrefService; |
26 | 25 |
27 namespace base { | 26 namespace base { |
28 class SequencedTaskRunner; | 27 class SequencedTaskRunner; |
(...skipping 18 matching lines...) Expand all Loading... |
47 // release the prefs listeners on the pref thread. | 46 // release the prefs listeners on the pref thread. |
48 // | 47 // |
49 // Class requires that update tasks from the Pref thread can post safely to the | 48 // Class requires that update tasks from the Pref thread can post safely to the |
50 // network thread, so the destruction order must guarantee that if |this| | 49 // network thread, so the destruction order must guarantee that if |this| |
51 // exists in pref thread, then a potential destruction on network thread will | 50 // exists in pref thread, then a potential destruction on network thread will |
52 // come after any task posted to network thread from that method on pref thread. | 51 // come after any task posted to network thread from that method on pref thread. |
53 // This is used to go through network thread before the actual update starts, | 52 // This is used to go through network thread before the actual update starts, |
54 // and grab a WeakPtr. | 53 // and grab a WeakPtr. |
55 class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties { | 54 class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties { |
56 public: | 55 public: |
57 // Create an instance of the HttpServerPropertiesManager. The lifetime of the | 56 // Provides an interface to interface with persistent preferences storage |
58 // PrefService objects must be longer than that of the | 57 // implemented by the embedder. |
59 // HttpServerPropertiesManager object. Must be constructed on the Pref thread. | 58 class NET_EXPORT PrefDelegate { |
| 59 public: |
| 60 virtual ~PrefDelegate(); |
| 61 |
| 62 // Returns true if the pref system has data for the server properties. |
| 63 virtual bool HasServerProperties() = 0; |
| 64 |
| 65 // Returns the branch of the preferences system for the server properties. |
| 66 virtual const base::DictionaryValue& GetServerProperties() const = 0; |
| 67 |
| 68 // Sets the server properties to the given value. |
| 69 virtual void SetServerProperties(const base::DictionaryValue& value) = 0; |
| 70 |
| 71 // Start and stop listening for external storage changes. There will only |
| 72 // be one callback active at a time. |
| 73 virtual void StartListeningForUpdates(const base::Closure& callback) = 0; |
| 74 virtual void StopListeningForUpdates() = 0; |
| 75 }; |
| 76 |
| 77 // Create an instance of the HttpServerPropertiesManager. |
| 78 // |
| 79 // Ownership of the PrefDelegate pointer is taken by this class. This is |
| 80 // passed as a raw pointer rather than a scoped_refptr currently because |
| 81 // the test uses gmock and it doesn't forward move semantics properly. |
| 82 // |
| 83 // Must be constructed on the Pref thread. |
60 HttpServerPropertiesManager( | 84 HttpServerPropertiesManager( |
61 PrefService* pref_service, | 85 PrefDelegate* pref_delegate, |
62 const char* pref_path, | |
63 scoped_refptr<base::SequencedTaskRunner> network_task_runner); | 86 scoped_refptr<base::SequencedTaskRunner> network_task_runner); |
64 ~HttpServerPropertiesManager() override; | 87 ~HttpServerPropertiesManager() override; |
65 | 88 |
66 // Initialize on Network thread. | 89 // Initialize on Network thread. |
67 void InitializeOnNetworkThread(); | 90 void InitializeOnNetworkThread(); |
68 | 91 |
69 // Prepare for shutdown. Must be called on the Pref thread before destruction. | 92 // Prepare for shutdown. Must be called on the Pref thread before destruction. |
70 void ShutdownOnPrefThread(); | 93 void ShutdownOnPrefThread(); |
71 | 94 |
72 // Helper function for unit tests to set the version in the dictionary. | 95 // Helper function for unit tests to set the version in the dictionary. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Pref thread | 293 // Pref thread |
271 // ----------- | 294 // ----------- |
272 | 295 |
273 const scoped_refptr<base::SequencedTaskRunner> pref_task_runner_; | 296 const scoped_refptr<base::SequencedTaskRunner> pref_task_runner_; |
274 | 297 |
275 base::WeakPtr<HttpServerPropertiesManager> pref_weak_ptr_; | 298 base::WeakPtr<HttpServerPropertiesManager> pref_weak_ptr_; |
276 | 299 |
277 // Used to post cache update tasks. | 300 // Used to post cache update tasks. |
278 scoped_ptr<base::OneShotTimer> pref_cache_update_timer_; | 301 scoped_ptr<base::OneShotTimer> pref_cache_update_timer_; |
279 | 302 |
280 // Used to track the spdy servers changes. | 303 scoped_ptr<PrefDelegate> pref_delegate_; |
281 PrefChangeRegistrar pref_change_registrar_; | |
282 PrefService* pref_service_; // Weak. | |
283 bool setting_prefs_; | 304 bool setting_prefs_; |
284 const char* path_; | |
285 | 305 |
286 // -------------- | 306 // -------------- |
287 // Network thread | 307 // Network thread |
288 // -------------- | 308 // -------------- |
289 | 309 |
290 const scoped_refptr<base::SequencedTaskRunner> network_task_runner_; | 310 const scoped_refptr<base::SequencedTaskRunner> network_task_runner_; |
291 | 311 |
292 // Used to post |prefs::kHttpServerProperties| pref update tasks. | 312 // Used to post |prefs::kHttpServerProperties| pref update tasks. |
293 scoped_ptr<base::OneShotTimer> network_prefs_update_timer_; | 313 scoped_ptr<base::OneShotTimer> network_prefs_update_timer_; |
294 | 314 |
295 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_impl_; | 315 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_impl_; |
296 | 316 |
297 // Used to get |weak_ptr_| to self on the pref thread. | 317 // Used to get |weak_ptr_| to self on the pref thread. |
298 scoped_ptr<base::WeakPtrFactory<HttpServerPropertiesManager> > | 318 scoped_ptr<base::WeakPtrFactory<HttpServerPropertiesManager> > |
299 pref_weak_ptr_factory_; | 319 pref_weak_ptr_factory_; |
300 | 320 |
301 // Used to get |weak_ptr_| to self on the network thread. | 321 // Used to get |weak_ptr_| to self on the network thread. |
302 scoped_ptr<base::WeakPtrFactory<HttpServerPropertiesManager> > | 322 scoped_ptr<base::WeakPtrFactory<HttpServerPropertiesManager> > |
303 network_weak_ptr_factory_; | 323 network_weak_ptr_factory_; |
304 | 324 |
305 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager); | 325 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager); |
306 }; | 326 }; |
307 | 327 |
308 } // namespace net | 328 } // namespace net |
309 | 329 |
310 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ | 330 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ |
OLD | NEW |