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/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 13 matching lines...) Expand all Loading... | |
| 24 #include "chrome/browser/net/chrome_network_delegate.h" | 24 #include "chrome/browser/net/chrome_network_delegate.h" |
| 25 #include "chrome/browser/net/connect_interceptor.h" | 25 #include "chrome/browser/net/connect_interceptor.h" |
| 26 #include "chrome/browser/net/http_server_properties_manager.h" | 26 #include "chrome/browser/net/http_server_properties_manager.h" |
| 27 #include "chrome/browser/net/predictor.h" | 27 #include "chrome/browser/net/predictor.h" |
| 28 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" | 28 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 34 #include "components/webdata/encryptor/encryptor.h" | |
| 34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/cookie_crypto_delegate.h" | |
| 35 #include "content/public/browser/cookie_store_factory.h" | 37 #include "content/public/browser/cookie_store_factory.h" |
| 36 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/resource_context.h" | 39 #include "content/public/browser/resource_context.h" |
| 38 #include "content/public/browser/storage_partition.h" | 40 #include "content/public/browser/storage_partition.h" |
| 39 #include "extensions/common/constants.h" | 41 #include "extensions/common/constants.h" |
| 40 #include "net/base/cache_type.h" | 42 #include "net/base/cache_type.h" |
| 41 #include "net/ftp/ftp_network_layer.h" | 43 #include "net/ftp/ftp_network_layer.h" |
| 42 #include "net/http/http_cache.h" | 44 #include "net/http/http_cache.h" |
| 43 #include "net/ssl/server_bound_cert_service.h" | 45 #include "net/ssl/server_bound_cert_service.h" |
| 44 #include "net/url_request/protocol_intercept_job_factory.h" | 46 #include "net/url_request/protocol_intercept_job_factory.h" |
| 45 #include "net/url_request/url_request_job_factory_impl.h" | 47 #include "net/url_request/url_request_job_factory_impl.h" |
| 46 #include "webkit/browser/quota/special_storage_policy.h" | 48 #include "webkit/browser/quota/special_storage_policy.h" |
| 47 | 49 |
| 48 #if defined(OS_ANDROID) | 50 #if defined(OS_ANDROID) |
| 49 #include "chrome/app/android/chrome_data_reduction_proxy_android.h" | 51 #include "chrome/app/android/chrome_data_reduction_proxy_android.h" |
| 50 #endif | 52 #endif |
| 51 | 53 |
| 54 // On operating systems that support an encryption API but don't | |
| 55 // automatically protect all user data, encrypt the cookie. | |
| 56 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | |
| 57 #define CRYPT_COOKIES | |
| 58 #endif | |
| 59 | |
| 52 namespace { | 60 namespace { |
| 53 | 61 |
| 62 #if defined(CRYPT_COOKIES) | |
| 63 class CookieOSCryptoDelegate : public content::CookieCryptoDelegate { | |
| 64 public: | |
| 65 virtual bool EncryptString(const std::string& plaintext, | |
| 66 std::string* ciphertext) OVERRIDE; | |
| 67 virtual bool DecryptString(const std::string& ciphertext, | |
| 68 std::string* plaintext) OVERRIDE; | |
| 69 }; | |
| 70 | |
| 71 bool CookieOSCryptoDelegate::EncryptString(const std::string& plaintext, | |
| 72 std::string* ciphertext) { | |
| 73 return Encryptor::EncryptString(plaintext, ciphertext); | |
| 74 } | |
| 75 | |
| 76 bool CookieOSCryptoDelegate::DecryptString(const std::string& ciphertext, | |
| 77 std::string* plaintext) { | |
| 78 return Encryptor::DecryptString(ciphertext, plaintext); | |
| 79 } | |
| 80 #endif // CRYPT_COOKIES | |
| 81 | |
| 82 | |
| 54 net::BackendType ChooseCacheBackendType() { | 83 net::BackendType ChooseCacheBackendType() { |
| 55 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 84 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 56 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { | 85 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { |
| 57 const std::string opt_value = | 86 const std::string opt_value = |
| 58 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); | 87 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); |
| 59 if (LowerCaseEqualsASCII(opt_value, "off")) | 88 if (LowerCaseEqualsASCII(opt_value, "off")) |
| 60 return net::CACHE_BACKEND_BLOCKFILE; | 89 return net::CACHE_BACKEND_BLOCKFILE; |
| 61 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) | 90 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) |
| 62 return net::CACHE_BACKEND_SIMPLE; | 91 return net::CACHE_BACKEND_SIMPLE; |
| 63 } | 92 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 | 416 |
| 388 // setup cookie store | 417 // setup cookie store |
| 389 if (!cookie_store.get()) { | 418 if (!cookie_store.get()) { |
| 390 DCHECK(!lazy_params_->cookie_path.empty()); | 419 DCHECK(!lazy_params_->cookie_path.empty()); |
| 391 | 420 |
| 392 cookie_store = content::CreatePersistentCookieStore( | 421 cookie_store = content::CreatePersistentCookieStore( |
| 393 lazy_params_->cookie_path, | 422 lazy_params_->cookie_path, |
| 394 lazy_params_->restore_old_session_cookies, | 423 lazy_params_->restore_old_session_cookies, |
| 395 lazy_params_->special_storage_policy.get(), | 424 lazy_params_->special_storage_policy.get(), |
| 396 profile_params->cookie_monster_delegate.get(), | 425 profile_params->cookie_monster_delegate.get(), |
| 397 scoped_refptr<base::SequencedTaskRunner>()); | 426 scoped_refptr<base::SequencedTaskRunner>(), |
| 427 #if defined(CRYPT_COOKIES) | |
| 428 new CookieOSCryptoDelegate | |
| 429 #else | |
| 430 NULL | |
| 431 #endif | |
| 432 ); | |
|
Scott Hess - ex-Googler
2013/10/08 17:35:55
Definitely defer to Erik on this, but ...
Would i
bcwhite
2013/10/08 18:23:36
All OS support it. It's only some OS that it's ne
erikwright (departed)
2013/10/08 18:41:53
It makes me a bit ill, but maybe "MaybeCreate()"?
Scott Hess - ex-Googler
2013/10/08 19:13:51
I don't feel strongly about it. Repeated #ifdef a
bcwhite
2013/10/08 20:18:09
It makes sense just to get rid of the repeated #if
Scott Hess - ex-Googler
2013/10/08 21:22:13
Except to make the code more convoluted!
I am not
bcwhite
2013/10/10 17:19:30
Comment improved.
| |
| 398 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); | 433 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); |
| 399 } | 434 } |
| 400 | 435 |
| 401 main_context->set_cookie_store(cookie_store.get()); | 436 main_context->set_cookie_store(cookie_store.get()); |
| 402 | 437 |
| 403 // Setup server bound cert service. | 438 // Setup server bound cert service. |
| 404 if (!server_bound_cert_service) { | 439 if (!server_bound_cert_service) { |
| 405 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 440 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
| 406 | 441 |
| 407 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 442 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 | 518 |
| 484 extensions_context->set_throttler_manager( | 519 extensions_context->set_throttler_manager( |
| 485 io_thread_globals->throttler_manager.get()); | 520 io_thread_globals->throttler_manager.get()); |
| 486 | 521 |
| 487 net::CookieStore* extensions_cookie_store = | 522 net::CookieStore* extensions_cookie_store = |
| 488 content::CreatePersistentCookieStore( | 523 content::CreatePersistentCookieStore( |
| 489 lazy_params_->extensions_cookie_path, | 524 lazy_params_->extensions_cookie_path, |
| 490 lazy_params_->restore_old_session_cookies, | 525 lazy_params_->restore_old_session_cookies, |
| 491 NULL, | 526 NULL, |
| 492 NULL, | 527 NULL, |
| 493 scoped_refptr<base::SequencedTaskRunner>()); | 528 scoped_refptr<base::SequencedTaskRunner>(), |
| 529 #if defined(CRYPT_COOKIES) | |
| 530 new CookieOSCryptoDelegate | |
| 531 #else | |
| 532 NULL | |
| 533 #endif | |
| 534 ); | |
| 494 // Enable cookies for devtools and extension URLs. | 535 // Enable cookies for devtools and extension URLs. |
| 495 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 536 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
| 496 extensions::kExtensionScheme}; | 537 extensions::kExtensionScheme}; |
| 497 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); | 538 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); |
| 498 extensions_context->set_cookie_store(extensions_cookie_store); | 539 extensions_context->set_cookie_store(extensions_cookie_store); |
| 499 | 540 |
| 500 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( | 541 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
| 501 new net::URLRequestJobFactoryImpl()); | 542 new net::URLRequestJobFactoryImpl()); |
| 502 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 543 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| 503 // Without a network_delegate, this protocol handler will never | 544 // Without a network_delegate, this protocol handler will never |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 DCHECK(!cookie_path.empty()); | 611 DCHECK(!cookie_path.empty()); |
| 571 | 612 |
| 572 // TODO(creis): We should have a cookie delegate for notifying the cookie | 613 // TODO(creis): We should have a cookie delegate for notifying the cookie |
| 573 // extensions API, but we need to update it to understand isolated apps | 614 // extensions API, but we need to update it to understand isolated apps |
| 574 // first. | 615 // first. |
| 575 cookie_store = content::CreatePersistentCookieStore( | 616 cookie_store = content::CreatePersistentCookieStore( |
| 576 cookie_path, | 617 cookie_path, |
| 577 false, | 618 false, |
| 578 NULL, | 619 NULL, |
| 579 NULL, | 620 NULL, |
| 580 scoped_refptr<base::SequencedTaskRunner>()); | 621 scoped_refptr<base::SequencedTaskRunner>(), |
| 622 #if defined(CRYPT_COOKIES) | |
| 623 new CookieOSCryptoDelegate | |
| 624 #else | |
| 625 NULL | |
| 626 #endif | |
| 627 ); | |
| 581 } | 628 } |
| 582 | 629 |
| 583 // Transfer ownership of the cookies and cache to AppRequestContext. | 630 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 584 context->SetCookieStore(cookie_store.get()); | 631 context->SetCookieStore(cookie_store.get()); |
| 585 context->SetHttpTransactionFactory( | 632 context->SetHttpTransactionFactory( |
| 586 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 633 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
| 587 | 634 |
| 588 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 635 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 589 new net::URLRequestJobFactoryImpl()); | 636 new net::URLRequestJobFactoryImpl()); |
| 590 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 637 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 const base::Closure& completion) { | 740 const base::Closure& completion) { |
| 694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 695 DCHECK(initialized()); | 742 DCHECK(initialized()); |
| 696 | 743 |
| 697 DCHECK(transport_security_state()); | 744 DCHECK(transport_security_state()); |
| 698 // Completes synchronously. | 745 // Completes synchronously. |
| 699 transport_security_state()->DeleteAllDynamicDataSince(time); | 746 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 700 DCHECK(http_server_properties_manager_); | 747 DCHECK(http_server_properties_manager_); |
| 701 http_server_properties_manager_->Clear(completion); | 748 http_server_properties_manager_->Clear(completion); |
| 702 } | 749 } |
| OLD | NEW |