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

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
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/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/task.h"
14 #include "chrome/browser/prefs/pref_change_registrar.h"
15 #include "content/common/notification_observer.h"
16 #include "net/base/host_port_pair.h"
17 #include "net/http/http_server_properties.h"
18 #include "net/http/http_server_properties_impl.h"
19
20 class NotificationDetails;
21 class NotificationSource;
22 class PrefService;
23
24 namespace base {
25 class ListValue;
26 }
27
28 namespace chrome_browser_net {
29
30 ////////////////////////////////////////////////////////////////////////////////
31 // HttpServerPropertiesManager
32
33 // The manager for creating and updating an HttpServerProperties (for example it
34 // tracks if a server supports SPDY or not).
35 //
36 // This class interacts with both the UI thread, where notifications of pref
37 // changes are received from, and the IO thread, which owns it (in the
38 // ProfileIOData) and checks for SpdyServers (from ChromeNetworkDelegate).
39 //
40 // It must be constructed on the UI thread, to set up |ui_method_factory_| and
41 // the prefs listeners.
42 //
43 // ShutdownOnUIThread must be called from UI before destruction, to release
44 // the prefs listeners on the UI thread. This is done from ProfileIOData.
45 //
46 // Update tasks from the UI thread can post safely to the IO thread, since the
47 // destruction order of Profile and ProfileIOData guarantees that if this
48 // exists in UI, then a potential destruction on IO will come after any task
49 // posted to IO from that method on UI. This is used to go through IO before
50 // the actual update starts, and grab a WeakPtr.
51 class HttpServerPropertiesManager
52 : public net::HttpServerProperties,
53 public NotificationObserver {
54 public:
55 // Create an instance of the HttpServerPropertiesManager. The lifetime of the
56 // PrefService objects must be longer than that of the
57 // HttpServerPropertiesManager object. Get SPDY Server preferences from
58 // |prefs| object. Must be constructed on the UI thread.
59 explicit HttpServerPropertiesManager(PrefService* pref_service);
60 virtual ~HttpServerPropertiesManager();
61
62 // Initialize |ui_weak_ptr_factory_| and |io_method_factory_| on IO thread.
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.
69 virtual bool SupportsSpdy(const net::HostPortPair& server) const OVERRIDE;
70
71 // Add |server| as the SPDY server which supports SPDY protocol into the
72 // persisitent store. Should only be called from IO thread.
73 virtual void SetSupportsSpdy(const net::HostPortPair& server,
74 bool support_spdy) OVERRIDE;
75
76 // Register |prefs| SPDY preferences.
77 static void RegisterPrefs(PrefService* prefs);
78
79 protected:
80 // These are used to delay updating the spdy servers in |spdy_servers_table_|
81 // while the preferences are changing, and execute only one update per
82 // simultaneous prefs changes.
83 void ScheduleUpdateOnUI();
84 virtual void PostUpdateTaskOnUI(Task* task); // Virtual for testing.
85 virtual void UpdateCacheFromPrefs(); // Virtual for testing.
86
87 // Starts the |spdy_servers| update on the IO thread. Protected for testing.
88 void UpdateCacheFromPrefsOnIO(StringVector* spdy_servers, bool support_spdy);
89
90 // These are used to delay updating the preferences when spdy servers_ are
91 // changing, and execute only one update per simultaneous spdy server changes.
92 void ScheduleUpdateOnIO();
93 virtual void PostUpdateTaskOnIO(Task* task); // Virtual for testing.
94 virtual void UpdatePrefsFromCache(); // Virtual for testing.
95
96 // Update |prefs::kSpdyServers| preferences with |spdy_server_list| on UI
97 // thread. Protected for testing.
98 void SetSpdyServersInPrefsOnUI(base::ListValue* spdy_server_list);
99
100 private:
101 // Callback for preference changes.
102 virtual void Observe(int type,
103 const NotificationSource& source,
104 const NotificationDetails& details);
105
106 // ---------
107 // UI thread
108 // ---------
109
110 // Used to post update tasks to the UI thread.
111 ScopedRunnableMethodFactory<HttpServerPropertiesManager> ui_method_factory_;
112
113 // Used to get |weak_ptr_| to self on the UI thread.
114 scoped_ptr<base::WeakPtrFactory<HttpServerPropertiesManager> >
115 ui_weak_ptr_factory_;
116
117 // Used to track the spdy servers changes.
118 PrefChangeRegistrar pref_change_registrar_;
119 PrefService* pref_service_; // Weak.
120
121 // ---------
122 // IO thread
123 // ---------
124
125 // Used to post update tasks to the IO thread.
126 scoped_ptr<ScopedRunnableMethodFactory<HttpServerPropertiesManager> >
127 io_method_factory_;
128
129 // Used to get |weak_ptr_| to self on the IO thread.
130 base::WeakPtrFactory<HttpServerPropertiesManager> io_weak_ptr_factory_;
131
132 mutable scoped_ptr<net::HttpServerPropertiesImpl>
willchan no longer on Chromium 2011/10/04 05:55:02 Why is this mutable?
ramant (doing other things) 2011/10/06 06:17:52 Done.
133 http_server_properties_impl_;
134
135 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager);
136 };
137
138 } // namespace chrome_browser_net
139
140 #endif // CHROME_BROWSER_NET_HTTP_SERVER_PROPERTIES_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698