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