Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: chrome/browser/net/http_server_properties_manager.h

Issue 7827033: Introduce net::HttpServerPropertiesManager to manage server-specific properties. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/browser/net/http_server_properties_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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
5 #ifndef CHROME_BROWSER_NET_HTTP_SERVER_PROPERTIES_MANAGER_H_
6 #define CHROME_BROWSER_NET_HTTP_SERVER_PROPERTIES_MANAGER_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/task.h"
15 #include "base/values.h"
16 #include "chrome/browser/prefs/pref_change_registrar.h"
17 #include "content/common/notification_observer.h"
18 #include "net/base/host_port_pair.h"
19 #include "net/http/http_server_properties.h"
20 #include "net/http/http_server_properties_impl.h"
21
22 class NotificationDetails;
23 class NotificationSource;
24 class PrefService;
25
26 namespace chrome_browser_net {
27
28 ////////////////////////////////////////////////////////////////////////////////
29 // HttpServerPropertiesManager
30
31 // The manager for creating and updating an HttpServerProperties (for example it
32 // tracks if a server supports SPDY or not).
33 //
34 // This class interacts with both the UI thread, where notifications of pref
35 // changes are received from, and the IO thread, which owns it (in the
36 // ProfileIOData) and it persists the changes from network stack that if a
37 // server supports SPDY or not.
38 //
39 // It must be constructed on the UI thread, to set up |ui_method_factory_| and
40 // the prefs listeners.
41 //
42 // ShutdownOnUIThread must be called from UI before destruction, to release
43 // the prefs listeners on the UI thread. This is done from ProfileIOData.
44 //
45 // Update tasks from the UI thread can post safely to the IO thread, since the
46 // destruction order of Profile and ProfileIOData guarantees that if this
47 // exists in UI, then a potential destruction on IO will come after any task
48 // posted to IO from that method on UI. This is used to go through IO before
49 // the actual update starts, and grab a WeakPtr.
50 class HttpServerPropertiesManager
51 : public net::HttpServerProperties,
52 public NotificationObserver {
53 public:
54 // Create an instance of the HttpServerPropertiesManager. The lifetime of the
55 // PrefService objects must be longer than that of the
56 // HttpServerPropertiesManager object. Must be constructed on the UI thread.
57 explicit HttpServerPropertiesManager(PrefService* pref_service);
58 virtual ~HttpServerPropertiesManager();
59
60 // Initialize |http_server_properties_impl_| and |io_method_factory_| on IO
61 // thread. It also posts a task to UI thread to get SPDY Server preferences
62 // from |pref_service_|.
63 void InitializeOnIOThread();
64
65 // Prepare for shutdown. Must be called on the UI thread, before destruction.
66 void ShutdownOnUIThread();
67
68 // Returns true if |server| supports SPDY. Should only be called from IO
69 // thread.
70 virtual bool SupportsSpdy(const net::HostPortPair& server) const OVERRIDE;
71
72 // Add |server| as the SPDY server which supports SPDY protocol into the
73 // persisitent store. Should only be called from IO thread.
74 virtual void SetSupportsSpdy(const net::HostPortPair& server,
75 bool support_spdy) OVERRIDE;
76
77 // Deletes all data.
78 virtual void DeleteAll() OVERRIDE;
79
80 // Register |prefs| SPDY preferences.
81 static void RegisterPrefs(PrefService* prefs);
82
83 protected:
84 typedef base::RefCountedData<base::ListValue> RefCountedListValue;
85
86 // These are used to delay updating the spdy servers in
87 // |http_server_properties_impl_| while the preferences are changing, and
88 // execute only one update per simultaneous prefs changes.
89 void ScheduleUpdateCacheOnUI();
90
91 // Update spdy servers (the cached data in |http_server_properties_impl_|)
92 // with data from preferences. Virtual for testing.
93 virtual void UpdateCacheFromPrefs();
94
95 // Starts the |spdy_servers| update on the IO thread. Protected for testing.
96 void UpdateCacheFromPrefsOnIO(StringVector* spdy_servers, bool support_spdy);
97
98 // These are used to delay updating the preferences when spdy servers_ are
99 // changing, and execute only one update per simultaneous spdy server changes.
100 void ScheduleUpdatePrefsOnIO();
101
102 // Update spdy servers in preferences with the cached data from
103 // |http_server_properties_impl_|. Virtual for testing.
104 virtual void UpdatePrefsFromCache(); // Virtual for testing.
105
106 // Update |prefs::kSpdyServers| preferences with |spdy_server_list| on UI
107 // thread. Protected for testing.
108 void SetSpdyServersInPrefsOnUI(
109 scoped_refptr<RefCountedListValue> spdy_server_list);
110
111 private:
112 // Post the tasks with the delay. These are overridden in tests to post the
113 // task without the delay.
114 virtual void PostUpdateTaskOnUI(Task* task); // Virtual for testing.
115 virtual void PostUpdateTaskOnIO(Task* task); // Virtual for testing.
116
117 // Callback for preference changes.
118 virtual void Observe(int type,
119 const NotificationSource& source,
120 const NotificationDetails& details);
121
122 // ---------
123 // UI thread
124 // ---------
125
126 // Used to post update tasks to the UI thread.
127 ScopedRunnableMethodFactory<HttpServerPropertiesManager> ui_method_factory_;
128
129 // Used to get |weak_ptr_| to self on the UI thread.
130 scoped_ptr<base::WeakPtrFactory<HttpServerPropertiesManager> >
131 ui_weak_ptr_factory_;
132
133 base::WeakPtr<HttpServerPropertiesManager> ui_weak_ptr_;
134
135 // Used to track the spdy servers changes.
136 PrefChangeRegistrar pref_change_registrar_;
137 PrefService* pref_service_; // Weak.
138
139 // ---------
140 // IO thread
141 // ---------
142
143 // Used to post update tasks to the IO thread.
144 scoped_ptr<ScopedRunnableMethodFactory<HttpServerPropertiesManager> >
145 io_method_factory_;
146
147 scoped_ptr<net::HttpServerPropertiesImpl> http_server_properties_impl_;
148
149 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager);
150 };
151
152 } // namespace chrome_browser_net
153
154 #endif // CHROME_BROWSER_NET_HTTP_SERVER_PROPERTIES_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/browser/net/http_server_properties_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698