| OLD | NEW |
| 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" | 11 #include "base/prefs/public/pref_change_registrar.h" |
| 12 #include "content/public/browser/notification_observer.h" | 12 #include "base/prefs/public/pref_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | |
| 14 #include "net/url_request/url_request_context.h" | 13 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
| 16 #include "net/url_request/url_request_job_factory.h" | 15 #include "net/url_request/url_request_job_factory.h" |
| 17 | 16 |
| 18 class ChromeURLDataManagerBackend; | 17 class ChromeURLDataManagerBackend; |
| 19 class ChromeURLRequestContextFactory; | 18 class ChromeURLRequestContextFactory; |
| 20 class IOThread; | 19 class IOThread; |
| 21 class Profile; | 20 class Profile; |
| 22 class ProfileIOData; | 21 class ProfileIOData; |
| 23 | 22 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContext); | 91 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContext); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 // A net::URLRequestContextGetter subclass used by the browser. This returns a | 94 // A net::URLRequestContextGetter subclass used by the browser. This returns a |
| 96 // subclass of net::URLRequestContext which can be used to store extra | 95 // subclass of net::URLRequestContext which can be used to store extra |
| 97 // information about requests. | 96 // information about requests. |
| 98 // | 97 // |
| 99 // Most methods are expected to be called on the UI thread, except for | 98 // Most methods are expected to be called on the UI thread, except for |
| 100 // the destructor and GetURLRequestContext(). | 99 // the destructor and GetURLRequestContext(). |
| 101 class ChromeURLRequestContextGetter : public net::URLRequestContextGetter, | 100 class ChromeURLRequestContextGetter : public net::URLRequestContextGetter, |
| 102 public content::NotificationObserver { | 101 public PrefObserver { |
| 103 public: | 102 public: |
| 104 // Constructs a ChromeURLRequestContextGetter that will use |factory| to | 103 // Constructs a ChromeURLRequestContextGetter that will use |factory| to |
| 105 // create the ChromeURLRequestContext. If |profile| is non-NULL, then the | 104 // create the ChromeURLRequestContext. If |profile| is non-NULL, then the |
| 106 // ChromeURLRequestContextGetter will additionally watch the preferences for | 105 // ChromeURLRequestContextGetter will additionally watch the preferences for |
| 107 // changes to charset/language and CleanupOnUIThread() will need to be | 106 // changes to charset/language and CleanupOnUIThread() will need to be |
| 108 // called to unregister. | 107 // called to unregister. |
| 109 ChromeURLRequestContextGetter(Profile* profile, | 108 ChromeURLRequestContextGetter(Profile* profile, |
| 110 ChromeURLRequestContextFactory* factory); | 109 ChromeURLRequestContextFactory* factory); |
| 111 | 110 |
| 112 // Note that GetURLRequestContext() can only be called from the IO | 111 // Note that GetURLRequestContext() can only be called from the IO |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 Profile* profile, | 172 Profile* profile, |
| 174 const ProfileIOData* profile_io_data, | 173 const ProfileIOData* profile_io_data, |
| 175 const std::string& app_id, | 174 const std::string& app_id, |
| 176 scoped_ptr<net::URLRequestJobFactory::Interceptor> | 175 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 177 protocol_handler_interceptor); | 176 protocol_handler_interceptor); |
| 178 | 177 |
| 179 // Clean up UI thread resources. This is expected to get called on the UI | 178 // 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. | 179 // thread before the instance is deleted on the IO thread. |
| 181 void CleanupOnUIThread(); | 180 void CleanupOnUIThread(); |
| 182 | 181 |
| 183 // content::NotificationObserver implementation. | 182 // PrefObserver implementation. |
| 184 virtual void Observe(int type, | 183 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 185 const content::NotificationSource& source, | 184 const std::string& pref_name) OVERRIDE; |
| 186 const content::NotificationDetails& details) OVERRIDE; | |
| 187 | 185 |
| 188 private: | 186 private: |
| 189 // Must be called on the IO thread. | 187 // Must be called on the IO thread. |
| 190 virtual ~ChromeURLRequestContextGetter(); | 188 virtual ~ChromeURLRequestContextGetter(); |
| 191 | 189 |
| 192 // Registers an observer on |profile|'s preferences which will be used | 190 // Registers an observer on |profile|'s preferences which will be used |
| 193 // to update the context when the default language and charset change. | 191 // to update the context when the default language and charset change. |
| 194 void RegisterPrefsObserver(Profile* profile); | 192 void RegisterPrefsObserver(Profile* profile); |
| 195 | 193 |
| 196 // These methods simply forward to the corresponding method on | 194 // These methods simply forward to the corresponding method on |
| 197 // ChromeURLRequestContext. | 195 // ChromeURLRequestContext. |
| 198 void OnAcceptLanguageChange(const std::string& accept_language); | 196 void OnAcceptLanguageChange(const std::string& accept_language); |
| 199 void OnDefaultCharsetChange(const std::string& default_charset); | 197 void OnDefaultCharsetChange(const std::string& default_charset); |
| 200 | 198 |
| 201 PrefChangeRegistrar registrar_; | 199 PrefChangeRegistrar registrar_; |
| 202 | 200 |
| 203 // Deferred logic for creating a ChromeURLRequestContext. | 201 // Deferred logic for creating a ChromeURLRequestContext. |
| 204 // Access only from the IO thread. | 202 // Access only from the IO thread. |
| 205 scoped_ptr<ChromeURLRequestContextFactory> factory_; | 203 scoped_ptr<ChromeURLRequestContextFactory> factory_; |
| 206 | 204 |
| 207 // NULL if not yet initialized. Otherwise, it is the ChromeURLRequestContext | 205 // NULL if not yet initialized. Otherwise, it is the ChromeURLRequestContext |
| 208 // instance that was lazily created by GetURLRequestContext(). | 206 // instance that was lazily created by GetURLRequestContext(). |
| 209 // Access only from the IO thread. | 207 // Access only from the IO thread. |
| 210 base::WeakPtr<ChromeURLRequestContext> url_request_context_; | 208 base::WeakPtr<ChromeURLRequestContext> url_request_context_; |
| 211 | 209 |
| 212 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); | 210 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); |
| 213 }; | 211 }; |
| 214 | 212 |
| 215 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ | 213 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ |
| OLD | NEW |