Chromium Code Reviews| 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 #include "chrome/browser/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/string_util.h" | |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/io_thread.h" | 13 #include "chrome/browser/io_thread.h" |
| 14 #include "chrome/browser/net/basic_http_user_agent_settings.h" | |
| 13 #include "chrome/browser/net/load_time_stats.h" | 15 #include "chrome/browser/net/load_time_stats.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_io_data.h" | 18 #include "chrome/browser/profiles/profile_io_data.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 22 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| 23 #include "net/cookies/cookie_store.h" | 25 #include "net/cookies/cookie_store.h" |
| 24 #include "net/http/http_util.h" | 26 #include "net/http/http_util.h" |
| 25 | 27 |
| 26 using content::BrowserThread; | 28 using content::BrowserThread; |
| 27 | 29 |
| 28 class ChromeURLRequestContextFactory { | 30 class ChromeURLRequestContextFactory { |
| 29 public: | 31 public: |
| 30 ChromeURLRequestContextFactory() {} | 32 ChromeURLRequestContextFactory() {} |
| 31 virtual ~ChromeURLRequestContextFactory() {} | 33 virtual ~ChromeURLRequestContextFactory() {} |
| 32 | 34 |
| 33 // Called to create a new instance (will only be called once). | 35 // Called to create a new instance (will only be called once). |
| 34 virtual ChromeURLRequestContext* Create() = 0; | 36 virtual ChromeURLRequestContext* Create() = 0; |
| 35 | 37 |
| 36 protected: | 38 protected: |
| 37 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); | 39 DISALLOW_COPY_AND_ASSIGN(ChromeURLRequestContextFactory); |
| 38 }; | 40 }; |
| 39 | 41 |
| 42 // Implementation of HttpUserAgentSettings for ChromeURLRequestContext | |
| 43 // that mirrors changes in Accept-Language and Accept-Charset from | |
| 44 // content's PrefService. | |
| 45 class ChromeHttpUserAgentSettings : public net::HttpUserAgentSettings { | |
| 46 public: | |
| 47 ChromeHttpUserAgentSettings() {} | |
| 48 virtual ~ChromeHttpUserAgentSettings() {} | |
| 49 | |
| 50 // net::HttpUserAgentSettings implementation. | |
| 51 virtual std::string GetAcceptLanguage() OVERRIDE { | |
| 52 return accept_language_; | |
| 53 } | |
| 54 virtual std::string GetAcceptCharset() OVERRIDE { | |
| 55 return accept_charset_; | |
| 56 } | |
| 57 virtual std::string GetUserAgent(const GURL& url) OVERRIDE { | |
| 58 return content::GetUserAgent(url); | |
| 59 } | |
| 60 | |
|
willchan no longer on Chromium
2012/10/06 19:32:49
too many newlines
| |
| 61 | |
| 62 // Sets the value of 'Accept-Charset' header field. | |
| 63 void set_accept_charset(const std::string& accept_charset) { | |
| 64 accept_charset_ = accept_charset; | |
| 65 } | |
| 66 | |
| 67 // Sets the value of 'Accept-Language' header field. | |
| 68 void set_accept_language(const std::string& accept_language) { | |
| 69 accept_language_ = accept_language; | |
| 70 } | |
| 71 | |
| 72 private: | |
| 73 std::string accept_language_; | |
| 74 std::string accept_charset_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(ChromeHttpUserAgentSettings); | |
| 77 }; | |
| 78 | |
| 40 namespace { | 79 namespace { |
| 41 | 80 |
| 42 // ---------------------------------------------------------------------------- | 81 // ---------------------------------------------------------------------------- |
| 43 // Helper factories | 82 // Helper factories |
| 44 // ---------------------------------------------------------------------------- | 83 // ---------------------------------------------------------------------------- |
| 45 | 84 |
| 46 // Factory that creates the main ChromeURLRequestContext. | 85 // Factory that creates the main ChromeURLRequestContext. |
| 47 class FactoryForMain : public ChromeURLRequestContextFactory { | 86 class FactoryForMain : public ChromeURLRequestContextFactory { |
| 48 public: | 87 public: |
| 49 explicit FactoryForMain(const ProfileIOData* profile_io_data) | 88 explicit FactoryForMain(const ProfileIOData* profile_io_data) |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 | 369 |
| 331 // ---------------------------------------------------------------------------- | 370 // ---------------------------------------------------------------------------- |
| 332 // ChromeURLRequestContext | 371 // ChromeURLRequestContext |
| 333 // ---------------------------------------------------------------------------- | 372 // ---------------------------------------------------------------------------- |
| 334 | 373 |
| 335 ChromeURLRequestContext::ChromeURLRequestContext( | 374 ChromeURLRequestContext::ChromeURLRequestContext( |
| 336 ContextType type, | 375 ContextType type, |
| 337 chrome_browser_net::LoadTimeStats* load_time_stats) | 376 chrome_browser_net::LoadTimeStats* load_time_stats) |
| 338 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 377 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 339 is_incognito_(false), | 378 is_incognito_(false), |
| 340 load_time_stats_(load_time_stats) { | 379 load_time_stats_(load_time_stats), |
| 380 chrome_http_user_agent_settings_(new ChromeHttpUserAgentSettings) { | |
| 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 342 if (load_time_stats_) | 382 if (load_time_stats_) |
| 343 load_time_stats_->RegisterURLRequestContext(this, type); | 383 load_time_stats_->RegisterURLRequestContext(this, type); |
| 384 set_http_user_agent_settings(chrome_http_user_agent_settings_.get()); | |
|
willchan no longer on Chromium
2012/10/06 19:32:49
Sorry if someone called this out earlier and there
erikwright (departed)
2012/10/09 15:24:46
When you call CopyFrom, you get all of the other c
willchan no longer on Chromium
2012/10/09 22:58:56
I think it's been the case for a long time. See pr
| |
| 344 } | 385 } |
| 345 | 386 |
| 346 ChromeURLRequestContext::~ChromeURLRequestContext() { | 387 ChromeURLRequestContext::~ChromeURLRequestContext() { |
| 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 348 if (load_time_stats_) | 389 if (load_time_stats_) |
| 349 load_time_stats_->UnregisterURLRequestContext(this); | 390 load_time_stats_->UnregisterURLRequestContext(this); |
| 350 } | 391 } |
| 351 | 392 |
| 352 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { | 393 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { |
| 353 URLRequestContext::CopyFrom(other); | 394 URLRequestContext::CopyFrom(other); |
| 354 | 395 |
| 355 // Copy ChromeURLRequestContext parameters. | 396 // Copy ChromeURLRequestContext parameters. |
| 356 // ChromeURLDataManagerBackend is unique per context. | 397 // ChromeURLDataManagerBackend is unique per context. |
| 357 set_is_incognito(other->is_incognito()); | 398 set_is_incognito(other->is_incognito()); |
| 358 } | 399 } |
| 359 | 400 |
| 360 ChromeURLDataManagerBackend* | 401 ChromeURLDataManagerBackend* |
| 361 ChromeURLRequestContext::chrome_url_data_manager_backend() const { | 402 ChromeURLRequestContext::chrome_url_data_manager_backend() const { |
| 362 return chrome_url_data_manager_backend_; | 403 return chrome_url_data_manager_backend_; |
| 363 } | 404 } |
| 364 | 405 |
| 365 void ChromeURLRequestContext::set_chrome_url_data_manager_backend( | 406 void ChromeURLRequestContext::set_chrome_url_data_manager_backend( |
| 366 ChromeURLDataManagerBackend* backend) { | 407 ChromeURLDataManagerBackend* backend) { |
| 367 DCHECK(backend); | 408 DCHECK(backend); |
| 368 chrome_url_data_manager_backend_ = backend; | 409 chrome_url_data_manager_backend_ = backend; |
| 369 } | 410 } |
| 370 | 411 |
| 371 const std::string& ChromeURLRequestContext::GetUserAgent( | |
| 372 const GURL& url) const { | |
| 373 return content::GetUserAgent(url); | |
| 374 } | |
| 375 | |
| 376 void ChromeURLRequestContext::OnAcceptLanguageChange( | 412 void ChromeURLRequestContext::OnAcceptLanguageChange( |
| 377 const std::string& accept_language) { | 413 const std::string& accept_language) { |
| 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 379 set_accept_language( | 415 chrome_http_user_agent_settings_->set_accept_language( |
| 380 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); | 416 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); |
| 381 } | 417 } |
| 382 | 418 |
| 383 void ChromeURLRequestContext::OnDefaultCharsetChange( | 419 void ChromeURLRequestContext::OnDefaultCharsetChange( |
| 384 const std::string& default_charset) { | 420 const std::string& default_charset) { |
| 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 386 set_referrer_charset(default_charset); | 422 set_referrer_charset(default_charset); |
| 387 set_accept_charset( | 423 chrome_http_user_agent_settings_->set_accept_charset( |
| 388 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); | 424 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); |
| 389 } | 425 } |
| OLD | NEW |