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

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

Powered by Google App Engine
This is Rietveld 408576698