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

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

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add TODO Created 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ 5 #ifndef CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_
6 #define CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ 6 #define CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/public/pref_change_registrar.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "net/url_request/url_request_context.h" 11 #include "net/url_request/url_request_context.h"
15 #include "net/url_request/url_request_context_getter.h" 12 #include "net/url_request/url_request_context_getter.h"
16 #include "net/url_request/url_request_job_factory.h" 13 #include "net/url_request/url_request_job_factory.h"
17 14
18 class ChromeURLDataManagerBackend; 15 class ChromeURLDataManagerBackend;
19 class ChromeURLRequestContextFactory; 16 class ChromeURLRequestContextFactory;
20 class IOThread; 17 class IOThread;
21 class Profile; 18 class Profile;
22 class ProfileIOData; 19 class ProfileIOData;
23 20
(...skipping 22 matching lines...) Expand all
46 return weak_factory_.GetWeakPtr(); 43 return weak_factory_.GetWeakPtr();
47 } 44 }
48 45
49 // Copies the state from |other| into this context. 46 // Copies the state from |other| into this context.
50 void CopyFrom(ChromeURLRequestContext* other); 47 void CopyFrom(ChromeURLRequestContext* other);
51 48
52 bool is_incognito() const { 49 bool is_incognito() const {
53 return is_incognito_; 50 return is_incognito_;
54 } 51 }
55 52
56 virtual const std::string& GetUserAgent(const GURL& url) const OVERRIDE;
57
58 // TODO(willchan): Get rid of the need for this accessor. Really, this should 53 // TODO(willchan): Get rid of the need for this accessor. Really, this should
59 // move completely to ProfileIOData. 54 // move completely to ProfileIOData.
60 ChromeURLDataManagerBackend* chrome_url_data_manager_backend() const; 55 ChromeURLDataManagerBackend* chrome_url_data_manager_backend() const;
61 56
62 void set_is_incognito(bool is_incognito) { 57 void set_is_incognito(bool is_incognito) {
63 is_incognito_ = is_incognito; 58 is_incognito_ = is_incognito;
64 } 59 }
65 60
66 void set_chrome_url_data_manager_backend( 61 void set_chrome_url_data_manager_backend(
67 ChromeURLDataManagerBackend* backend); 62 ChromeURLDataManagerBackend* backend);
68 63
69 // Callback for when the accept language changes.
70 void OnAcceptLanguageChange(const std::string& accept_language);
71
72 // Callback for when the default charset changes.
73 void OnDefaultCharsetChange(const std::string& default_charset);
74
75 private: 64 private:
76 base::WeakPtrFactory<ChromeURLRequestContext> weak_factory_; 65 base::WeakPtrFactory<ChromeURLRequestContext> weak_factory_;
77 66
78 // --------------------------------------------------------------------------- 67 // ---------------------------------------------------------------------------
79 // Important: When adding any new members below, consider whether they need to 68 // Important: When adding any new members below, consider whether they need to
80 // be added to CopyFrom. 69 // be added to CopyFrom.
81 // --------------------------------------------------------------------------- 70 // ---------------------------------------------------------------------------
82 71
83 ChromeURLDataManagerBackend* chrome_url_data_manager_backend_; 72 ChromeURLDataManagerBackend* chrome_url_data_manager_backend_;
84 bool is_incognito_; 73 bool is_incognito_;
85 chrome_browser_net::LoadTimeStats* load_time_stats_; 74 chrome_browser_net::LoadTimeStats* load_time_stats_;
86 75
87 // --------------------------------------------------------------------------- 76 // ---------------------------------------------------------------------------
88 // Important: When adding any new members above, consider whether they need to 77 // Important: When adding any new members above, consider whether they need to
89 // be added to CopyFrom. 78 // be added to CopyFrom.
90 // --------------------------------------------------------------------------- 79 // ---------------------------------------------------------------------------
91 80
92 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContext); 81 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContext);
93 }; 82 };
94 83
95 // A net::URLRequestContextGetter subclass used by the browser. This returns a 84 // A net::URLRequestContextGetter subclass used by the browser. This returns a
96 // subclass of net::URLRequestContext which can be used to store extra 85 // subclass of net::URLRequestContext which can be used to store extra
97 // information about requests. 86 // information about requests.
98 // 87 //
99 // Most methods are expected to be called on the UI thread, except for 88 // Most methods are expected to be called on the UI thread, except for
100 // the destructor and GetURLRequestContext(). 89 // the destructor and GetURLRequestContext().
101 class ChromeURLRequestContextGetter : public net::URLRequestContextGetter, 90 class ChromeURLRequestContextGetter : public net::URLRequestContextGetter {
102 public content::NotificationObserver {
103 public: 91 public:
104 // Constructs a ChromeURLRequestContextGetter that will use |factory| to 92 // Constructs a ChromeURLRequestContextGetter that will use |factory| to
105 // create the ChromeURLRequestContext. If |profile| is non-NULL, then the 93 // create the ChromeURLRequestContext.
106 // ChromeURLRequestContextGetter will additionally watch the preferences for 94 explicit ChromeURLRequestContextGetter(
107 // changes to charset/language and CleanupOnUIThread() will need to be 95 ChromeURLRequestContextFactory* factory);
108 // called to unregister.
109 ChromeURLRequestContextGetter(Profile* profile,
110 ChromeURLRequestContextFactory* factory);
111 96
112 // Note that GetURLRequestContext() can only be called from the IO 97 // Note that GetURLRequestContext() can only be called from the IO
113 // thread (it will assert otherwise). 98 // thread (it will assert otherwise).
114 // GetIOMessageLoopProxy however can be called from any thread. 99 // GetIOMessageLoopProxy however can be called from any thread.
115 // 100 //
116 // net::URLRequestContextGetter implementation. 101 // net::URLRequestContextGetter implementation.
117 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; 102 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
118 virtual scoped_refptr<base::SingleThreadTaskRunner> 103 virtual scoped_refptr<base::SingleThreadTaskRunner>
119 GetNetworkTaskRunner() const OVERRIDE; 104 GetNetworkTaskRunner() const OVERRIDE;
120 105
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 154
170 // Create an instance for an OTR profile for an app with isolated storage. 155 // Create an instance for an OTR profile for an app with isolated storage.
171 // This is expected to get called on UI thread. 156 // This is expected to get called on UI thread.
172 static ChromeURLRequestContextGetter* CreateOffTheRecordForIsolatedApp( 157 static ChromeURLRequestContextGetter* CreateOffTheRecordForIsolatedApp(
173 Profile* profile, 158 Profile* profile,
174 const ProfileIOData* profile_io_data, 159 const ProfileIOData* profile_io_data,
175 const std::string& app_id, 160 const std::string& app_id,
176 scoped_ptr<net::URLRequestJobFactory::Interceptor> 161 scoped_ptr<net::URLRequestJobFactory::Interceptor>
177 protocol_handler_interceptor); 162 protocol_handler_interceptor);
178 163
179 // Clean up UI thread resources. This is expected to get called on the UI
180 // thread before the instance is deleted on the IO thread.
181 void CleanupOnUIThread();
182
183 // content::NotificationObserver implementation.
184 virtual void Observe(int type,
185 const content::NotificationSource& source,
186 const content::NotificationDetails& details) OVERRIDE;
187
188 private: 164 private:
189 // Must be called on the IO thread.
190 virtual ~ChromeURLRequestContextGetter(); 165 virtual ~ChromeURLRequestContextGetter();
191 166
192 // Registers an observer on |profile|'s preferences which will be used
193 // to update the context when the default language and charset change.
194 void RegisterPrefsObserver(Profile* profile);
195
196 // These methods simply forward to the corresponding method on
197 // ChromeURLRequestContext.
198 void OnAcceptLanguageChange(const std::string& accept_language);
199 void OnDefaultCharsetChange(const std::string& default_charset);
200
201 PrefChangeRegistrar registrar_;
202
203 // Deferred logic for creating a ChromeURLRequestContext. 167 // Deferred logic for creating a ChromeURLRequestContext.
204 // Access only from the IO thread. 168 // Access only from the IO thread.
205 scoped_ptr<ChromeURLRequestContextFactory> factory_; 169 scoped_ptr<ChromeURLRequestContextFactory> factory_;
206 170
207 // NULL if not yet initialized. Otherwise, it is the ChromeURLRequestContext 171 // NULL if not yet initialized. Otherwise, it is the ChromeURLRequestContext
208 // instance that was lazily created by GetURLRequestContext(). 172 // instance that was lazily created by GetURLRequestContext().
209 // Access only from the IO thread. 173 // Access only from the IO thread.
210 base::WeakPtr<ChromeURLRequestContext> url_request_context_; 174 base::WeakPtr<ChromeURLRequestContext> url_request_context_;
211 175
212 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); 176 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter);
213 }; 177 };
214 178
215 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ 179 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698