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 BasicHttpUserAgentSettings { | |
|
erikwright (departed)
2012/09/21 15:06:33
Hmm. It's kind of funny that this inherits from Ba
| |
| 46 public: | |
| 47 ChromeHttpUserAgentSettings() | |
| 48 : BasicHttpUserAgentSettings(EmptyString(), EmptyString()) {} | |
| 49 virtual ~ChromeHttpUserAgentSettings() {} | |
| 50 | |
| 51 // net::HttpUserAgentSettings implementation. | |
| 52 virtual const std::string& GetAcceptLanguage() OVERRIDE { | |
| 53 return accept_language_; | |
| 54 } | |
| 55 virtual const std::string& GetAcceptCharset() OVERRIDE { | |
| 56 return accept_charset_; | |
| 57 } | |
| 58 | |
| 59 // Sets the value of 'Accept-Charset' header field. | |
| 60 void set_accept_charset(const std::string& accept_charset) { | |
| 61 accept_charset_ = accept_charset; | |
| 62 } | |
| 63 | |
| 64 // Sets the value of 'Accept-Language' header field. | |
| 65 void set_accept_language(const std::string& accept_language) { | |
| 66 accept_language_ = accept_language; | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 std::string accept_language_; | |
| 71 std::string accept_charset_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(ChromeHttpUserAgentSettings); | |
| 74 }; | |
| 75 | |
| 40 namespace { | 76 namespace { |
| 41 | 77 |
| 42 // ---------------------------------------------------------------------------- | 78 // ---------------------------------------------------------------------------- |
| 43 // Helper factories | 79 // Helper factories |
| 44 // ---------------------------------------------------------------------------- | 80 // ---------------------------------------------------------------------------- |
| 45 | 81 |
| 46 // Factory that creates the main ChromeURLRequestContext. | 82 // Factory that creates the main ChromeURLRequestContext. |
| 47 class FactoryForMain : public ChromeURLRequestContextFactory { | 83 class FactoryForMain : public ChromeURLRequestContextFactory { |
| 48 public: | 84 public: |
| 49 explicit FactoryForMain(const ProfileIOData* profile_io_data) | 85 explicit FactoryForMain(const ProfileIOData* profile_io_data) |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 | 366 |
| 331 // ---------------------------------------------------------------------------- | 367 // ---------------------------------------------------------------------------- |
| 332 // ChromeURLRequestContext | 368 // ChromeURLRequestContext |
| 333 // ---------------------------------------------------------------------------- | 369 // ---------------------------------------------------------------------------- |
| 334 | 370 |
| 335 ChromeURLRequestContext::ChromeURLRequestContext( | 371 ChromeURLRequestContext::ChromeURLRequestContext( |
| 336 ContextType type, | 372 ContextType type, |
| 337 chrome_browser_net::LoadTimeStats* load_time_stats) | 373 chrome_browser_net::LoadTimeStats* load_time_stats) |
| 338 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 374 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 339 is_incognito_(false), | 375 is_incognito_(false), |
| 340 load_time_stats_(load_time_stats) { | 376 load_time_stats_(load_time_stats), |
| 377 chrome_http_user_agent_settings_(new ChromeHttpUserAgentSettings) { | |
| 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 342 if (load_time_stats_) | 379 if (load_time_stats_) |
| 343 load_time_stats_->RegisterURLRequestContext(this, type); | 380 load_time_stats_->RegisterURLRequestContext(this, type); |
| 381 set_http_user_agent_settings(chrome_http_user_agent_settings_.get()); | |
| 344 } | 382 } |
| 345 | 383 |
| 346 ChromeURLRequestContext::~ChromeURLRequestContext() { | 384 ChromeURLRequestContext::~ChromeURLRequestContext() { |
| 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 348 if (load_time_stats_) | 386 if (load_time_stats_) |
| 349 load_time_stats_->UnregisterURLRequestContext(this); | 387 load_time_stats_->UnregisterURLRequestContext(this); |
| 350 } | 388 } |
| 351 | 389 |
| 352 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { | 390 void ChromeURLRequestContext::CopyFrom(ChromeURLRequestContext* other) { |
| 353 URLRequestContext::CopyFrom(other); | 391 URLRequestContext::CopyFrom(other); |
| 354 | 392 |
| 355 // Copy ChromeURLRequestContext parameters. | 393 // Copy ChromeURLRequestContext parameters. |
| 356 // ChromeURLDataManagerBackend is unique per context. | 394 // ChromeURLDataManagerBackend is unique per context. |
| 357 set_is_incognito(other->is_incognito()); | 395 set_is_incognito(other->is_incognito()); |
| 358 } | 396 } |
| 359 | 397 |
| 360 ChromeURLDataManagerBackend* | 398 ChromeURLDataManagerBackend* |
| 361 ChromeURLRequestContext::chrome_url_data_manager_backend() const { | 399 ChromeURLRequestContext::chrome_url_data_manager_backend() const { |
| 362 return chrome_url_data_manager_backend_; | 400 return chrome_url_data_manager_backend_; |
| 363 } | 401 } |
| 364 | 402 |
| 365 void ChromeURLRequestContext::set_chrome_url_data_manager_backend( | 403 void ChromeURLRequestContext::set_chrome_url_data_manager_backend( |
| 366 ChromeURLDataManagerBackend* backend) { | 404 ChromeURLDataManagerBackend* backend) { |
| 367 DCHECK(backend); | 405 DCHECK(backend); |
| 368 chrome_url_data_manager_backend_ = backend; | 406 chrome_url_data_manager_backend_ = backend; |
| 369 } | 407 } |
| 370 | 408 |
| 371 const std::string& ChromeURLRequestContext::GetUserAgent( | |
| 372 const GURL& url) const { | |
| 373 return content::GetUserAgent(url); | |
| 374 } | |
| 375 | |
| 376 void ChromeURLRequestContext::OnAcceptLanguageChange( | 409 void ChromeURLRequestContext::OnAcceptLanguageChange( |
| 377 const std::string& accept_language) { | 410 const std::string& accept_language) { |
| 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 379 set_accept_language( | 412 chrome_http_user_agent_settings_->set_accept_language( |
| 380 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); | 413 net::HttpUtil::GenerateAcceptLanguageHeader(accept_language)); |
| 381 } | 414 } |
| 382 | 415 |
| 383 void ChromeURLRequestContext::OnDefaultCharsetChange( | 416 void ChromeURLRequestContext::OnDefaultCharsetChange( |
| 384 const std::string& default_charset) { | 417 const std::string& default_charset) { |
| 385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 386 set_referrer_charset(default_charset); | 419 set_referrer_charset(default_charset); |
| 387 set_accept_charset( | 420 chrome_http_user_agent_settings_->set_accept_charset( |
| 388 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); | 421 net::HttpUtil::GenerateAcceptCharsetHeader(default_charset)); |
| 389 } | 422 } |
| OLD | NEW |