OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/io_thread.h" | 10 #include "chrome/browser/io_thread.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 : profile_io_data_(profile_io_data) {} | 70 : profile_io_data_(profile_io_data) {} |
71 | 71 |
72 virtual scoped_refptr<ChromeURLRequestContext> Create() { | 72 virtual scoped_refptr<ChromeURLRequestContext> Create() { |
73 return profile_io_data_->GetExtensionsRequestContext(); | 73 return profile_io_data_->GetExtensionsRequestContext(); |
74 } | 74 } |
75 | 75 |
76 private: | 76 private: |
77 const scoped_refptr<const ProfileIOData> profile_io_data_; | 77 const scoped_refptr<const ProfileIOData> profile_io_data_; |
78 }; | 78 }; |
79 | 79 |
80 // Factory that creates the ChromeURLRequestContext for a given isolated app. | |
81 class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { | |
82 public: | |
83 FactoryForIsolatedApp(const ProfileIOData* profile_io_data, | |
84 std::string app_id, | |
Matt Perry
2011/03/15 00:40:56
const std::string&
Charlie Reis
2011/03/15 06:23:42
Done.
| |
85 ChromeURLRequestContextGetter* main_context) | |
86 : profile_io_data_(profile_io_data), | |
87 app_id_(app_id), | |
88 main_request_context_getter_(main_context) {} | |
89 | |
90 virtual scoped_refptr<ChromeURLRequestContext> Create() { | |
91 // We will copy most of the state from the main request context. | |
92 return profile_io_data_->GetIsolatedAppRequestContext( | |
93 main_request_context_getter_->GetIOContext(), app_id_); | |
94 } | |
95 | |
96 private: | |
97 const scoped_refptr<const ProfileIOData> profile_io_data_; | |
98 std::string app_id_; | |
99 scoped_refptr<ChromeURLRequestContextGetter> | |
100 main_request_context_getter_; | |
101 }; | |
102 | |
80 // Factory that creates the ChromeURLRequestContext for media. | 103 // Factory that creates the ChromeURLRequestContext for media. |
81 class FactoryForMedia : public ChromeURLRequestContextFactory { | 104 class FactoryForMedia : public ChromeURLRequestContextFactory { |
82 public: | 105 public: |
83 explicit FactoryForMedia(const ProfileIOData* profile_io_data) | 106 explicit FactoryForMedia(const ProfileIOData* profile_io_data) |
84 : profile_io_data_(profile_io_data) { | 107 : profile_io_data_(profile_io_data) { |
85 } | 108 } |
86 | 109 |
87 virtual scoped_refptr<ChromeURLRequestContext> Create() { | 110 virtual scoped_refptr<ChromeURLRequestContext> Create() { |
88 return profile_io_data_->GetMediaRequestContext(); | 111 return profile_io_data_->GetMediaRequestContext(); |
89 } | 112 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 ChromeURLRequestContextGetter::CreateOriginalForExtensions( | 231 ChromeURLRequestContextGetter::CreateOriginalForExtensions( |
209 Profile* profile, const ProfileIOData* profile_io_data) { | 232 Profile* profile, const ProfileIOData* profile_io_data) { |
210 DCHECK(!profile->IsOffTheRecord()); | 233 DCHECK(!profile->IsOffTheRecord()); |
211 return new ChromeURLRequestContextGetter( | 234 return new ChromeURLRequestContextGetter( |
212 profile, | 235 profile, |
213 new FactoryForExtensions(profile_io_data)); | 236 new FactoryForExtensions(profile_io_data)); |
214 } | 237 } |
215 | 238 |
216 // static | 239 // static |
217 ChromeURLRequestContextGetter* | 240 ChromeURLRequestContextGetter* |
241 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | |
242 Profile* profile, | |
243 const ProfileIOData* profile_io_data, | |
244 std::string app_id) { | |
245 DCHECK(!profile->IsOffTheRecord()); | |
246 ChromeURLRequestContextGetter* main_context = | |
247 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | |
248 return new ChromeURLRequestContextGetter( | |
249 profile, | |
250 new FactoryForIsolatedApp(profile_io_data, app_id, main_context)); | |
251 } | |
252 | |
253 // static | |
254 ChromeURLRequestContextGetter* | |
218 ChromeURLRequestContextGetter::CreateOffTheRecord( | 255 ChromeURLRequestContextGetter::CreateOffTheRecord( |
219 Profile* profile, const ProfileIOData* profile_io_data) { | 256 Profile* profile, const ProfileIOData* profile_io_data) { |
220 DCHECK(profile->IsOffTheRecord()); | 257 DCHECK(profile->IsOffTheRecord()); |
221 return new ChromeURLRequestContextGetter( | 258 return new ChromeURLRequestContextGetter( |
222 profile, new FactoryForMain(profile_io_data)); | 259 profile, new FactoryForMain(profile_io_data)); |
223 } | 260 } |
224 | 261 |
225 // static | 262 // static |
226 ChromeURLRequestContextGetter* | 263 ChromeURLRequestContextGetter* |
227 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( | 264 ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( |
228 Profile* profile, const ProfileIOData* profile_io_data) { | 265 Profile* profile, const ProfileIOData* profile_io_data) { |
229 DCHECK(profile->IsOffTheRecord()); | 266 DCHECK(profile->IsOffTheRecord()); |
230 return new ChromeURLRequestContextGetter( | 267 return new ChromeURLRequestContextGetter( |
231 profile, new FactoryForExtensions(profile_io_data)); | 268 profile, new FactoryForExtensions(profile_io_data)); |
232 } | 269 } |
233 | 270 |
271 // static | |
272 ChromeURLRequestContextGetter* | |
273 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( | |
274 Profile* profile, | |
275 const ProfileIOData* profile_io_data, | |
276 std::string app_id) { | |
277 DCHECK(profile->IsOffTheRecord()); | |
278 ChromeURLRequestContextGetter* main_context = | |
279 static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); | |
280 return new ChromeURLRequestContextGetter( | |
281 profile, | |
282 new FactoryForIsolatedApp(profile_io_data, app_id, main_context)); | |
283 } | |
284 | |
234 void ChromeURLRequestContextGetter::CleanupOnUIThread() { | 285 void ChromeURLRequestContextGetter::CleanupOnUIThread() { |
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
236 // Unregister for pref notifications. | 287 // Unregister for pref notifications. |
237 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; | 288 DCHECK(!registrar_.IsEmpty()) << "Called more than once!"; |
238 registrar_.RemoveAll(); | 289 registrar_.RemoveAll(); |
239 } | 290 } |
240 | 291 |
241 // NotificationObserver implementation. | 292 // NotificationObserver implementation. |
242 void ChromeURLRequestContextGetter::Observe( | 293 void ChromeURLRequestContextGetter::Observe( |
243 NotificationType type, | 294 NotificationType type, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 | 368 |
318 // ---------------------------------------------------------------------------- | 369 // ---------------------------------------------------------------------------- |
319 // ChromeURLRequestContext | 370 // ChromeURLRequestContext |
320 // ---------------------------------------------------------------------------- | 371 // ---------------------------------------------------------------------------- |
321 | 372 |
322 ChromeURLRequestContext::ChromeURLRequestContext() | 373 ChromeURLRequestContext::ChromeURLRequestContext() |
323 : is_off_the_record_(false) { | 374 : is_off_the_record_(false) { |
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
325 } | 376 } |
326 | 377 |
378 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { | |
379 URLRequestContext::CopyFrom(other); | |
380 | |
381 // Copy ChromeURLRequestContext parameters. | |
382 set_user_script_dir_path(other->user_script_dir_path()); | |
383 set_appcache_service(other->appcache_service()); | |
384 set_database_tracker(other->database_tracker()); | |
385 set_chrome_cookie_policy(other->chrome_cookie_policy_); | |
386 set_host_content_settings_map(other->host_content_settings_map()); | |
387 set_host_zoom_map(other->host_zoom_map_); | |
388 set_blob_storage_context(other->blob_storage_context()); | |
389 set_file_system_context(other->file_system_context()); | |
390 set_extension_info_map(other->extension_info_map_); | |
391 set_prerender_manager(other->prerender_manager()); | |
392 // ChromeURLDataManagerBackend is unique per context. | |
393 set_is_off_the_record(other->is_off_the_record()); | |
394 } | |
395 | |
327 void ChromeURLRequestContext::set_chrome_cookie_policy( | 396 void ChromeURLRequestContext::set_chrome_cookie_policy( |
328 ChromeCookiePolicy* cookie_policy) { | 397 ChromeCookiePolicy* cookie_policy) { |
329 chrome_cookie_policy_ = cookie_policy; // Take a strong reference. | 398 chrome_cookie_policy_ = cookie_policy; // Take a strong reference. |
330 set_cookie_policy(cookie_policy); | 399 set_cookie_policy(cookie_policy); |
331 } | 400 } |
332 | 401 |
333 ChromeURLDataManagerBackend* | 402 ChromeURLDataManagerBackend* |
334 ChromeURLRequestContext::GetChromeURLDataManagerBackend() { | 403 ChromeURLRequestContext::GetChromeURLDataManagerBackend() { |
335 if (!chrome_url_data_manager_backend_.get()) | 404 if (!chrome_url_data_manager_backend_.get()) |
336 chrome_url_data_manager_backend_.reset(new ChromeURLDataManagerBackend()); | 405 chrome_url_data_manager_backend_.reset(new ChromeURLDataManagerBackend()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
377 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); | 446 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); |
378 } | 447 } |
379 | 448 |
380 void ChromeURLRequestContext::OnDefaultCharsetChange( | 449 void ChromeURLRequestContext::OnDefaultCharsetChange( |
381 const std::string& default_charset) { | 450 const std::string& default_charset) { |
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
383 set_referrer_charset(default_charset); | 452 set_referrer_charset(default_charset); |
384 set_accept_charset( | 453 set_accept_charset( |
385 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); | 454 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); |
386 } | 455 } |
OLD | NEW |