| 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/profiles/profile_impl_io_data.h" | 5 #include "chrome/browser/profiles/profile_impl_io_data.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/net/chrome_network_delegate.h" | 25 #include "chrome/browser/net/chrome_network_delegate.h" |
| 26 #include "chrome/browser/net/connect_interceptor.h" | 26 #include "chrome/browser/net/connect_interceptor.h" |
| 27 #include "chrome/browser/net/http_server_properties_manager.h" | 27 #include "chrome/browser/net/http_server_properties_manager.h" |
| 28 #include "chrome/browser/net/predictor.h" | 28 #include "chrome/browser/net/predictor.h" |
| 29 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" | 29 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 35 #include "components/webdata/encryptor/encryptor.h" |
| 35 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/cookie_crypto_delegate.h" |
| 36 #include "content/public/browser/cookie_store_factory.h" | 38 #include "content/public/browser/cookie_store_factory.h" |
| 37 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 38 #include "content/public/browser/resource_context.h" | 40 #include "content/public/browser/resource_context.h" |
| 39 #include "content/public/browser/storage_partition.h" | 41 #include "content/public/browser/storage_partition.h" |
| 40 #include "extensions/common/constants.h" | 42 #include "extensions/common/constants.h" |
| 41 #include "net/base/cache_type.h" | 43 #include "net/base/cache_type.h" |
| 42 #include "net/ftp/ftp_network_layer.h" | 44 #include "net/ftp/ftp_network_layer.h" |
| 43 #include "net/http/http_cache.h" | 45 #include "net/http/http_cache.h" |
| 44 #include "net/ssl/server_bound_cert_service.h" | 46 #include "net/ssl/server_bound_cert_service.h" |
| 45 #include "net/url_request/protocol_intercept_job_factory.h" | 47 #include "net/url_request/protocol_intercept_job_factory.h" |
| 46 #include "net/url_request/url_request_job_factory_impl.h" | 48 #include "net/url_request/url_request_job_factory_impl.h" |
| 47 #include "webkit/browser/quota/special_storage_policy.h" | 49 #include "webkit/browser/quota/special_storage_policy.h" |
| 48 | 50 |
| 49 #if defined(OS_ANDROID) || defined(OS_IOS) | 51 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 50 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" | 52 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" |
| 51 #endif | 53 #endif |
| 52 | 54 |
| 53 namespace { | 55 namespace { |
| 54 | 56 |
| 57 // Use the operating system's mechanisms to encrypt cookies before writing |
| 58 // them to persistent store. Currently this only is done with desktop OS's |
| 59 // because ChromeOS and Android already protect the entire profile contents. |
| 60 // |
| 61 // TODO(bcwhite): Enable on MACOSX -- requires all Cookie tests to call |
| 62 // Encryptor::UseMockKeychain or will hang waiting for user input. |
| 63 #if defined(OS_WIN) || defined(OS_LINUX) // || defined(OS_MACOSX) |
| 64 class CookieOSCryptoDelegate : public content::CookieCryptoDelegate { |
| 65 public: |
| 66 virtual bool EncryptString(const std::string& plaintext, |
| 67 std::string* ciphertext) OVERRIDE; |
| 68 virtual bool DecryptString(const std::string& ciphertext, |
| 69 std::string* plaintext) OVERRIDE; |
| 70 }; |
| 71 |
| 72 bool CookieOSCryptoDelegate::EncryptString(const std::string& plaintext, |
| 73 std::string* ciphertext) { |
| 74 return Encryptor::EncryptString(plaintext, ciphertext); |
| 75 } |
| 76 |
| 77 bool CookieOSCryptoDelegate::DecryptString(const std::string& ciphertext, |
| 78 std::string* plaintext) { |
| 79 return Encryptor::DecryptString(ciphertext, plaintext); |
| 80 } |
| 81 |
| 82 scoped_ptr<content::CookieCryptoDelegate> CreateCookieCryptoIfUseful() { |
| 83 return scoped_ptr<content::CookieCryptoDelegate>( |
| 84 new CookieOSCryptoDelegate); |
| 85 } |
| 86 #else |
| 87 scoped_ptr<content::CookieCryptoDelegate> CreateCookieCryptoIfUseful() { |
| 88 return scoped_ptr<content::CookieCryptoDelegate>(); |
| 89 } |
| 90 #endif |
| 91 |
| 92 |
| 55 net::BackendType ChooseCacheBackendType() { | 93 net::BackendType ChooseCacheBackendType() { |
| 56 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 94 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 57 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { | 95 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { |
| 58 const std::string opt_value = | 96 const std::string opt_value = |
| 59 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); | 97 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); |
| 60 if (LowerCaseEqualsASCII(opt_value, "off")) | 98 if (LowerCaseEqualsASCII(opt_value, "off")) |
| 61 return net::CACHE_BACKEND_BLOCKFILE; | 99 return net::CACHE_BACKEND_BLOCKFILE; |
| 62 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) | 100 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) |
| 63 return net::CACHE_BACKEND_SIMPLE; | 101 return net::CACHE_BACKEND_SIMPLE; |
| 64 } | 102 } |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 435 } |
| 398 | 436 |
| 399 // setup cookie store | 437 // setup cookie store |
| 400 if (!cookie_store.get()) { | 438 if (!cookie_store.get()) { |
| 401 DCHECK(!lazy_params_->cookie_path.empty()); | 439 DCHECK(!lazy_params_->cookie_path.empty()); |
| 402 | 440 |
| 403 cookie_store = content::CreatePersistentCookieStore( | 441 cookie_store = content::CreatePersistentCookieStore( |
| 404 lazy_params_->cookie_path, | 442 lazy_params_->cookie_path, |
| 405 lazy_params_->restore_old_session_cookies, | 443 lazy_params_->restore_old_session_cookies, |
| 406 lazy_params_->special_storage_policy.get(), | 444 lazy_params_->special_storage_policy.get(), |
| 407 profile_params->cookie_monster_delegate.get()); | 445 profile_params->cookie_monster_delegate.get(), |
| 446 CreateCookieCryptoIfUseful()); |
| 408 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); | 447 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); |
| 409 } | 448 } |
| 410 | 449 |
| 411 main_context->set_cookie_store(cookie_store.get()); | 450 main_context->set_cookie_store(cookie_store.get()); |
| 412 | 451 |
| 413 // Setup server bound cert service. | 452 // Setup server bound cert service. |
| 414 if (!server_bound_cert_service) { | 453 if (!server_bound_cert_service) { |
| 415 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 454 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
| 416 | 455 |
| 417 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 456 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 extensions_context->set_net_log(io_thread->net_log()); | 534 extensions_context->set_net_log(io_thread->net_log()); |
| 496 | 535 |
| 497 extensions_context->set_throttler_manager( | 536 extensions_context->set_throttler_manager( |
| 498 io_thread_globals->throttler_manager.get()); | 537 io_thread_globals->throttler_manager.get()); |
| 499 | 538 |
| 500 net::CookieStore* extensions_cookie_store = | 539 net::CookieStore* extensions_cookie_store = |
| 501 content::CreatePersistentCookieStore( | 540 content::CreatePersistentCookieStore( |
| 502 lazy_params_->extensions_cookie_path, | 541 lazy_params_->extensions_cookie_path, |
| 503 lazy_params_->restore_old_session_cookies, | 542 lazy_params_->restore_old_session_cookies, |
| 504 NULL, | 543 NULL, |
| 505 NULL); | 544 NULL, |
| 545 CreateCookieCryptoIfUseful()); |
| 506 // Enable cookies for devtools and extension URLs. | 546 // Enable cookies for devtools and extension URLs. |
| 507 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 547 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
| 508 extensions::kExtensionScheme}; | 548 extensions::kExtensionScheme}; |
| 509 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); | 549 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); |
| 510 extensions_context->set_cookie_store(extensions_cookie_store); | 550 extensions_context->set_cookie_store(extensions_cookie_store); |
| 511 | 551 |
| 512 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( | 552 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
| 513 new net::URLRequestJobFactoryImpl()); | 553 new net::URLRequestJobFactoryImpl()); |
| 514 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 554 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| 515 // Without a network_delegate, this protocol handler will never | 555 // Without a network_delegate, this protocol handler will never |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 if (!cookie_store.get()) { | 621 if (!cookie_store.get()) { |
| 582 DCHECK(!cookie_path.empty()); | 622 DCHECK(!cookie_path.empty()); |
| 583 | 623 |
| 584 // TODO(creis): We should have a cookie delegate for notifying the cookie | 624 // TODO(creis): We should have a cookie delegate for notifying the cookie |
| 585 // extensions API, but we need to update it to understand isolated apps | 625 // extensions API, but we need to update it to understand isolated apps |
| 586 // first. | 626 // first. |
| 587 cookie_store = content::CreatePersistentCookieStore( | 627 cookie_store = content::CreatePersistentCookieStore( |
| 588 cookie_path, | 628 cookie_path, |
| 589 false, | 629 false, |
| 590 NULL, | 630 NULL, |
| 591 NULL); | 631 NULL, |
| 632 CreateCookieCryptoIfUseful()); |
| 592 } | 633 } |
| 593 | 634 |
| 594 // Transfer ownership of the cookies and cache to AppRequestContext. | 635 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 595 context->SetCookieStore(cookie_store.get()); | 636 context->SetCookieStore(cookie_store.get()); |
| 596 context->SetHttpTransactionFactory( | 637 context->SetHttpTransactionFactory( |
| 597 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 638 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
| 598 | 639 |
| 599 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 640 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 600 new net::URLRequestJobFactoryImpl()); | 641 new net::URLRequestJobFactoryImpl()); |
| 601 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 642 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 const base::Closure& completion) { | 745 const base::Closure& completion) { |
| 705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 706 DCHECK(initialized()); | 747 DCHECK(initialized()); |
| 707 | 748 |
| 708 DCHECK(transport_security_state()); | 749 DCHECK(transport_security_state()); |
| 709 // Completes synchronously. | 750 // Completes synchronously. |
| 710 transport_security_state()->DeleteAllDynamicDataSince(time); | 751 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 711 DCHECK(http_server_properties_manager_); | 752 DCHECK(http_server_properties_manager_); |
| 712 http_server_properties_manager_->Clear(completion); | 753 http_server_properties_manager_->Clear(completion); |
| 713 } | 754 } |
| OLD | NEW |