| 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" |
| 35 #include "content/public/browser/cookie_store_factory.h" | 36 #include "content/public/browser/cookie_store_factory.h" |
| 36 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/resource_context.h" | 38 #include "content/public/browser/resource_context.h" |
| 38 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
| 39 #include "extensions/common/constants.h" | 40 #include "extensions/common/constants.h" |
| 40 #include "net/base/cache_type.h" | 41 #include "net/base/cache_type.h" |
| 41 #include "net/ftp/ftp_network_layer.h" | 42 #include "net/ftp/ftp_network_layer.h" |
| 42 #include "net/http/http_cache.h" | 43 #include "net/http/http_cache.h" |
| 43 #include "net/ssl/server_bound_cert_service.h" | 44 #include "net/ssl/server_bound_cert_service.h" |
| 44 #include "net/url_request/protocol_intercept_job_factory.h" | 45 #include "net/url_request/protocol_intercept_job_factory.h" |
| 45 #include "net/url_request/url_request_job_factory_impl.h" | 46 #include "net/url_request/url_request_job_factory_impl.h" |
| 46 #include "webkit/browser/quota/special_storage_policy.h" | 47 #include "webkit/browser/quota/special_storage_policy.h" |
| 47 | 48 |
| 48 #if defined(OS_ANDROID) | 49 #if defined(OS_ANDROID) |
| 49 #include "chrome/app/android/chrome_data_reduction_proxy_android.h" | 50 #include "chrome/app/android/chrome_data_reduction_proxy_android.h" |
| 50 #endif | 51 #endif |
| 51 | 52 |
| 53 // On operating systems that support an encryption API but don't |
| 54 // automatically protect all user data, encrypt the cookie. |
| 55 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
| 56 #define CRYPT_COOKIES |
| 57 #endif |
| 58 |
| 52 namespace { | 59 namespace { |
| 53 | 60 |
| 61 #if defined(CRYPT_COOKIES) |
| 62 class CookieOSCryptoDelegate : public content::CookieCryptoDelegate { |
| 63 public: |
| 64 virtual bool EncryptString(const std::string& plaintext, |
| 65 std::string* ciphertext) OVERRIDE; |
| 66 virtual bool DecryptString(const std::string& ciphertext, |
| 67 std::string* plaintext) OVERRIDE; |
| 68 }; |
| 69 |
| 70 bool CookieOSCryptoDelegate::EncryptString(const std::string& plaintext, |
| 71 std::string* ciphertext) { |
| 72 return Encryptor::EncryptString(plaintext, ciphertext); |
| 73 } |
| 74 |
| 75 bool CookieOSCryptoDelegate::DecryptString(const std::string& ciphertext, |
| 76 std::string* plaintext) { |
| 77 return Encryptor::DecryptString(ciphertext, plaintext); |
| 78 } |
| 79 #endif // CRYPT_COOKIES |
| 80 |
| 81 |
| 54 net::BackendType ChooseCacheBackendType() { | 82 net::BackendType ChooseCacheBackendType() { |
| 55 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 83 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 56 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { | 84 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { |
| 57 const std::string opt_value = | 85 const std::string opt_value = |
| 58 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); | 86 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); |
| 59 if (LowerCaseEqualsASCII(opt_value, "off")) | 87 if (LowerCaseEqualsASCII(opt_value, "off")) |
| 60 return net::CACHE_BACKEND_BLOCKFILE; | 88 return net::CACHE_BACKEND_BLOCKFILE; |
| 61 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) | 89 if (opt_value == "" || LowerCaseEqualsASCII(opt_value, "on")) |
| 62 return net::CACHE_BACKEND_SIMPLE; | 90 return net::CACHE_BACKEND_SIMPLE; |
| 63 } | 91 } |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 410 |
| 383 // setup cookie store | 411 // setup cookie store |
| 384 if (!cookie_store.get()) { | 412 if (!cookie_store.get()) { |
| 385 DCHECK(!lazy_params_->cookie_path.empty()); | 413 DCHECK(!lazy_params_->cookie_path.empty()); |
| 386 | 414 |
| 387 cookie_store = content::CreatePersistentCookieStore( | 415 cookie_store = content::CreatePersistentCookieStore( |
| 388 lazy_params_->cookie_path, | 416 lazy_params_->cookie_path, |
| 389 lazy_params_->restore_old_session_cookies, | 417 lazy_params_->restore_old_session_cookies, |
| 390 lazy_params_->special_storage_policy.get(), | 418 lazy_params_->special_storage_policy.get(), |
| 391 profile_params->cookie_monster_delegate.get(), | 419 profile_params->cookie_monster_delegate.get(), |
| 392 scoped_refptr<base::SequencedTaskRunner>()); | 420 scoped_refptr<base::SequencedTaskRunner>(), |
| 421 #if defined(CRYPT_COOKIES) |
| 422 new CookieOSCryptoDelegate |
| 423 #else |
| 424 NULL |
| 425 #endif |
| 426 ); |
| 393 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); | 427 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); |
| 394 } | 428 } |
| 395 | 429 |
| 396 main_context->set_cookie_store(cookie_store.get()); | 430 main_context->set_cookie_store(cookie_store.get()); |
| 397 | 431 |
| 398 // Setup server bound cert service. | 432 // Setup server bound cert service. |
| 399 if (!server_bound_cert_service) { | 433 if (!server_bound_cert_service) { |
| 400 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 434 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
| 401 | 435 |
| 402 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 436 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 512 |
| 479 extensions_context->set_throttler_manager( | 513 extensions_context->set_throttler_manager( |
| 480 io_thread_globals->throttler_manager.get()); | 514 io_thread_globals->throttler_manager.get()); |
| 481 | 515 |
| 482 net::CookieStore* extensions_cookie_store = | 516 net::CookieStore* extensions_cookie_store = |
| 483 content::CreatePersistentCookieStore( | 517 content::CreatePersistentCookieStore( |
| 484 lazy_params_->extensions_cookie_path, | 518 lazy_params_->extensions_cookie_path, |
| 485 lazy_params_->restore_old_session_cookies, | 519 lazy_params_->restore_old_session_cookies, |
| 486 NULL, | 520 NULL, |
| 487 NULL, | 521 NULL, |
| 488 scoped_refptr<base::SequencedTaskRunner>()); | 522 scoped_refptr<base::SequencedTaskRunner>(), |
| 523 #if defined(CRYPT_COOKIES) |
| 524 new CookieOSCryptoDelegate |
| 525 #else |
| 526 NULL |
| 527 #endif |
| 528 ); |
| 489 // Enable cookies for devtools and extension URLs. | 529 // Enable cookies for devtools and extension URLs. |
| 490 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 530 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
| 491 extensions::kExtensionScheme}; | 531 extensions::kExtensionScheme}; |
| 492 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); | 532 extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); |
| 493 extensions_context->set_cookie_store(extensions_cookie_store); | 533 extensions_context->set_cookie_store(extensions_cookie_store); |
| 494 | 534 |
| 495 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( | 535 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( |
| 496 new net::URLRequestJobFactoryImpl()); | 536 new net::URLRequestJobFactoryImpl()); |
| 497 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. | 537 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
| 498 // Without a network_delegate, this protocol handler will never | 538 // Without a network_delegate, this protocol handler will never |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 DCHECK(!cookie_path.empty()); | 605 DCHECK(!cookie_path.empty()); |
| 566 | 606 |
| 567 // TODO(creis): We should have a cookie delegate for notifying the cookie | 607 // TODO(creis): We should have a cookie delegate for notifying the cookie |
| 568 // extensions API, but we need to update it to understand isolated apps | 608 // extensions API, but we need to update it to understand isolated apps |
| 569 // first. | 609 // first. |
| 570 cookie_store = content::CreatePersistentCookieStore( | 610 cookie_store = content::CreatePersistentCookieStore( |
| 571 cookie_path, | 611 cookie_path, |
| 572 false, | 612 false, |
| 573 NULL, | 613 NULL, |
| 574 NULL, | 614 NULL, |
| 575 scoped_refptr<base::SequencedTaskRunner>()); | 615 scoped_refptr<base::SequencedTaskRunner>(), |
| 616 #if defined(CRYPT_COOKIES) |
| 617 new CookieOSCryptoDelegate |
| 618 #else |
| 619 NULL |
| 620 #endif |
| 621 ); |
| 576 } | 622 } |
| 577 | 623 |
| 578 // Transfer ownership of the cookies and cache to AppRequestContext. | 624 // Transfer ownership of the cookies and cache to AppRequestContext. |
| 579 context->SetCookieStore(cookie_store.get()); | 625 context->SetCookieStore(cookie_store.get()); |
| 580 context->SetHttpTransactionFactory( | 626 context->SetHttpTransactionFactory( |
| 581 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); | 627 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); |
| 582 | 628 |
| 583 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 629 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
| 584 new net::URLRequestJobFactoryImpl()); | 630 new net::URLRequestJobFactoryImpl()); |
| 585 InstallProtocolHandlers(job_factory.get(), protocol_handlers); | 631 InstallProtocolHandlers(job_factory.get(), protocol_handlers); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 const base::Closure& completion) { | 734 const base::Closure& completion) { |
| 689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 690 DCHECK(initialized()); | 736 DCHECK(initialized()); |
| 691 | 737 |
| 692 DCHECK(transport_security_state()); | 738 DCHECK(transport_security_state()); |
| 693 // Completes synchronously. | 739 // Completes synchronously. |
| 694 transport_security_state()->DeleteAllDynamicDataSince(time); | 740 transport_security_state()->DeleteAllDynamicDataSince(time); |
| 695 DCHECK(http_server_properties_manager_); | 741 DCHECK(http_server_properties_manager_); |
| 696 http_server_properties_manager_->Clear(completion); | 742 http_server_properties_manager_->Clear(completion); |
| 697 } | 743 } |
| OLD | NEW |