OLD | NEW |
1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | |
11 | 10 |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/prefs/pref_change_registrar.h" | 12 #include "chrome/browser/prefs/pref_change_registrar.h" |
14 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
16 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
17 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
18 | 17 |
19 class ChromeURLDataManagerBackend; | 18 class ChromeURLDataManagerBackend; |
20 class ChromeURLRequestContextFactory; | 19 class ChromeURLRequestContextFactory; |
21 class IOThread; | 20 class IOThread; |
22 class Profile; | 21 class Profile; |
23 class ProfileIOData; | 22 class ProfileIOData; |
24 namespace base { | |
25 class WaitableEvent; | |
26 } | |
27 | 23 |
28 // Subclass of net::URLRequestContext which can be used to store extra | 24 // Subclass of net::URLRequestContext which can be used to store extra |
29 // information for requests. | 25 // information for requests. |
30 // | 26 // |
31 // All methods of this class must be called from the IO thread, | 27 // All methods of this class must be called from the IO thread, |
32 // including the constructor and destructor. | 28 // including the constructor and destructor. |
33 class ChromeURLRequestContext : public net::URLRequestContext { | 29 class ChromeURLRequestContext : public net::URLRequestContext { |
34 public: | 30 public: |
35 ChromeURLRequestContext(); | 31 ChromeURLRequestContext(); |
36 | 32 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 public: | 87 public: |
92 // Constructs a ChromeURLRequestContextGetter that will use |factory| to | 88 // Constructs a ChromeURLRequestContextGetter that will use |factory| to |
93 // create the ChromeURLRequestContext. If |profile| is non-NULL, then the | 89 // create the ChromeURLRequestContext. If |profile| is non-NULL, then the |
94 // ChromeURLRequestContextGetter will additionally watch the preferences for | 90 // ChromeURLRequestContextGetter will additionally watch the preferences for |
95 // changes to charset/language and CleanupOnUIThread() will need to be | 91 // changes to charset/language and CleanupOnUIThread() will need to be |
96 // called to unregister. | 92 // called to unregister. |
97 ChromeURLRequestContextGetter(Profile* profile, | 93 ChromeURLRequestContextGetter(Profile* profile, |
98 ChromeURLRequestContextFactory* factory); | 94 ChromeURLRequestContextFactory* factory); |
99 | 95 |
100 // Note that GetURLRequestContext() can only be called from the IO | 96 // Note that GetURLRequestContext() can only be called from the IO |
101 // thread (it will assert otherwise). DONTUSEME_GetCookieStore() and | 97 // thread (it will assert otherwise). |
102 // GetIOMessageLoopProxy however can be called from any thread. | 98 // GetIOMessageLoopProxy however can be called from any thread. |
103 // | 99 // |
104 // net::URLRequestContextGetter implementation. | 100 // net::URLRequestContextGetter implementation. |
105 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | 101 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
106 virtual net::CookieStore* DONTUSEME_GetCookieStore() OVERRIDE; | |
107 virtual scoped_refptr<base::MessageLoopProxy> | 102 virtual scoped_refptr<base::MessageLoopProxy> |
108 GetIOMessageLoopProxy() const OVERRIDE; | 103 GetIOMessageLoopProxy() const OVERRIDE; |
109 | 104 |
110 // Convenience overload of GetURLRequestContext() that returns a | 105 // Convenience overload of GetURLRequestContext() that returns a |
111 // ChromeURLRequestContext* rather than a net::URLRequestContext*. | 106 // ChromeURLRequestContext* rather than a net::URLRequestContext*. |
112 ChromeURLRequestContext* GetIOContext() { | 107 ChromeURLRequestContext* GetIOContext() { |
113 return reinterpret_cast<ChromeURLRequestContext*>(GetURLRequestContext()); | 108 return reinterpret_cast<ChromeURLRequestContext*>(GetURLRequestContext()); |
114 } | 109 } |
115 | 110 |
116 // Create an instance for use with an 'original' (non-OTR) profile. This is | 111 // Create an instance for use with an 'original' (non-OTR) profile. This is |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Registers an observer on |profile|'s preferences which will be used | 164 // Registers an observer on |profile|'s preferences which will be used |
170 // to update the context when the default language and charset change. | 165 // to update the context when the default language and charset change. |
171 void RegisterPrefsObserver(Profile* profile); | 166 void RegisterPrefsObserver(Profile* profile); |
172 | 167 |
173 // These methods simply forward to the corresponding method on | 168 // These methods simply forward to the corresponding method on |
174 // ChromeURLRequestContext. | 169 // ChromeURLRequestContext. |
175 void OnAcceptLanguageChange(const std::string& accept_language); | 170 void OnAcceptLanguageChange(const std::string& accept_language); |
176 void OnDefaultCharsetChange(const std::string& default_charset); | 171 void OnDefaultCharsetChange(const std::string& default_charset); |
177 void OnClearSiteDataOnExitChange(bool clear_site_data); | 172 void OnClearSiteDataOnExitChange(bool clear_site_data); |
178 | 173 |
179 // Saves the cookie store to |result| and signals |completion|. | |
180 void GetCookieStoreAsyncHelper(base::WaitableEvent* completion, | |
181 net::CookieStore** result); | |
182 | |
183 PrefChangeRegistrar registrar_; | 174 PrefChangeRegistrar registrar_; |
184 | 175 |
185 // Deferred logic for creating a ChromeURLRequestContext. | 176 // Deferred logic for creating a ChromeURLRequestContext. |
186 // Access only from the IO thread. | 177 // Access only from the IO thread. |
187 scoped_ptr<ChromeURLRequestContextFactory> factory_; | 178 scoped_ptr<ChromeURLRequestContextFactory> factory_; |
188 | 179 |
189 // NULL if not yet initialized. Otherwise, it is the net::URLRequestContext | 180 // NULL if not yet initialized. Otherwise, it is the net::URLRequestContext |
190 // instance that was lazily created by GetURLRequestContext(). | 181 // instance that was lazily created by GetURLRequestContext(). |
191 // Access only from the IO thread. | 182 // Access only from the IO thread. |
192 base::WeakPtr<net::URLRequestContext> url_request_context_; | 183 base::WeakPtr<net::URLRequestContext> url_request_context_; |
193 | 184 |
194 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); | 185 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextGetter); |
195 }; | 186 }; |
196 | 187 |
197 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ | 188 #endif // CHROME_BROWSER_NET_CHROME_URL_REQUEST_CONTEXT_H_ |
OLD | NEW |