diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc index 09b1002f1ffa..334c55011165 100644 --- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc +++ b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc @@ -42,13 +42,13 @@ #include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager_observer.h" +#include "content/public/browser/cookie_store_factory.h" #include "content/public/browser/dom_storage_context.h" #include "content/public/browser/local_storage_usage_info.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/storage_partition.h" #include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread_bundle.h" -#include "net/cookies/cookie_monster.h" #include "net/ssl/server_bound_cert_service.h" #include "net/ssl/server_bound_cert_store.h" #include "net/ssl/ssl_client_cert_type.h" @@ -298,7 +298,7 @@ class RemoveSafeBrowsingCookieTester : public RemoveCookieTester { // Create a cookiemonster that does not have persistant storage, and replace // the SafeBrowsingService created one with it. - net::CookieStore* monster = new net::CookieMonster(NULL, NULL); + net::CookieStore* monster = content::CreateInMemoryCookieStore(NULL); sb_service->url_request_context()->GetURLRequestContext()-> set_cookie_store(monster); SetMonster(monster); diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 66230089445f..b88dff81a417 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -45,6 +45,7 @@ #include "chrome/common/url_constants.h" #include "components/policy/core/common/policy_service.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/cookie_store_factory.h" #include "net/base/host_mapping_rules.h" #include "net/base/net_util.h" #include "net/base/network_time_notifier.h" @@ -52,7 +53,6 @@ #include "net/cert/cert_verifier.h" #include "net/cert/ct_known_logs.h" #include "net/cert/ct_verifier.h" -#include "net/cookies/cookie_monster.h" #include "net/dns/host_cache.h" #include "net/dns/host_resolver.h" #include "net/dns/mapped_host_resolver.h" @@ -594,7 +594,7 @@ void IOThread::InitAsync() { globals_->proxy_script_fetcher_proxy_service.reset( net::ProxyService::CreateDirectWithNetLog(net_log_)); // In-memory cookie store. - globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); + globals_->system_cookie_store = content::CreateInMemoryCookieStore(NULL); // In-memory server bound cert store. globals_->system_server_bound_cert_service.reset( new net::ServerBoundCertService( @@ -725,12 +725,6 @@ void IOThread::CleanUp() { } void IOThread::InitializeNetworkOptions(const CommandLine& command_line) { - if (command_line.HasSwitch(switches::kEnableFileCookies)) { - // Enable cookie storage for file:// URLs. Must do this before the first - // Profile (and therefore the first CookieMonster) is created. - net::CookieMonster::EnableFileScheme(); - } - // Only handle use-spdy command line flags if "spdy.disabled" preference is // not disabled via policy. if (is_spdy_disabled_by_policy_) { diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc index 37255151db3a..48483b034c1b 100644 --- a/chrome/browser/net/connection_tester.cc +++ b/chrome/browser/net/connection_tester.cc @@ -15,12 +15,12 @@ #include "base/threading/thread_restrictions.h" #include "chrome/common/chrome_switches.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/cookie_store_factory.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" #include "net/base/request_priority.h" #include "net/cert/cert_verifier.h" -#include "net/cookies/cookie_monster.h" #include "net/dns/host_resolver.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" @@ -132,7 +132,7 @@ class ExperimentURLRequestContext : public net::URLRequestContext { storage_.set_http_transaction_factory(new net::HttpCache( network_session.get(), net::HttpCache::DefaultBackend::InMemory(0))); // In-memory cookie store. - storage_.set_cookie_store(new net::CookieMonster(NULL, NULL)); + storage_.set_cookie_store(content::CreateInMemoryCookieStore(NULL)); return net::OK; } diff --git a/chrome/browser/net/connection_tester_unittest.cc b/chrome/browser/net/connection_tester_unittest.cc index f5ecb59f1e8e..530c7a853380 100644 --- a/chrome/browser/net/connection_tester_unittest.cc +++ b/chrome/browser/net/connection_tester_unittest.cc @@ -6,8 +6,8 @@ #include "base/prefs/testing_pref_service.h" #include "content/public/test/test_browser_thread.h" +#include "content/public/browser/cookie_store_factory.h" #include "net/cert/mock_cert_verifier.h" -#include "net/cookies/cookie_monster.h" #include "net/dns/mock_host_resolver.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_auth_handler_factory.h" @@ -148,7 +148,7 @@ class ConnectionTesterTest : public PlatformTest { http_transaction_factory_.get()); // In-memory cookie store. proxy_script_fetcher_context_->set_cookie_store( - new net::CookieMonster(NULL, NULL)); + content::CreateInMemoryCookieStore(NULL)); } }; diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc index 3a5562c1197f..4e20401c7932 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -24,6 +24,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/cookie_store_factory.h" #include "content/public/browser/resource_context.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" @@ -200,8 +201,9 @@ void OffTheRecordProfileIOData::InitializeInternal( set_server_bound_cert_service(server_bound_cert_service); main_context->set_server_bound_cert_service(server_bound_cert_service); - main_context->set_cookie_store(new net::CookieMonster( - NULL, profile_params->cookie_monster_delegate.get())); + main_context->set_cookie_store( + content::CreateInMemoryCookieStore( + profile_params->cookie_monster_delegate.get())); net::HttpCache::BackendFactory* main_backend = net::HttpCache::DefaultBackend::InMemory(0); @@ -252,7 +254,7 @@ void OffTheRecordProfileIOData:: // All we care about for extensions is the cookie store. For incognito, we // use a non-persistent cookie store. net::CookieMonster* extensions_cookie_store = - new net::CookieMonster(NULL, NULL); + content::CreateInMemoryCookieStore(NULL)->GetCookieMonster(); // Enable cookies for devtools and extension URLs. const char* schemes[] = {chrome::kChromeDevToolsScheme, extensions::kExtensionScheme}; @@ -290,7 +292,7 @@ OffTheRecordProfileIOData::InitializeAppRequestContext( // Use a separate in-memory cookie store for the app. // TODO(creis): We should have a cookie delegate for notifying the cookie // extensions API, but we need to update it to understand isolated apps first. - context->SetCookieStore(new net::CookieMonster(NULL, NULL)); + context->SetCookieStore(content::CreateInMemoryCookieStore(NULL)); // Use a separate in-memory cache for the app. net::HttpCache::BackendFactory* app_backend = diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index f3d7cad36976..d85b6a307e7b 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -426,8 +426,8 @@ void ProfileImplIOData::InitializeInternal( net::ServerBoundCertService* server_bound_cert_service = NULL; if (record_mode || playback_mode) { // Don't use existing cookies and use an in-memory store. - cookie_store = new net::CookieMonster( - NULL, profile_params->cookie_monster_delegate.get()); + cookie_store = content::CreateInMemoryCookieStore( + profile_params->cookie_monster_delegate.get()); // Don't use existing server-bound certs and use an in-memory store. server_bound_cert_service = new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), @@ -606,13 +606,13 @@ ProfileImplIOData::InitializeAppRequestContext( scoped_refptr cookie_store = NULL; if (partition_descriptor.in_memory) { - cookie_store = new net::CookieMonster(NULL, NULL); + cookie_store = content::CreateInMemoryCookieStore(NULL); } else if (record_mode || playback_mode) { // Don't use existing cookies and use an in-memory store. // TODO(creis): We should have a cookie delegate for notifying the cookie // extensions API, but we need to update it to understand isolated apps // first. - cookie_store = new net::CookieMonster(NULL, NULL); + cookie_store = content::CreateInMemoryCookieStore(NULL); app_http_cache->set_mode( record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); } diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 9154eda7bfec..d315e2e8438d 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -638,10 +638,6 @@ const char kEnableExtensionActivityLogTesting[] = // crbug.com/142458 . const char kEnableFastUnload[] = "enable-fast-unload"; -// By default, cookies are not allowed on file://. They are needed for testing, -// for example page cycler and layout tests. See bug 1157243. -const char kEnableFileCookies[] = "enable-file-cookies"; - // Enables Google Now integration. const char kEnableGoogleNowIntegration[] = "enable-google-now-integration"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 454a776baada..dc3030ed1c0d 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -182,7 +182,6 @@ extern const char kEnableEphemeralApps[]; extern const char kEnableExtensionActivityLogging[]; extern const char kEnableExtensionActivityLogTesting[]; extern const char kEnableFastUnload[]; -extern const char kEnableFileCookies[]; extern const char kEnableGoogleNowIntegration[]; extern const char kEnableHttp2Draft04[]; extern const char kEnableWebBasedSignin[]; diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 54aff8303e12..40e2c6f90a33 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -63,6 +63,7 @@ #include "components/policy/core/common/policy_service.h" #include "components/user_prefs/user_prefs.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/cookie_store_factory.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/storage_partition.h" @@ -123,7 +124,8 @@ class QuittingHistoryDBTask : public history::HistoryDBTask { class TestExtensionURLRequestContext : public net::URLRequestContext { public: TestExtensionURLRequestContext() { - net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); + net::CookieMonster* cookie_monster = + content::CreateInMemoryCookieStore(NULL)->GetCookieMonster(); const char* schemes[] = {extensions::kExtensionScheme}; cookie_monster->SetCookieableSchemes(schemes, 1); set_cookie_store(cookie_monster); diff --git a/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc b/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc index 4aa3fe1a43fa..aa2cb43c069e 100644 --- a/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc +++ b/components/autofill/content/browser/wallet/wallet_signin_helper_unittest.cc @@ -11,6 +11,7 @@ #include "chrome/test/base/testing_profile.h" #include "components/autofill/content/browser/wallet/wallet_service_url.h" #include "components/autofill/content/browser/wallet/wallet_signin_helper_delegate.h" +#include "content/public/browser/cookie_store_factory.h" #include "content/public/test/test_browser_thread_bundle.h" #include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_urls.h" @@ -125,7 +126,8 @@ TEST_F(WalletSigninHelperTest, PassiveSigninFailedSigninNo) { TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenPresent) { EXPECT_CALL(mock_delegate_, OnDidFetchWalletCookieValue("gdToken")); - net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); + net::CookieMonster* cookie_monster = + content::CreateInMemoryCookieStore(NULL)->GetCookieMonster(); net::CookieOptions httponly_options; httponly_options.set_include_httponly(); scoped_ptr cookie( @@ -145,7 +147,8 @@ TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenPresent) { TEST_F(WalletSigninHelperTest, GetWalletCookieValueWhenMissing) { EXPECT_CALL(mock_delegate_, OnDidFetchWalletCookieValue(std::string())); - net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); + net::CookieMonster* cookie_monster = + content::CreateInMemoryCookieStore(NULL)->GetCookieMonster(); net::CookieOptions httponly_options; httponly_options.set_include_httponly(); scoped_ptr cookie( diff --git a/content/browser/net/sqlite_persistent_cookie_store.cc b/content/browser/net/sqlite_persistent_cookie_store.cc index e2b788033142..6386f85d3cb2 100644 --- a/content/browser/net/sqlite_persistent_cookie_store.cc +++ b/content/browser/net/sqlite_persistent_cookie_store.cc @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/bind.h" #include "base/callback.h" +#include "base/command_line.h" #include "base/file_util.h" #include "base/files/file_path.h" #include "base/location.h" @@ -28,6 +29,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_crypto_delegate.h" #include "content/public/browser/cookie_store_factory.h" +#include "content/public/common/content_switches.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/cookie_constants.h" @@ -1264,7 +1266,25 @@ net::CookieStore* CreatePersistentCookieStore( restore_old_session_cookies, storage_policy, crypto_delegate.Pass()); - return new net::CookieMonster(persistent_store, cookie_monster_delegate); + + net::CookieMonster* cookie_monster = + new net::CookieMonster(persistent_store, cookie_monster_delegate); + + // In the case of Android WebView, the cookie store may be created + // before the browser process fully initializes -- certainly before + // the main loop ever runs. In this situation, the CommandLine singleton + // will not have been set up. Android tests do not need file cookies + // so always ignore them here. + // + // TODO(ajwong): Remove the InitializedForCurrentProcess() check + // once http://crbug.com/331424 is resolved. + if (CommandLine::InitializedForCurrentProcess() && + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableFileCookies)) { + cookie_monster->SetEnableFileScheme(true); + } + + return cookie_monster; } net::CookieStore* CreatePersistentCookieStore( @@ -1284,4 +1304,16 @@ net::CookieStore* CreatePersistentCookieStore( crypto_delegate.Pass()); } +net::CookieStore* CreateInMemoryCookieStore( + net::CookieMonster::Delegate* cookie_monster_delegate) { + net::CookieMonster* cookie_monster = + new net::CookieMonster(NULL, cookie_monster_delegate); + if (CommandLine::InitializedForCurrentProcess() && + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableFileCookies)) { + cookie_monster->SetEnableFileScheme(true); + } + return cookie_monster; +} + } // namespace content diff --git a/content/public/browser/cookie_store_factory.h b/content/public/browser/cookie_store_factory.h index 300178ed85cf..41f90ee35884 100644 --- a/content/public/browser/cookie_store_factory.h +++ b/content/public/browser/cookie_store_factory.h @@ -38,6 +38,9 @@ CONTENT_EXPORT net::CookieStore* CreatePersistentCookieStore( net::CookieMonster::Delegate* cookie_monster_delegate, scoped_ptr crypto_delegate); +CONTENT_EXPORT net::CookieStore* CreateInMemoryCookieStore( + net::CookieMonster::Delegate* cookie_monster_delegate); + } // namespace content #endif // CONTENT_PUBLIC_BROWSER_COOKIE_STORE_FACTORY_H_ diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index 3e7142975a6d..be4cfa8b0b65 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -441,6 +441,10 @@ const char kEnableExperimentalWebPlatformFeatures[] = // Enable an experimental WebSocket implementation. const char kEnableExperimentalWebSocket[] = "enable-experimental-websocket"; +// By default, cookies are not allowed on file://. They are needed for testing, +// for example page cycler and layout tests. See bug 1157243. +const char kEnableFileCookies[] = "enable-file-cookies"; + // Enable the fast text autosizing implementation. const char kEnableFastTextAutosizing[] = "enable-fast-text-autosizing"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index f30a39197983..95c4844ccde9 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -133,6 +133,7 @@ CONTENT_EXPORT extern const char kEnableExperimentalCanvasFeatures[]; CONTENT_EXPORT extern const char kEnableExperimentalWebPlatformFeatures[]; CONTENT_EXPORT extern const char kEnableExperimentalWebSocket[]; extern const char kEnableFastTextAutosizing[]; +CONTENT_EXPORT extern const char kEnableFileCookies[]; CONTENT_EXPORT extern const char kEnableFixedPositionCreatesStackingContext[]; CONTENT_EXPORT extern const char kEnableGestureTapHighlight[]; extern const char kEnableGpuBenchmarking[]; diff --git a/content/shell/app/shell_main_delegate.cc b/content/shell/app/shell_main_delegate.cc index 9867be78e750..acdc87511752 100644 --- a/content/shell/app/shell_main_delegate.cc +++ b/content/shell/app/shell_main_delegate.cc @@ -171,7 +171,7 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { command_line.AppendSwitch(switches::kDisableDelegatedRenderer); #endif - net::CookieMonster::EnableFileScheme(); + command_line.AppendSwitch(switches::kEnableFileCookies); // Unless/until WebM files are added to the media layout tests, we need to // avoid removing MP4/H264/AAC so that layout tests can run on Android. diff --git a/content/shell/browser/shell_url_request_context_getter.cc b/content/shell/browser/shell_url_request_context_getter.cc index 6df718ded052..c31b26c229a5 100644 --- a/content/shell/browser/shell_url_request_context_getter.cc +++ b/content/shell/browser/shell_url_request_context_getter.cc @@ -12,6 +12,7 @@ #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/cookie_store_factory.h" #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "content/shell/browser/shell_network_delegate.h" @@ -101,7 +102,7 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); - storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); + storage_->set_cookie_store(CreateInMemoryCookieStore(NULL)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), base::WorkerPool::GetTaskRunner(true))); diff --git a/content/test/test_webkit_platform_support.cc b/content/test/test_webkit_platform_support.cc index a25483088479..373953576f6d 100644 --- a/content/test/test_webkit_platform_support.cc +++ b/content/test/test_webkit_platform_support.cc @@ -11,6 +11,7 @@ #include "base/metrics/stats_counters.h" #include "base/path_service.h" #include "base/strings/utf_string_conversions.h" +#include "content/public/common/content_switches.h" #include "content/test/mock_webclipboard_impl.h" #include "content/test/web_gesture_curve_mock.h" #include "content/test/web_layer_tree_view_impl_for_testing.h" @@ -100,7 +101,7 @@ TestWebKitPlatformSupport::TestWebKitPlatformSupport() { SetThemeEngine(NULL); #endif - net::CookieMonster::EnableFileScheme(); + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableFileCookies); // Test shell always exposes the GC. webkit_glue::SetJavaScriptFlags(" --expose-gc"); diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc index 15c7143a608e..d6eccf46a103 100644 --- a/net/cookies/cookie_monster.cc +++ b/net/cookies/cookie_monster.cc @@ -254,40 +254,40 @@ CookieMonster::CookieItVector::iterator LowerBoundAccessDate( LowerBoundAccessDateComparator); } -// Mapping between DeletionCause and Delegate::ChangeCause; the mapping also -// provides a boolean that specifies whether or not an OnCookieChanged -// notification ought to be generated. +// Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the +// mapping also provides a boolean that specifies whether or not an +// OnCookieChanged notification ought to be generated. typedef struct ChangeCausePair_struct { - CookieMonster::Delegate::ChangeCause cause; + CookieMonsterDelegate::ChangeCause cause; bool notify; } ChangeCausePair; ChangeCausePair ChangeCauseMapping[] = { // DELETE_COOKIE_EXPLICIT - { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true }, // DELETE_COOKIE_OVERWRITE - { CookieMonster::Delegate::CHANGE_COOKIE_OVERWRITE, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true }, // DELETE_COOKIE_EXPIRED - { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true }, // DELETE_COOKIE_EVICTED - { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE - { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }, + { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, // DELETE_COOKIE_DONT_RECORD - { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }, + { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, // DELETE_COOKIE_EVICTED_DOMAIN - { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EVICTED_GLOBAL - { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE - { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE - { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, // DELETE_COOKIE_EXPIRED_OVERWRITE - { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, + { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, // DELETE_COOKIE_CONTROL_CHAR - { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true}, + { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true}, // DELETE_COOKIE_LAST_ENTRY - { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false } + { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false } }; std::string BuildCookieLine(const CanonicalCookieVector& cookies) { @@ -308,10 +308,8 @@ std::string BuildCookieLine(const CanonicalCookieVector& cookies) { } // namespace -// static -bool CookieMonster::default_enable_file_scheme_ = false; - -CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) +CookieMonster::CookieMonster(PersistentCookieStore* store, + CookieMonsterDelegate* delegate) : initialized_(false), loaded_(false), store_(store), @@ -326,7 +324,7 @@ CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) } CookieMonster::CookieMonster(PersistentCookieStore* store, - Delegate* delegate, + CookieMonsterDelegate* delegate, int last_access_threshold_milliseconds) : initialized_(false), loaded_(false), @@ -1289,11 +1287,6 @@ void CookieMonster::SetKeepExpiredCookies() { keep_expired_cookies_ = true; } -// static -void CookieMonster::EnableFileScheme() { - default_enable_file_scheme_ = true; -} - void CookieMonster::FlushStore(const base::Closure& callback) { base::AutoLock autolock(lock_); if (initialized_ && store_.get()) @@ -1673,9 +1666,9 @@ const int CookieMonster::kDefaultCookieableSchemesCount = arraysize(kDefaultCookieableSchemes); void CookieMonster::SetDefaultCookieableSchemes() { - int num_schemes = default_enable_file_scheme_ ? - kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1; - SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); + // Always disable file scheme unless SetEnableFileScheme(true) is called. + SetCookieableSchemes(kDefaultCookieableSchemes, + kDefaultCookieableSchemesCount - 1); } void CookieMonster::FindCookiesForHostAndDomain( @@ -1777,7 +1770,7 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( cookies_.insert(CookieMap::value_type(key, cc)); if (delegate_.get()) { delegate_->OnCookieChanged( - *cc, false, Delegate::CHANGE_COOKIE_EXPLICIT); + *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); } return inserted; diff --git a/net/cookies/cookie_monster.h b/net/cookies/cookie_monster.h index 3e2ed6ddd0fb..455484ef1ba2 100644 --- a/net/cookies/cookie_monster.h +++ b/net/cookies/cookie_monster.h @@ -37,6 +37,7 @@ class TimeTicks; namespace net { +class CookieMonsterDelegate; class ParsedCookie; // The cookie monster is the system for storing and retrieving cookies. It has @@ -65,8 +66,8 @@ class ParsedCookie; // - Verify that our domain enforcement and non-dotted handling is correct class NET_EXPORT CookieMonster : public CookieStore { public: - class Delegate; class PersistentCookieStore; + typedef CookieMonsterDelegate Delegate; // Terminology: // * The 'top level domain' (TLD) of an internet domain name is @@ -138,11 +139,11 @@ class NET_EXPORT CookieMonster : public CookieStore { // monster's existence. If |store| is NULL, then no backing store will be // updated. If |delegate| is non-NULL, it will be notified on // creation/deletion of cookies. - CookieMonster(PersistentCookieStore* store, Delegate* delegate); + CookieMonster(PersistentCookieStore* store, CookieMonsterDelegate* delegate); // Only used during unit testing. CookieMonster(PersistentCookieStore* store, - Delegate* delegate, + CookieMonsterDelegate* delegate, int last_access_threshold_milliseconds); // Helper function that adds all cookies from |list| into this instance. @@ -216,6 +217,10 @@ class NET_EXPORT CookieMonster : public CookieStore { // Resets the list of cookieable schemes to kDefaultCookieableSchemes with or // without 'file' being included. + // + // There are some unknowns about how to correctly handle file:// cookies, + // and our implementation for this is not robust enough. This allows you + // to enable support, but it should only be used for testing. Bug 1157243. void SetEnableFileScheme(bool accept); // Instructs the cookie monster to not delete expired cookies. This is used @@ -226,12 +231,6 @@ class NET_EXPORT CookieMonster : public CookieStore { // Protects session cookies from deletion on shutdown. void SetForceKeepSessionState(); - // There are some unknowns about how to correctly handle file:// cookies, - // and our implementation for this is not robust enough. This allows you - // to enable support, but it should only be used for testing. Bug 1157243. - // Must be called before creating a CookieMonster instance. - static void EnableFileScheme(); - // Flush the backing store (if any) to disk and post the given callback when // done. // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. @@ -352,8 +351,8 @@ class NET_EXPORT CookieMonster : public CookieStore { // and to provide a public cause for onCookieChange notifications. // // If you add or remove causes from this list, please be sure to also update - // the Delegate::ChangeCause mapping inside ChangeCauseMapping. Moreover, - // these are used as array indexes, so avoid reordering to keep the + // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping. + // Moreover, these are used as array indexes, so avoid reordering to keep the // histogram buckets consistent. New items (if necessary) should be added // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. enum DeletionCause { @@ -546,9 +545,9 @@ class NET_EXPORT CookieMonster : public CookieStore { const base::Time& current_time); // |deletion_cause| argument is used for collecting statistics and choosing - // the correct Delegate::ChangeCause for OnCookieChanged notifications. - // Guarantee: All iterators to cookies_ except to the deleted entry remain - // vaild. + // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged + // notifications. Guarantee: All iterators to cookies_ except to the + // deleted entry remain vaild. void InternalDeleteCookie(CookieMap::iterator it, bool sync_to_store, DeletionCause deletion_cause); @@ -670,7 +669,7 @@ class NET_EXPORT CookieMonster : public CookieStore { std::vector cookieable_schemes_; - scoped_refptr delegate_; + scoped_refptr delegate_; // Lock for thread-safety base::Lock lock_; @@ -688,8 +687,8 @@ class NET_EXPORT CookieMonster : public CookieStore { DISALLOW_COPY_AND_ASSIGN(CookieMonster); }; -class NET_EXPORT CookieMonster::Delegate - : public base::RefCountedThreadSafe { +class NET_EXPORT CookieMonsterDelegate + : public base::RefCountedThreadSafe { public: // The publicly relevant reasons a cookie might be changed. enum ChangeCause { @@ -721,8 +720,8 @@ class NET_EXPORT CookieMonster::Delegate bool removed, ChangeCause cause) = 0; protected: - friend class base::RefCountedThreadSafe; - virtual ~Delegate() {} + friend class base::RefCountedThreadSafe; + virtual ~CookieMonsterDelegate() {} }; typedef base::RefCountedThreadSafe diff --git a/net/cookies/cookie_monster_store_test.h b/net/cookies/cookie_monster_store_test.h index d7da52104be2..ec40de625d98 100644 --- a/net/cookies/cookie_monster_store_test.h +++ b/net/cookies/cookie_monster_store_test.h @@ -115,8 +115,8 @@ class MockPersistentCookieStore DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); }; -// Mock for CookieMonster::Delegate -class MockCookieMonsterDelegate : public CookieMonster::Delegate { +// Mock for CookieMonsterDelegate +class MockCookieMonsterDelegate : public CookieMonsterDelegate { public: typedef std::pair CookieNotification; @@ -130,7 +130,7 @@ class MockCookieMonsterDelegate : public CookieMonster::Delegate { virtual void OnCookieChanged( const CanonicalCookie& cookie, bool removed, - CookieMonster::Delegate::ChangeCause cause) OVERRIDE; + CookieMonsterDelegate::ChangeCause cause) OVERRIDE; private: virtual ~MockCookieMonsterDelegate(); diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc index 69d98a1862ac..0e01f2845d16 100644 --- a/net/cookies/cookie_monster_unittest.cc +++ b/net/cookies/cookie_monster_unittest.cc @@ -1546,7 +1546,7 @@ TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { EXPECT_NE(name1, name2); } -TEST_F(CookieMonsterTest, Delegate) { +TEST_F(CookieMonsterTest, CookieMonsterDelegate) { scoped_refptr store( new MockPersistentCookieStore); scoped_refptr delegate( diff --git a/net/cookies/cookie_store.h b/net/cookies/cookie_store.h index 7dee857457fc..730f7106a766 100644 --- a/net/cookies/cookie_store.h +++ b/net/cookies/cookie_store.h @@ -33,7 +33,6 @@ class NET_EXPORT CookieStore : public base::RefCountedThreadSafe { typedef base::Callback SetCookiesCallback; typedef base::Callback DeleteCallback; - // Sets a single cookie. Expects a cookie line, like "a=1; domain=b.com". // // Fails either if the cookie is invalid or if this is a non-HTTPONLY cookie