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" | |
36 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
37 #include "content/public/browser/cookie_crypto_delegate.h" | |
38 #include "content/public/browser/cookie_store_factory.h" | 36 #include "content/public/browser/cookie_store_factory.h" |
39 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
40 #include "content/public/browser/resource_context.h" | 38 #include "content/public/browser/resource_context.h" |
41 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
42 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
43 #include "net/base/cache_type.h" | 41 #include "net/base/cache_type.h" |
44 #include "net/ftp/ftp_network_layer.h" | 42 #include "net/ftp/ftp_network_layer.h" |
45 #include "net/http/http_cache.h" | 43 #include "net/http/http_cache.h" |
46 #include "net/ssl/server_bound_cert_service.h" | 44 #include "net/ssl/server_bound_cert_service.h" |
47 #include "net/url_request/protocol_intercept_job_factory.h" | 45 #include "net/url_request/protocol_intercept_job_factory.h" |
48 #include "net/url_request/url_request_job_factory_impl.h" | 46 #include "net/url_request/url_request_job_factory_impl.h" |
49 #include "webkit/browser/quota/special_storage_policy.h" | 47 #include "webkit/browser/quota/special_storage_policy.h" |
50 | 48 |
51 #if defined(OS_ANDROID) || defined(OS_IOS) | 49 #if defined(OS_ANDROID) || defined(OS_IOS) |
52 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" | 50 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h" |
53 #endif | 51 #endif |
54 | 52 |
55 namespace { | 53 namespace { |
56 | 54 |
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 | |
93 net::BackendType ChooseCacheBackendType() { | 55 net::BackendType ChooseCacheBackendType() { |
94 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 56 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
95 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { | 57 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { |
96 const std::string opt_value = | 58 const std::string opt_value = |
97 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); | 59 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); |
98 if (LowerCaseEqualsASCII(opt_value, "off")) | 60 if (LowerCaseEqualsASCII(opt_value, "off")) |
99 return net::CACHE_BACKEND_BLOCKFILE; | 61 return net::CACHE_BACKEND_BLOCKFILE; |
100 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) | 62 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) |
101 return net::CACHE_BACKEND_SIMPLE; | 63 return net::CACHE_BACKEND_SIMPLE; |
102 } | 64 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } | 397 } |
436 | 398 |
437 // setup cookie store | 399 // setup cookie store |
438 if (!cookie_store.get()) { | 400 if (!cookie_store.get()) { |
439 DCHECK(!lazy_params_->cookie_path.empty()); | 401 DCHECK(!lazy_params_->cookie_path.empty()); |
440 | 402 |
441 cookie_store = content::CreatePersistentCookieStore( | 403 cookie_store = content::CreatePersistentCookieStore( |
442 lazy_params_->cookie_path, | 404 lazy_params_->cookie_path, |
443 lazy_params_->restore_old_session_cookies, | 405 lazy_params_->restore_old_session_cookies, |
444 lazy_params_->special_storage_policy.get(), | 406 lazy_params_->special_storage_policy.get(), |
445 profile_params->cookie_monster_delegate.get(), | 407 profile_params->cookie_monster_delegate.get()); |
446 CreateCookieCryptoIfUseful()); | |
447 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); | 408 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); |
448 } | 409 } |
449 | 410 |
450 main_context->set_cookie_store(cookie_store.get()); | 411 main_context->set_cookie_store(cookie_store.get()); |
451 | 412 |
452 // Setup server bound cert service. | 413 // Setup server bound cert service. |
453 if (!server_bound_cert_service) { | 414 if (!server_bound_cert_service) { |
454 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 415 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
455 | 416 |
456 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 417 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 extensions_context->set_net_log(io_thread->net_log()); | 495 extensions_context->set_net_log(io_thread->net_log()); |
535 | 496 |
536 extensions_context->set_throttler_manager( | 497 extensions_context->set_throttler_manager( |
537 io_thread_globals->throttler_manager.get()); | 498 io_thread_globals->throttler_manager.get()); |
538 | 499 |
539 net::CookieStore* extensions_cookie_store = | 500 net::CookieStore* extensions_cookie_store = |
540 content::CreatePersistentCookieStore( | 501 content::CreatePersistentCookieStore( |
541 lazy_params_->extensions_cookie_path, | 502 lazy_params_->extensions_cookie_path, |
542 lazy_params_->restore_old_session_cookies, | 503 lazy_params_->restore_old_session_cookies, |
543 NULL, | 504 NULL, |
544 NULL, | 505 NULL); |
545 CreateCookieCryptoIfUseful()); | |
546 // Enable cookies for devtools and extension URLs. | 506 // Enable cookies for devtools and extension URLs. |
547 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 507 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
548 extensions::kExtensionScheme}; | 508 extensions::kExtensionScheme}; |
549 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); | 509 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); |
550 extensions_context->set_cookie_store(extensions_cookie_store); | 510 extensions_context->set_cookie_store(extensions_cookie_store); |
551 | 511 |
552 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( | 512 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
553 new net::URLRequestJobFactoryImpl()); | 513 new net::URLRequestJobFactoryImpl()); |
554 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 514 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
555 // Without a network_delegate, this protocol handler will never | 515 // Without a network_delegate, this protocol handler will never |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 if (!cookie_store.get()) { | 581 if (!cookie_store.get()) { |
622 DCHECK(!cookie_path.empty()); | 582 DCHECK(!cookie_path.empty()); |
623 | 583 |
624 // TODO(creis): We should have a cookie delegate for notifying the cookie | 584 // TODO(creis): We should have a cookie delegate for notifying the cookie |
625 // extensions API, but we need to update it to understand isolated apps | 585 // extensions API, but we need to update it to understand isolated apps |
626 // first. | 586 // first. |
627 cookie_store = content::CreatePersistentCookieStore( | 587 cookie_store = content::CreatePersistentCookieStore( |
628 cookie_path, | 588 cookie_path, |
629 false, | 589 false, |
630 NULL, | 590 NULL, |
631 NULL, | 591 NULL); |
632 CreateCookieCryptoIfUseful()); | |
633 } | 592 } |
634 | 593 |
635 // Transfer ownership of the cookies and cache to AppRequestContext. | 594 // Transfer ownership of the cookies and cache to AppRequestContext. |
636 context->SetCookieStore(cookie_store.get()); | 595 context->SetCookieStore(cookie_store.get()); |
637 context->SetHttpTransactionFactory( | 596 context->SetHttpTransactionFactory( |
638 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 597 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
639 | 598 |
640 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 599 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
641 new net::URLRequestJobFactoryImpl()); | 600 new net::URLRequestJobFactoryImpl()); |
642 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 601 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 const base::Closure& completion) { | 704 const base::Closure& completion) { |
746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
747 DCHECK(initialized()); | 706 DCHECK(initialized()); |
748 | 707 |
749 DCHECK(transport_security_state()); | 708 DCHECK(transport_security_state()); |
750 // Completes synchronously. | 709 // Completes synchronously. |
751 transport_security_state()->DeleteAllDynamicDataSince(time); | 710 transport_security_state()->DeleteAllDynamicDataSince(time); |
752 DCHECK(http_server_properties_manager_); | 711 DCHECK(http_server_properties_manager_); |
753 http_server_properties_manager_->Clear(completion); | 712 http_server_properties_manager_->Clear(completion); |
754 } | 713 } |
OLD | NEW |