diff options
author | earthdok@chromium.org <earthdok@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-27 14:39:08 +0000 |
---|---|---|
committer | earthdok@chromium.org <earthdok@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-27 14:39:08 +0000 |
commit | 33ad6ce948e24e01ec1634af63001dda4ac0506a (patch) | |
tree | 71daec231014a7b05e1a213e2ac0a9a41f4ca52a /chrome | |
parent | d0a60eea5c90a5b594604c91654859a493e1b5cb (diff) | |
download | chromium_src-33ad6ce948e24e01ec1634af63001dda4ac0506a.zip chromium_src-33ad6ce948e24e01ec1634af63001dda4ac0506a.tar.gz chromium_src-33ad6ce948e24e01ec1634af63001dda4ac0506a.tar.bz2 |
Revert 219709 "Remove the Extensions URLRequestContext."
Reverted due to crashes under memory tools.
BUG=280138
> Remove the Extensions URLRequestContext.
>
> Though chrome-extension: scheme URLs support cookies, they do not share
> a namespace with http: and https:. In particular, chrome-extension://a and
> http://a should not have the same set of cookies.
>
> To enforce this, previously the code created a completely separate
> URLRequestContext for servicing chrome-extension: schemes. However,
> the code really only used this object as a method for conveying the
> correct cookie jar from Profile creation to a few spots where cookies
> were accessed; the rest of the URLRequestContext functionality was unused.
>
> This CL removes the Extensions URLRequestContext code and replaces it
> with APIs that directly expose the needed net::CookieStore.
>
> Lastly, CookieMonster::EnableFileScheme() is removed and
> CookieMonster::Delegate is renamed CookieMonsterDelegate.
>
> EnableFileScheme is an inherently racy API because
> CookieMonsters are creatable on all threads and this
> function sets an unprotected global flag. CookieMonsterDelegate
> is preferable to the nested interface because it can now be
> forward declared.
>
> TBRing darin and sky to cover the rest of the mechanical unittest changes.
>
> TBR=darin,sky
> BUG=158386,159193,57884
>
> Review URL: https://chromiumcodereview.appspot.com/12546016
TBR=ajwong@chromium.org
Review URL: https://codereview.chromium.org/23551005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219787 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
74 files changed, 824 insertions, 655 deletions
diff --git a/chrome/browser/autocomplete/bookmark_provider_unittest.cc b/chrome/browser/autocomplete/bookmark_provider_unittest.cc index 71ee42b..b48bf39 100644 --- a/chrome/browser/autocomplete/bookmark_provider_unittest.cc +++ b/chrome/browser/autocomplete/bookmark_provider_unittest.cc @@ -18,7 +18,6 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" // The bookmark corpus against which we will simulate searches. @@ -63,7 +62,6 @@ class BookmarkProviderTest : public testing::Test, protected: virtual void SetUp() OVERRIDE; - scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; scoped_ptr<TestingProfile> profile_; scoped_ptr<BookmarkModel> model_; scoped_refptr<BookmarkProvider> provider_; @@ -73,7 +71,6 @@ class BookmarkProviderTest : public testing::Test, }; void BookmarkProviderTest::SetUp() { - thread_bundle_.reset(new content::TestBrowserThreadBundle()); profile_.reset(new TestingProfile()); DCHECK(profile_.get()); provider_ = new BookmarkProvider(this, profile_.get()); diff --git a/chrome/browser/background/background_contents_service_unittest.cc b/chrome/browser/background/background_contents_service_unittest.cc index f739fda..a58cfbc 100644 --- a/chrome/browser/background/background_contents_service_unittest.cc +++ b/chrome/browser/background/background_contents_service_unittest.cc @@ -8,7 +8,6 @@ #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/prefs/pref_service.h" -#include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/background/background_contents_service.h" #include "chrome/browser/background/background_contents_service_factory.h" @@ -17,39 +16,19 @@ #include "chrome/browser/tab_contents/background_contents.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/pref_names.h" -#include "chrome/test/base/scoped_testing_local_state.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/testing_profile_manager.h" #include "content/public/browser/notification_service.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" -#include "ui/message_center/message_center.h" #include "url/gurl.h" class BackgroundContentsServiceTest : public testing::Test { - protected: - BackgroundContentsServiceTest() - : command_line_(CommandLine::NO_PROGRAM), - profile_manager_(TestingBrowserProcess::GetGlobal()), - profile_(NULL) { - CHECK(profile_manager_.SetUp()); - profile_ = profile_manager_.CreateTestingProfile("TestProfile"); - service_.reset(new BackgroundContentsService(profile_, &command_line_)); - BackgroundContentsServiceFactory::GetInstance()-> - RegisterUserPrefsOnBrowserContext(profile_); - } - - virtual ~BackgroundContentsServiceTest() { - base::RunLoop().RunUntilIdle(); - } - - static void SetUpTestCase() { - message_center::MessageCenter::Initialize(); - } - static void TearDownTestCase() { - message_center::MessageCenter::Shutdown(); + public: + BackgroundContentsServiceTest() {} + virtual ~BackgroundContentsServiceTest() {} + virtual void SetUp() { + command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); } const DictionaryValue* GetPrefs(Profile* profile) { @@ -68,11 +47,7 @@ class BackgroundContentsServiceTest : public testing::Test { return url; } - content::TestBrowserThreadBundle thread_bundle; - CommandLine command_line_; - TestingProfileManager profile_manager_; - TestingProfile* profile_; // Not owned. - scoped_ptr<BackgroundContentsService> service_; + scoped_ptr<CommandLine> command_line_; }; class MockBackgroundContents : public BackgroundContents { @@ -122,87 +97,104 @@ class MockBackgroundContents : public BackgroundContents { private: GURL url_; - // The ID of our parent application. + // The ID of our parent application string16 appid_; - // Parent profile. Not owned. + // Parent profile Profile* profile_; }; TEST_F(BackgroundContentsServiceTest, Create) { - // Check for creation and leaks when the basic objects in the - // fixtures are created/destructed. + // Check for creation and leaks. + TestingProfile profile; + BackgroundContentsService service(&profile, command_line_.get()); } TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) { - MockBackgroundContents* contents = new MockBackgroundContents(profile_); - EXPECT_FALSE(service_->IsTracked(contents)); - contents->SendOpenedNotification(service_.get()); - EXPECT_TRUE(service_->IsTracked(contents)); + TestingProfile profile; + BackgroundContentsService service(&profile, command_line_.get()); + MockBackgroundContents* contents = new MockBackgroundContents(&profile); + EXPECT_FALSE(service.IsTracked(contents)); + contents->SendOpenedNotification(&service); + EXPECT_TRUE(service.IsTracked(contents)); delete contents; - EXPECT_FALSE(service_->IsTracked(contents)); + EXPECT_FALSE(service.IsTracked(contents)); } TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) { + TestingProfile profile; + BackgroundContentsService service(&profile, command_line_.get()); + BackgroundContentsServiceFactory::GetInstance()-> + RegisterUserPrefsOnBrowserContext(&profile); GURL orig_url; GURL url("http://a/"); GURL url2("http://a/"); { scoped_ptr<MockBackgroundContents> contents( - new MockBackgroundContents(profile_)); - EXPECT_EQ(0U, GetPrefs(profile_)->size()); - contents->SendOpenedNotification(service_.get()); + new MockBackgroundContents(&profile)); + EXPECT_EQ(0U, GetPrefs(&profile)->size()); + contents->SendOpenedNotification(&service); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(profile_)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); // Navigate the contents to a new url, should not change url. contents->Navigate(url2); - EXPECT_EQ(1U, GetPrefs(profile_)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); } // Contents are deleted, url should persist. - EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); } TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) { + TestingProfile profile; + BackgroundContentsService service(&profile, command_line_.get()); + BackgroundContentsServiceFactory::GetInstance()-> + RegisterUserPrefsOnBrowserContext(&profile); + GURL url("http://a/"); - MockBackgroundContents* contents = new MockBackgroundContents(profile_); - EXPECT_EQ(0U, GetPrefs(profile_)->size()); - contents->SendOpenedNotification(service_.get()); + MockBackgroundContents* contents = new MockBackgroundContents(&profile); + EXPECT_EQ(0U, GetPrefs(&profile)->size()); + contents->SendOpenedNotification(&service); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(profile_)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); // Fake a window closed by script. - contents->MockClose(profile_); - EXPECT_EQ(0U, GetPrefs(profile_)->size()); + contents->MockClose(&profile); + EXPECT_EQ(0U, GetPrefs(&profile)->size()); } // Test what happens if a BackgroundContents shuts down (say, due to a renderer // crash) then is restarted. Should not persist URL twice. TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) { + TestingProfile profile; + BackgroundContentsService service(&profile, command_line_.get()); + BackgroundContentsServiceFactory::GetInstance()-> + RegisterUserPrefsOnBrowserContext(&profile); + GURL url("http://a/"); { scoped_ptr<MockBackgroundContents> contents(new MockBackgroundContents( - profile_, "appid")); - contents->SendOpenedNotification(service_.get()); + &profile, "appid")); + contents->SendOpenedNotification(&service); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(profile_)->size()); - EXPECT_EQ(url.spec(), GetPrefURLForApp(profile_, contents->appid())); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); } // Contents deleted, url should be persisted. - EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); { // Reopen the BackgroundContents to the same URL, we should not register the // URL again. scoped_ptr<MockBackgroundContents> contents(new MockBackgroundContents( - profile_, "appid")); - contents->SendOpenedNotification(service_.get()); + &profile, "appid")); + contents->SendOpenedNotification(&service); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); } } @@ -210,29 +202,34 @@ TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) { // between a BackgroundContents and its parent extension, including // unregistering the BC when the extension is uninstalled. TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) { - EXPECT_EQ(NULL, service_->GetAppBackgroundContents(ASCIIToUTF16("appid"))); - MockBackgroundContents* contents = new MockBackgroundContents(profile_, + TestingProfile profile; + BackgroundContentsService service(&profile, command_line_.get()); + BackgroundContentsServiceFactory::GetInstance()-> + RegisterUserPrefsOnBrowserContext(&profile); + + EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); + MockBackgroundContents* contents = new MockBackgroundContents(&profile, "appid"); scoped_ptr<MockBackgroundContents> contents2( - new MockBackgroundContents(profile_, "appid2")); - contents->SendOpenedNotification(service_.get()); - EXPECT_EQ(contents, service_->GetAppBackgroundContents(contents->appid())); - contents2->SendOpenedNotification(service_.get()); - EXPECT_EQ(contents2.get(), service_->GetAppBackgroundContents( + new MockBackgroundContents(&profile, "appid2")); + contents->SendOpenedNotification(&service); + EXPECT_EQ(contents, service.GetAppBackgroundContents(contents->appid())); + contents2->SendOpenedNotification(&service); + EXPECT_EQ(contents2.get(), service.GetAppBackgroundContents( contents2->appid())); - EXPECT_EQ(0U, GetPrefs(profile_)->size()); + EXPECT_EQ(0U, GetPrefs(&profile)->size()); // Navigate the contents, then make sure the one associated with the extension // is unregistered. GURL url("http://a/"); GURL url2("http://b/"); contents->Navigate(url); - EXPECT_EQ(1U, GetPrefs(profile_)->size()); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); contents2->Navigate(url2); - EXPECT_EQ(2U, GetPrefs(profile_)->size()); - service_->ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); - EXPECT_FALSE(service_->IsTracked(contents)); - EXPECT_EQ(NULL, service_->GetAppBackgroundContents(ASCIIToUTF16("appid"))); - EXPECT_EQ(1U, GetPrefs(profile_)->size()); - EXPECT_EQ(url2.spec(), GetPrefURLForApp(profile_, contents2->appid())); + EXPECT_EQ(2U, GetPrefs(&profile)->size()); + service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); + EXPECT_FALSE(service.IsTracked(contents)); + EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); + EXPECT_EQ(1U, GetPrefs(&profile)->size()); + EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); } diff --git a/chrome/browser/background/background_mode_manager_unittest.cc b/chrome/browser/background/background_mode_manager_unittest.cc index 7624532..2f222f1 100644 --- a/chrome/browser/background/background_mode_manager_unittest.cc +++ b/chrome/browser/background/background_mode_manager_unittest.cc @@ -6,47 +6,26 @@ #include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/background/background_mode_manager.h" -#include "chrome/browser/browser_shutdown.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile_manager.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_unittest_util.h" -#include "ui/message_center/message_center.h" class BackgroundModeManagerTest : public testing::Test { - protected: + public: BackgroundModeManagerTest() - : profile_manager_(TestingBrowserProcess::GetGlobal()) { + : profile_manager_(TestingBrowserProcess::GetGlobal()) {} + virtual ~BackgroundModeManagerTest() {} + virtual void SetUp() { command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); - CHECK(profile_manager_.SetUp()); -#if defined(OS_CHROMEOS) - // Because of the http://crbug.com/119175 workaround in the test - // constructor, browser shutdown needs to be reset otherwise - // subsequent test will fail. - browser_shutdown::SetTryingToQuit(false); -#endif // defined(OS_CHROMEOS) - } - - static void SetUpTestCase() { - message_center::MessageCenter::Initialize(); -#if defined(OS_CHROMEOS) - // Needed to handle http://crbug.com/119175. - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisableZeroBrowsersOpenForTests); -#endif // defined(OS_CHROMEOS) + ASSERT_TRUE(profile_manager_.SetUp()); } - static void TearDownTestCase() { - message_center::MessageCenter::Shutdown(); - } - scoped_ptr<CommandLine> command_line_; - content::TestBrowserThreadBundle thread_bundle_; TestingProfileManager profile_manager_; }; diff --git a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc index 532d89e..7e02b83 100644 --- a/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc +++ b/chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc @@ -7,8 +7,6 @@ #include "base/bind.h" #include "base/run_loop.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/storage_partition.h" -#include "content/public/common/url_constants.h" #include "content/public/test/test_browser_thread_bundle.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/parsed_cookie.h" @@ -23,32 +21,25 @@ class BrowsingDataCookieHelperTest : public testing::Test { : testing_profile_(new TestingProfile()) { } - net::CookieMonster* GetCookieMonster(const GURL& origin) { - using content::BrowserContext; - // Since it's a unittest, assume default StoragePartition. - return BrowserContext::GetDefaultStoragePartition(testing_profile_.get())-> - GetCookieStoreForScheme(origin.scheme())->GetCookieMonster(); - } - void CreateCookiesForTest() { - GURL origin1("http://www.google.com"); - GURL origin2("http://www.gmail.google.com"); - GetCookieMonster(origin1)->SetCookieWithOptionsAsync( - origin1, "A=1", net::CookieOptions(), + scoped_refptr<net::CookieMonster> cookie_monster = + testing_profile_->GetCookieMonster(); + cookie_monster->SetCookieWithOptionsAsync( + GURL("http://www.google.com"), "A=1", net::CookieOptions(), net::CookieMonster::SetCookiesCallback()); - GetCookieMonster(origin2)->SetCookieWithOptionsAsync( - origin2, "B=1", net::CookieOptions(), + cookie_monster->SetCookieWithOptionsAsync( + GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions(), net::CookieMonster::SetCookiesCallback()); } void CreateCookiesForDomainCookieTest() { - GURL origin("http://www.google.com"); - scoped_refptr<net::CookieMonster> cookie_monster = GetCookieMonster(origin); + scoped_refptr<net::CookieMonster> cookie_monster = + testing_profile_->GetCookieMonster(); cookie_monster->SetCookieWithOptionsAsync( - origin, "A=1", net::CookieOptions(), + GURL("http://www.google.com"), "A=1", net::CookieOptions(), net::CookieMonster::SetCookiesCallback()); cookie_monster->SetCookieWithOptionsAsync( - origin, "A=2; Domain=.www.google.com ", + GURL("http://www.google.com"), "A=2; Domain=.www.google.com ", net::CookieOptions(), net::CookieMonster::SetCookiesCallback()); } diff --git a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc index 7ec7e48..3de958d 100644 --- a/chrome/browser/browsing_data/browsing_data_remover_unittest.cc +++ b/chrome/browser/browsing_data/browsing_data_remover_unittest.cc @@ -31,15 +31,12 @@ #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/browser_context.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/common/url_constants.h" +#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread_bundle.h" -#include "content/public/test/test_utils.h" #include "net/cookies/cookie_monster.h" #include "net/ssl/server_bound_cert_service.h" #include "net/ssl/server_bound_cert_store.h" @@ -226,9 +223,8 @@ class RemoveCookieTester { class RemoveProfileCookieTester : public RemoveCookieTester { public: explicit RemoveProfileCookieTester(TestingProfile* profile) { - SetMonster( - content::BrowserContext::GetDefaultStoragePartition(profile)-> - GetCookieStoreForScheme(chrome::kHttpScheme)->GetCookieMonster()); + SetMonster(profile->GetRequestContext()->GetURLRequestContext()-> + cookie_store()->GetCookieMonster()); } }; @@ -245,9 +241,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 = - content::CreateCookieStore(content::CookieStoreConfig())-> - GetCookieMonster(); + net::CookieStore* monster = new net::CookieMonster(NULL, NULL); sb_service->url_request_context()->GetURLRequestContext()-> set_cookie_store(monster); SetMonster(monster); diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index cdefe7c..2d60399f 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -116,7 +116,6 @@ #include "content/public/browser/browser_url_handler.h" #include "content/public/browser/child_process_data.h" #include "content/public/browser/child_process_security_policy.h" -#include "content/public/browser/cookie_store_factory.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/resource_context.h" @@ -124,7 +123,6 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "content/public/common/child_process_host.h" -#include "content/public/common/content_constants.h" #include "content/public/common/content_descriptors.h" #include "extensions/browser/view_type_utils.h" #include "extensions/common/constants.h" @@ -135,7 +133,6 @@ #include "net/base/mime_util.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/cookie_options.h" -#include "net/cookies/cookie_store.h" #include "net/ssl/ssl_cert_request_info.h" #include "ppapi/host/ppapi_host.h" #include "ui/base/l10n/l10n_util.h" @@ -1653,6 +1650,18 @@ bool ChromeContentBrowserClient::AllowWorkerIndexedDB( return allow; } +net::URLRequestContext* +ChromeContentBrowserClient::OverrideRequestContextForURL( + const GURL& url, content::ResourceContext* context) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + if (url.SchemeIs(extensions::kExtensionScheme)) { + ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); + return io_data->extensions_request_context(); + } + + return NULL; +} + QuotaPermissionContext* ChromeContentBrowserClient::CreateQuotaPermissionContext() { return new ChromeQuotaPermissionContext(); diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index 9dea99d..fbe28f8 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -145,6 +145,8 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { const string16& name, content::ResourceContext* context, const std::vector<std::pair<int, int> >& render_views) OVERRIDE; + virtual net::URLRequestContext* OverrideRequestContextForURL( + const GURL& url, content::ResourceContext* context) OVERRIDE; virtual content::QuotaPermissionContext* CreateQuotaPermissionContext() OVERRIDE; virtual void AllowCertificateError( diff --git a/chrome/browser/diagnostics/sqlite_diagnostics.cc b/chrome/browser/diagnostics/sqlite_diagnostics.cc index 0560e65..dcb3491 100644 --- a/chrome/browser/diagnostics/sqlite_diagnostics.cc +++ b/chrome/browser/diagnostics/sqlite_diagnostics.cc @@ -219,7 +219,7 @@ DiagnosticsTest* MakeSqliteArchivedHistoryDbTest() { DiagnosticsTest* MakeSqliteCookiesDbTest() { return new SqliteIntegrityTest(SqliteIntegrityTest::CRITICAL, DIAGNOSTICS_SQLITE_INTEGRITY_COOKIE_TEST, - base::FilePath(content::kCookieFilename)); + base::FilePath(chrome::kCookieFilename)); } DiagnosticsTest* MakeSqliteWebDatabaseTrackerDbTest() { diff --git a/chrome/browser/download/download_request_limiter_unittest.cc b/chrome/browser/download/download_request_limiter_unittest.cc index 9ec96d2..06cd852 100644 --- a/chrome/browser/download/download_request_limiter_unittest.cc +++ b/chrome/browser/download/download_request_limiter_unittest.cc @@ -14,7 +14,6 @@ #include "chrome/test/base/testing_profile.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" using content::WebContents; @@ -38,8 +37,7 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { &DownloadRequestLimiterTest::FakeCreate, base::Unretained(this)); DownloadRequestInfoBarDelegate::SetCallbackForTesting( &fake_create_callback_); - content_settings_ = new HostContentSettingsMap( - Profile::FromBrowserContext(browser_context())->GetPrefs(), false); + content_settings_ = new HostContentSettingsMap(profile_.GetPrefs(), false); DownloadRequestLimiter::SetContentSettingsForTesting( content_settings_.get()); } @@ -141,9 +139,7 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { private: DownloadRequestInfoBarDelegate::FakeCreateCallback fake_create_callback_; - virtual content::BrowserContext* CreateBrowserContext() OVERRIDE { - return new TestingProfile(); - } + TestingProfile profile_; }; TEST_F(DownloadRequestLimiterTest, diff --git a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc index 08fc996..39d3908 100644 --- a/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc +++ b/chrome/browser/extensions/api/bluetooth/bluetooth_event_router_unittest.cc @@ -6,6 +6,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" #include "chrome/browser/extensions/event_names.h" @@ -14,7 +15,7 @@ #include "chrome/browser/extensions/test_extension_system.h" #include "chrome/common/extensions/api/bluetooth.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_device.h" #include "device/bluetooth/test/mock_bluetooth_profile.h" @@ -86,7 +87,8 @@ class ExtensionBluetoothEventRouterTest : public testing::Test { ExtensionBluetoothEventRouterTest() : mock_adapter_(new testing::StrictMock<device::MockBluetoothAdapter>()), test_profile_(new TestingProfile()), - router_(test_profile_.get()) { + router_(test_profile_.get()), + ui_thread_(content::BrowserThread::UI, &message_loop_) { router_.SetAdapterForTest(mock_adapter_); } @@ -94,17 +96,19 @@ class ExtensionBluetoothEventRouterTest : public testing::Test { // Some profile-dependent services rely on UI thread to clean up. We make // sure they are properly cleaned up by running the UI message loop until // idle. - test_profile_.reset(); - base::RunLoop().RunUntilIdle(); + test_profile_.reset(NULL); + base::RunLoop run_loop; + run_loop.RunUntilIdle(); } protected: - content::TestBrowserThreadBundle thread_bundle_; testing::StrictMock<device::MockBluetoothAdapter>* mock_adapter_; testing::NiceMock<device::MockBluetoothProfile> mock_audio_profile_; testing::NiceMock<device::MockBluetoothProfile> mock_health_profile_; scoped_ptr<TestingProfile> test_profile_; ExtensionBluetoothEventRouter router_; + base::MessageLoopForUI message_loop_; + content::TestBrowserThread ui_thread_; }; TEST_F(ExtensionBluetoothEventRouterTest, BluetoothEventListener) { diff --git a/chrome/browser/extensions/api/cookies/cookies_unittest.cc b/chrome/browser/extensions/api/cookies/cookies_unittest.cc index 6de2b19..b5fda79 100644 --- a/chrome/browser/extensions/api/cookies/cookies_unittest.cc +++ b/chrome/browser/extensions/api/cookies/cookies_unittest.cc @@ -12,7 +12,6 @@ #include "chrome/browser/extensions/api/cookies/cookies_helpers.h" #include "chrome/common/extensions/api/cookies.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "net/cookies/canonical_cookie.h" #include "net/cookies/cookie_constants.h" #include "url/gurl.h" @@ -40,7 +39,6 @@ class ExtensionCookiesTest : public testing::Test { }; TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) { - content::TestBrowserThreadBundle thread_bundle; TestingProfile::Builder profile_builder; TestingProfile::Builder otr_profile_builder; otr_profile_builder.SetIncognito(); @@ -112,7 +110,6 @@ TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) { ASSERT_TRUE(cookie2->expiration_date.get()); EXPECT_EQ(10000, *cookie2->expiration_date); - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; base::ListValue* tab_ids_list = new base::ListValue(); std::vector<int> tab_ids; diff --git a/chrome/browser/extensions/api/storage/settings_frontend_unittest.cc b/chrome/browser/extensions/api/storage/settings_frontend_unittest.cc index 249d54e..9eb8e45 100644 --- a/chrome/browser/extensions/api/storage/settings_frontend_unittest.cc +++ b/chrome/browser/extensions/api/storage/settings_frontend_unittest.cc @@ -7,7 +7,6 @@ #include "base/files/scoped_temp_dir.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" -#include "base/run_loop.h" #include "base/strings/stringprintf.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/api/storage/leveldb_settings_storage_factory.h" @@ -15,8 +14,7 @@ #include "chrome/browser/extensions/api/storage/settings_namespace.h" #include "chrome/browser/extensions/api/storage/settings_test_util.h" #include "chrome/browser/value_store/value_store.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" using content::BrowserThread; @@ -54,7 +52,9 @@ scoped_ptr<Value> CreateMegabyte() { class ExtensionSettingsFrontendTest : public testing::Test { public: ExtensionSettingsFrontendTest() - : storage_factory_(new util::ScopedSettingsStorageFactory()) {} + : storage_factory_(new util::ScopedSettingsStorageFactory()), + ui_thread_(BrowserThread::UI, base::MessageLoop::current()), + file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} virtual void SetUp() OVERRIDE { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); @@ -66,7 +66,7 @@ class ExtensionSettingsFrontendTest : public testing::Test { frontend_.reset(); profile_.reset(); // Execute any pending deletion tasks. - base::RunLoop().RunUntilIdle(); + message_loop_.RunUntilIdle(); } protected: @@ -76,11 +76,15 @@ class ExtensionSettingsFrontendTest : public testing::Test { SettingsFrontend::Create(storage_factory_.get(), profile_.get())); } - content::TestBrowserThreadBundle thread_bundle_; base::ScopedTempDir temp_dir_; scoped_ptr<util::MockProfile> profile_; scoped_ptr<SettingsFrontend> frontend_; scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_; + + private: + base::MessageLoop message_loop_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_thread_; }; // Get a semblance of coverage for both extension and app settings by @@ -137,7 +141,7 @@ TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { // This would be triggered by extension uninstall via a DataDeleter. frontend_->DeleteStorageSoon(id); - base::RunLoop().RunUntilIdle(); + base::MessageLoop::current()->RunUntilIdle(); // The storage area may no longer be valid post-uninstall, so re-request. storage = util::GetStorage(id, frontend_.get()); @@ -173,7 +177,7 @@ TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { } frontend_.reset(); - base::RunLoop().RunUntilIdle(); + base::MessageLoop::current()->RunUntilIdle(); // TODO(kalman): Figure out why this fails, despite appearing to work. // Leaving this commented out rather than disabling the whole test so that the // deletion code paths are at least exercised. @@ -278,7 +282,7 @@ TEST_F(ExtensionSettingsFrontendTest, frontend_->RunWithStorage( id, settings::LOCAL, base::Bind(&UnlimitedLocalStorageTestCallback)); - base::RunLoop().RunUntilIdle(); + base::MessageLoop::current()->RunUntilIdle(); } } // namespace extensions diff --git a/chrome/browser/extensions/api/storage/settings_sync_unittest.cc b/chrome/browser/extensions/api/storage/settings_sync_unittest.cc index 55870e4..0480062 100644 --- a/chrome/browser/extensions/api/storage/settings_sync_unittest.cc +++ b/chrome/browser/extensions/api/storage/settings_sync_unittest.cc @@ -7,7 +7,7 @@ #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/memory/scoped_ptr.h" -#include "base/run_loop.h" +#include "base/message_loop/message_loop.h" #include "chrome/browser/extensions/api/storage/leveldb_settings_storage_factory.h" #include "chrome/browser/extensions/api/storage/settings_frontend.h" #include "chrome/browser/extensions/api/storage/settings_storage_factory.h" @@ -17,7 +17,7 @@ #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/test_extension_service.h" #include "chrome/browser/value_store/testing_value_store.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "extensions/common/manifest.h" #include "sync/api/sync_change_processor.h" #include "sync/api/sync_error_factory.h" @@ -27,6 +27,7 @@ using base::DictionaryValue; using base::ListValue; using base::Value; +using content::BrowserThread; namespace extensions { @@ -204,7 +205,9 @@ class TestingValueStoreFactory : public SettingsStorageFactory { class ExtensionSettingsSyncTest : public testing::Test { public: ExtensionSettingsSyncTest() - : storage_factory_(new util::ScopedSettingsStorageFactory()), + : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), + file_thread_(BrowserThread::FILE, base::MessageLoop::current()), + storage_factory_(new util::ScopedSettingsStorageFactory()), sync_processor_(new MockSyncChangeProcessor), sync_processor_delegate_(new SyncChangeProcessorDelegate( sync_processor_.get())) {} @@ -221,7 +224,7 @@ class ExtensionSettingsSyncTest : public testing::Test { frontend_.reset(); profile_.reset(); // Execute any pending deletion tasks. - base::RunLoop().RunUntilIdle(); + message_loop_.RunUntilIdle(); } protected: @@ -258,7 +261,9 @@ class ExtensionSettingsSyncTest : public testing::Test { } // Need these so that the DCHECKs for running on FILE or UI threads pass. - content::TestBrowserThreadBundle thread_bundle_; + base::MessageLoop message_loop_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_thread_; base::ScopedTempDir temp_dir_; scoped_ptr<util::MockProfile> profile_; diff --git a/chrome/browser/extensions/data_deleter.cc b/chrome/browser/extensions/data_deleter.cc index c271321..8d53a42 100644 --- a/chrome/browser/extensions/data_deleter.cc +++ b/chrome/browser/extensions/data_deleter.cc @@ -29,11 +29,35 @@ void DataDeleter::StartDeleting(Profile* profile, const GURL& site = Extension::GetBaseURLFromExtensionId(extension_id); - BrowserContext::GetStoragePartitionForSite(profile, site)-> - ClearDataForOrigin((StoragePartition::REMOVE_DATA_MASK_ALL & - ~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), - StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, - storage_origin); + StoragePartition* partition = + BrowserContext::GetStoragePartitionForSite(profile, site); + + if (storage_origin.SchemeIs(extensions::kExtensionScheme)) { + // TODO(ajwong): Cookies are not properly isolated for + // chrome-extension:// scheme. (http://crbug.com/158386). + // + // However, no isolated apps actually can write to kExtensionScheme + // origins. Thus, it is benign to delete from the + // RequestContextForExtensions because there's nothing stored there. We + // preserve this code path without checking for isolation because it's + // simpler than special casing. This code should go away once we merge + // the various URLRequestContexts (http://crbug.com/159193). + partition->ClearDataForOrigin( + StoragePartition::REMOVE_DATA_MASK_ALL & + (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), + StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, + storage_origin, + profile->GetRequestContextForExtensions()); + } else { + // We don't need to worry about the media request context because that + // shares the same cookie store as the main request context. + partition->ClearDataForOrigin( + StoragePartition::REMOVE_DATA_MASK_ALL & + (~StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE), + StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, + storage_origin, + partition->GetURLRequestContext()); + } // Begin removal of the settings for the current extension. profile->GetExtensionService()->settings_frontend()-> diff --git a/chrome/browser/extensions/error_console/error_console_unittest.cc b/chrome/browser/extensions/error_console/error_console_unittest.cc index 792ff14..62b5320 100644 --- a/chrome/browser/extensions/error_console/error_console_unittest.cc +++ b/chrome/browser/extensions/error_console/error_console_unittest.cc @@ -12,7 +12,6 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/test/base/testing_profile.h" #include "content/public/common/url_constants.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "extensions/browser/extension_error.h" #include "extensions/common/constants.h" #include "testing/gtest/include/gtest/gtest.h" @@ -56,14 +55,14 @@ scoped_ptr<const ExtensionError> CreateNewRuntimeError( class ErrorConsoleUnitTest : public testing::Test { public: - ErrorConsoleUnitTest() - : error_console_(ErrorConsole::Get(&profile_)) { + ErrorConsoleUnitTest() : + profile_(new TestingProfile), + error_console_(ErrorConsole::Get(profile_.get())) { } virtual ~ErrorConsoleUnitTest() { } protected: - content::TestBrowserThreadBundle thread_bundle_; - TestingProfile profile_; + scoped_ptr<TestingProfile> profile_; ErrorConsole* error_console_; }; diff --git a/chrome/browser/extensions/extension_process_manager_unittest.cc b/chrome/browser/extensions/extension_process_manager_unittest.cc index 8077894..bdd8d96 100644 --- a/chrome/browser/extensions/extension_process_manager_unittest.cc +++ b/chrome/browser/extensions/extension_process_manager_unittest.cc @@ -7,7 +7,6 @@ #include "chrome/test/base/testing_profile.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/site_instance.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -35,7 +34,6 @@ TEST_F(ExtensionProcessManagerTest, ProcessGrouping) { // Extensions in different profiles should always be different SiteInstances. // Note: we don't initialize these, since we're not testing that // functionality. This means we can get away with a NULL UserScriptMaster. - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile1; scoped_ptr<ExtensionProcessManager> manager1( ExtensionProcessManager::Create(&profile1)); diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 7939bdb..4ccc3c1 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -22,7 +22,6 @@ #include "base/memory/weak_ptr.h" #include "base/message_loop/message_loop.h" #include "base/path_service.h" -#include "base/run_loop.h" #include "base/stl_util.h" #include "base/strings/string16.h" #include "base/strings/string_number_conversions.h" @@ -4110,8 +4109,8 @@ TEST_F(ExtensionServiceTest, ClearExtensionData) { // Set a cookie for the extension. net::CookieMonster* cookie_monster = - BrowserContext::GetDefaultStoragePartition(profile_.get())-> - GetCookieStoreForScheme(ext_url.scheme())->GetCookieMonster(); + profile_->GetRequestContextForExtensions()->GetURLRequestContext()-> + cookie_store()->GetCookieMonster(); ASSERT_TRUE(cookie_monster); net::CookieOptions options; cookie_monster->SetCookieWithOptionsAsync( @@ -4226,8 +4225,8 @@ TEST_F(ExtensionServiceTest, ClearAppData) { // Set a cookie for the extension. net::CookieMonster* cookie_monster = - BrowserContext::GetDefaultStoragePartition(profile_.get())-> - GetCookieStoreForScheme(origin1.scheme())->GetCookieMonster(); + profile_->GetRequestContext()->GetURLRequestContext()-> + cookie_store()->GetCookieMonster(); ASSERT_TRUE(cookie_monster); net::CookieOptions options; cookie_monster->SetCookieWithOptionsAsync( @@ -4923,8 +4922,8 @@ TEST(ExtensionServiceTestSimple, Enabledness) { ExtensionErrorReporter::Init(false); // no noisy errors ExtensionsReadyRecorder recorder; - content::TestBrowserThreadBundle thread_bundle; scoped_ptr<TestingProfile> profile(new TestingProfile()); + content::TestBrowserThreadBundle thread_bundle_; #if defined OS_CHROMEOS chromeos::ScopedTestDeviceSettingsService device_settings_service; chromeos::ScopedTestCrosSettings cros_settings; diff --git a/chrome/browser/extensions/extension_warning_badge_service_unittest.cc b/chrome/browser/extensions/extension_warning_badge_service_unittest.cc index 16b751d..273c016 100644 --- a/chrome/browser/extensions/extension_warning_badge_service_unittest.cc +++ b/chrome/browser/extensions/extension_warning_badge_service_unittest.cc @@ -10,7 +10,6 @@ #include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" namespace extensions { @@ -67,7 +66,6 @@ const ExtensionWarning::WarningType warning_2 = // Check that no badge appears if it has been suppressed for a specific // warning. TEST(ExtensionWarningBadgeServiceTest, SuppressBadgeForCurrentWarnings) { - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; TestExtensionWarningSet warnings(&profile); TestExtensionWarningBadgeService badge_service(&profile, &warnings); diff --git a/chrome/browser/extensions/extension_warning_service_unittest.cc b/chrome/browser/extensions/extension_warning_service_unittest.cc index a612d6e..7ad5b82 100644 --- a/chrome/browser/extensions/extension_warning_service_unittest.cc +++ b/chrome/browser/extensions/extension_warning_service_unittest.cc @@ -8,7 +8,6 @@ #include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -48,7 +47,6 @@ const ExtensionWarning::WarningType warning_2 = // Check that inserting a warning triggers notifications, whereas inserting // the same warning again is silent. TEST(ExtensionWarningServiceTest, SetWarning) { - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; TestExtensionWarningService warning_service(&profile); MockObserver observer; @@ -71,7 +69,6 @@ TEST(ExtensionWarningServiceTest, SetWarning) { // Check that ClearWarnings deletes exactly the specified warnings and // triggers notifications where appropriate. TEST(ExtensionWarningServiceTest, ClearWarnings) { - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; TestExtensionWarningService warning_service(&profile); MockObserver observer; diff --git a/chrome/browser/extensions/menu_manager_unittest.cc b/chrome/browser/extensions/menu_manager_unittest.cc index 84bbcec..5fef312 100644 --- a/chrome/browser/extensions/menu_manager_unittest.cc +++ b/chrome/browser/extensions/menu_manager_unittest.cc @@ -10,7 +10,6 @@ #include "base/message_loop/message_loop.h" #include "base/path_service.h" #include "base/prefs/pref_service.h" -#include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/chrome_notification_types.h" @@ -28,10 +27,11 @@ #include "chrome/test/base/testing_profile.h" #include "content/public/browser/notification_service.h" #include "content/public/common/context_menu_params.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +using content::BrowserThread; using testing::_; using testing::AtLeast; using testing::DeleteArg; @@ -47,13 +47,15 @@ namespace context_menus = api::context_menus; class MenuManagerTest : public testing::Test { public: MenuManagerTest() - : manager_(&profile_), - prefs_(base::MessageLoopForUI::current()->message_loop_proxy().get()), + : ui_thread_(BrowserThread::UI, &message_loop_), + file_thread_(BrowserThread::FILE, &message_loop_), + manager_(&profile_), + prefs_(message_loop_.message_loop_proxy().get()), next_id_(1) {} virtual void TearDown() OVERRIDE { prefs_.pref_service()->CommitPendingWrite(); - base::RunLoop().RunUntilIdle(); + message_loop_.RunUntilIdle(); } // Returns a test item. @@ -84,7 +86,9 @@ class MenuManagerTest : public testing::Test { } protected: - content::TestBrowserThreadBundle thread_bundle_; + base::MessageLoopForUI message_loop_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_thread_; TestingProfile profile_; MenuManager manager_; diff --git a/chrome/browser/history/shortcuts_backend_unittest.cc b/chrome/browser/history/shortcuts_backend_unittest.cc index 0a413aa..985c8c4 100644 --- a/chrome/browser/history/shortcuts_backend_unittest.cc +++ b/chrome/browser/history/shortcuts_backend_unittest.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "base/files/scoped_temp_dir.h" +#include "base/message_loop/message_loop.h" #include "base/path_service.h" -#include "base/run_loop.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" @@ -12,7 +12,7 @@ #include "chrome/browser/history/shortcuts_backend_factory.h" #include "chrome/browser/history/shortcuts_database.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "sql/statement.h" #include "testing/gtest/include/gtest/gtest.h" @@ -27,7 +27,9 @@ class ShortcutsBackendTest : public testing::Test, public ShortcutsBackend::ShortcutsBackendObserver { public: ShortcutsBackendTest() - : load_notified_(false), + : ui_thread_(BrowserThread::UI, &ui_message_loop_), + db_thread_(BrowserThread::DB), + load_notified_(false), changed_notified_(false) {} virtual void SetUp(); @@ -38,16 +40,18 @@ class ShortcutsBackendTest : public testing::Test, void InitBackend(); - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; scoped_refptr<ShortcutsBackend> backend_; + base::MessageLoopForUI ui_message_loop_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread db_thread_; bool load_notified_; bool changed_notified_; - base::RunLoop on_loaded_loop_; }; void ShortcutsBackendTest::SetUp() { + db_thread_.Start(); ShortcutsBackendFactory::GetInstance()->SetTestingFactoryAndUse( &profile_, &ShortcutsBackendFactory::BuildProfileForTesting); backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); @@ -57,11 +61,12 @@ void ShortcutsBackendTest::SetUp() { void ShortcutsBackendTest::TearDown() { backend_->RemoveObserver(this); + db_thread_.Stop(); } void ShortcutsBackendTest::OnShortcutsLoaded() { load_notified_ = true; - on_loaded_loop_.Quit(); + base::MessageLoop::current()->Quit(); } void ShortcutsBackendTest::OnShortcutsChanged() { @@ -74,7 +79,7 @@ void ShortcutsBackendTest::InitBackend() { ASSERT_TRUE(backend); ASSERT_FALSE(load_notified_); ASSERT_FALSE(backend_->initialized()); - on_loaded_loop_.Run(); + base::MessageLoop::current()->Run(); EXPECT_TRUE(load_notified_); EXPECT_TRUE(backend_->initialized()); } diff --git a/chrome/browser/history/shortcuts_database_unittest.cc b/chrome/browser/history/shortcuts_database_unittest.cc index 72b5c17..dd3a322 100644 --- a/chrome/browser/history/shortcuts_database_unittest.cc +++ b/chrome/browser/history/shortcuts_database_unittest.cc @@ -9,7 +9,6 @@ #include "base/time/time.h" #include "chrome/browser/history/shortcuts_database.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "sql/statement.h" #include "testing/gtest/include/gtest/gtest.h" @@ -53,13 +52,11 @@ class ShortcutsDatabaseTest : public testing::Test { void AddAll(); - scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; scoped_ptr<TestingProfile> profile_; scoped_refptr<ShortcutsDatabase> db_; }; void ShortcutsDatabaseTest::SetUp() { - thread_bundle_.reset(new content::TestBrowserThreadBundle()); profile_.reset(new TestingProfile()); db_ = new ShortcutsDatabase(profile_.get()); ASSERT_TRUE(db_->Init()); diff --git a/chrome/browser/history/thumbnail_database_unittest.cc b/chrome/browser/history/thumbnail_database_unittest.cc index ea911bd..75758e7 100644 --- a/chrome/browser/history/thumbnail_database_unittest.cc +++ b/chrome/browser/history/thumbnail_database_unittest.cc @@ -19,7 +19,6 @@ #include "chrome/common/thumbnail_score.h" #include "chrome/test/base/testing_profile.h" #include "chrome/tools/profiles/thumbnail-inl.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/codec/jpeg_codec.h" @@ -79,18 +78,26 @@ class ThumbnailDatabaseTest : public testing::Test { }; class IconMappingMigrationTest : public HistoryUnitTestBase { + public: + IconMappingMigrationTest() { + } + virtual ~IconMappingMigrationTest() { + } + protected: virtual void SetUp() { + profile_.reset(new TestingProfile); + base::FilePath data_path; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); data_path = data_path.AppendASCII("History"); - history_db_name_ = profile_.GetPath().Append(chrome::kHistoryFilename); + history_db_name_ = profile_->GetPath().Append(chrome::kHistoryFilename); ASSERT_NO_FATAL_FAILURE( ExecuteSQLScript(data_path.AppendASCII("history.20.sql"), history_db_name_)); thumbnail_db_name_ = - profile_.GetPath().Append(chrome::kFaviconsFilename); + profile_->GetPath().Append(chrome::kFaviconsFilename); ASSERT_NO_FATAL_FAILURE( ExecuteSQLScript(data_path.AppendASCII("thumbnails.3.sql"), thumbnail_db_name_)); @@ -101,8 +108,7 @@ class IconMappingMigrationTest : public HistoryUnitTestBase { base::FilePath thumbnail_db_name_; private: - content::TestBrowserThreadBundle thread_bundle_; - TestingProfile profile_; + scoped_ptr<TestingProfile> profile_; }; TEST_F(ThumbnailDatabaseTest, AddIconMapping) { diff --git a/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc b/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc index d22b3d3..314e8a7 100644 --- a/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc +++ b/chrome/browser/invalidation/ticl_invalidation_service_unittest.cc @@ -7,7 +7,6 @@ #include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/invalidation/invalidation_service_test_template.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "sync/notifier/fake_invalidation_handler.h" #include "sync/notifier/fake_invalidator.h" #include "sync/notifier/invalidation_util.h" @@ -24,7 +23,6 @@ class TiclInvalidationServiceTestDelegate { } void CreateInvalidationService() { - thread_bundle_.reset(new content::TestBrowserThreadBundle()); fake_invalidator_ = new syncer::FakeInvalidator(); profile_.reset(new TestingProfile()); invalidation_service_.reset( @@ -50,7 +48,6 @@ class TiclInvalidationServiceTestDelegate { } syncer::FakeInvalidator* fake_invalidator_; // owned by the service. - scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; scoped_ptr<TiclInvalidationService> invalidation_service_; scoped_ptr<TestingProfile> profile_; }; diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index bb5fbd5..d2745b3 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -45,12 +45,12 @@ #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 "net/base/host_mapping_rules.h" #include "net/base/net_util.h" #include "net/base/network_time_notifier.h" #include "net/base/sdch_manager.h" #include "net/cert/cert_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" @@ -534,8 +534,7 @@ void IOThread::InitAsync() { globals_->proxy_script_fetcher_proxy_service.reset( net::ProxyService::CreateDirectWithNetLog(net_log_)); // In-memory cookie store. - globals_->system_cookie_store = - content::CreateCookieStore(content::CookieStoreConfig()); + globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); // In-memory server bound cert store. globals_->system_server_bound_cert_service.reset( new net::ServerBoundCertService( @@ -678,6 +677,12 @@ 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/managed_mode/managed_user_sync_service_unittest.cc b/chrome/browser/managed_mode/managed_user_sync_service_unittest.cc index 496ceb8..7ed7765 100644 --- a/chrome/browser/managed_mode/managed_user_sync_service_unittest.cc +++ b/chrome/browser/managed_mode/managed_user_sync_service_unittest.cc @@ -13,7 +13,6 @@ #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "sync/api/sync_change.h" #include "sync/api/sync_error_factory_mock.h" #include "sync/protocol/sync.pb.h" @@ -87,7 +86,6 @@ class ManagedUserSyncServiceTest : public ::testing::Test { MockChangeProcessor* change_processor() { return change_processor_; } private: - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; ManagedUserSyncService* service_; diff --git a/chrome/browser/net/chrome_cookie_notification_details.h b/chrome/browser/net/chrome_cookie_notification_details.h index b4a7c8f..d54f280 100644 --- a/chrome/browser/net/chrome_cookie_notification_details.h +++ b/chrome/browser/net/chrome_cookie_notification_details.h @@ -23,7 +23,7 @@ struct ChromeCookieDetails { const net::CanonicalCookie* cookie; bool removed; - net::CookieMonsterDelegate::ChangeCause cause; + net::CookieMonster::Delegate::ChangeCause cause; }; #endif // CHROME_BROWSER_NET_CHROME_COOKIE_NOTIFICATION_DETAILS_H_ diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 460353a..f335040 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -57,6 +57,20 @@ class FactoryForMain : public ChromeURLRequestContextFactory { content::ProtocolHandlerMap protocol_handlers_; }; +// Factory that creates the ChromeURLRequestContext for extensions. +class FactoryForExtensions : public ChromeURLRequestContextFactory { + public: + explicit FactoryForExtensions(const ProfileIOData* profile_io_data) + : profile_io_data_(profile_io_data) {} + + virtual ChromeURLRequestContext* Create() OVERRIDE { + return profile_io_data_->GetExtensionsRequestContext(); + } + + private: + const ProfileIOData* const profile_io_data_; +}; + // Factory that creates the ChromeURLRequestContext for a given isolated app. class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { public: @@ -199,6 +213,15 @@ ChromeURLRequestContextGetter::CreateOriginalForMedia( // static ChromeURLRequestContextGetter* +ChromeURLRequestContextGetter::CreateOriginalForExtensions( + Profile* profile, const ProfileIOData* profile_io_data) { + DCHECK(!profile->IsOffTheRecord()); + return new ChromeURLRequestContextGetter( + new FactoryForExtensions(profile_io_data)); +} + +// static +ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( Profile* profile, const ProfileIOData* profile_io_data, @@ -242,6 +265,15 @@ ChromeURLRequestContextGetter::CreateOffTheRecord( // static ChromeURLRequestContextGetter* +ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( + Profile* profile, const ProfileIOData* profile_io_data) { + DCHECK(profile->IsOffTheRecord()); + return new ChromeURLRequestContextGetter( + new FactoryForExtensions(profile_io_data)); +} + +// static +ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( Profile* profile, const ProfileIOData* profile_io_data, diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 30215e5..db09992 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -100,6 +100,11 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter { static ChromeURLRequestContextGetter* CreateOriginalForMedia( Profile* profile, const ProfileIOData* profile_io_data); + // Create an instance for an original profile for extensions. This is expected + // to get called on UI thread. + static ChromeURLRequestContextGetter* CreateOriginalForExtensions( + Profile* profile, const ProfileIOData* profile_io_data); + // Create an instance for an original profile for an app with isolated // storage. This is expected to get called on UI thread. static ChromeURLRequestContextGetter* CreateOriginalForIsolatedApp( @@ -125,6 +130,11 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter { const ProfileIOData* profile_io_data, content::ProtocolHandlerMap* protocol_handlers); + // Create an instance for an OTR profile for extensions. This is expected + // to get called on UI thread. + static ChromeURLRequestContextGetter* CreateOffTheRecordForExtensions( + Profile* profile, const ProfileIOData* profile_io_data); + // Create an instance for an OTR profile for an app with isolated storage. // This is expected to get called on UI thread. static ChromeURLRequestContextGetter* CreateOffTheRecordForIsolatedApp( diff --git a/chrome/browser/net/cookie_store_util.cc b/chrome/browser/net/cookie_store_util.cc deleted file mode 100644 index 7999261..0000000 --- a/chrome/browser/net/cookie_store_util.cc +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/net/cookie_store_util.h" - -#include "base/bind.h" -#include "base/callback.h" -#include "base/command_line.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/net/chrome_cookie_notification_details.h" -#include "chrome/browser/net/evicted_domain_cookie_counter.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_switches.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/common/content_constants.h" -#include "extensions/common/constants.h" - -using content::BrowserThread; - -namespace { - -class ChromeCookieMonsterDelegate : public net::CookieMonsterDelegate { - public: - explicit ChromeCookieMonsterDelegate(Profile* profile) - : profile_getter_( - base::Bind(&GetProfileOnUI, g_browser_process->profile_manager(), - profile)) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(profile); - } - - // net::CookieMonster::Delegate implementation. - virtual void OnCookieChanged( - const net::CanonicalCookie& cookie, - bool removed, - net::CookieMonster::Delegate::ChangeCause cause) OVERRIDE { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper, - this, cookie, removed, cause)); - } - - private: - virtual ~ChromeCookieMonsterDelegate() {} - - static Profile* GetProfileOnUI(ProfileManager* profile_manager, - Profile* profile) { - if (profile_manager->IsValidProfile(profile)) - return profile; - return NULL; - } - - void OnCookieChangedAsyncHelper( - const net::CanonicalCookie& cookie, - bool removed, - net::CookieMonster::Delegate::ChangeCause cause) { - Profile* profile = profile_getter_.Run(); - if (profile) { - ChromeCookieDetails cookie_details(&cookie, removed, cause); - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_COOKIE_CHANGED, - content::Source<Profile>(profile), - content::Details<ChromeCookieDetails>(&cookie_details)); - } - } - - const base::Callback<Profile*(void)> profile_getter_; -}; - -} // namespace - -namespace chrome_browser_net { - -bool IsCookieRecordMode() { - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - // Only allow Record Mode if we are in a Debug build or where we are running - // a cycle, and the user has limited control. - return command_line.HasSwitch(switches::kRecordMode) && - (chrome::kRecordModeEnabled || - command_line.HasSwitch(switches::kVisitURLs)); -} - -bool ShouldUseInMemoryCookiesAndCache() { - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - return IsCookieRecordMode() || - command_line.HasSwitch(switches::kPlaybackMode); -} - -net::CookieMonsterDelegate* CreateCookieDelegate(Profile* profile) { - return new EvictedDomainCookieCounter( - new ChromeCookieMonsterDelegate(profile)); -} - -void SetCookieStoreConfigs( - const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - content::CookieStoreConfig::SessionCookieMode session_cookie_mode, - quota::SpecialStoragePolicy* storage_policy, - net::CookieMonsterDelegate* cookie_delegate, - content::BrowserContext::CookieSchemeMap* configs) { - using content::CookieStoreConfig; - configs->clear(); - - bool in_memory = in_memory_partition || - chrome_browser_net::ShouldUseInMemoryCookiesAndCache(); - - if (in_memory) { - (*configs)[content::BrowserContext::kDefaultCookieScheme] = - CookieStoreConfig(base::FilePath(), - CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - storage_policy, - cookie_delegate); - } else { - (*configs)[content::BrowserContext::kDefaultCookieScheme] = - CookieStoreConfig(partition_path.Append(content::kCookieFilename), - session_cookie_mode, - storage_policy, - cookie_delegate); - } - - // Handle adding the extensions cookie store. - if (is_default_partition) { - if (in_memory) { - (*configs)[extensions::kExtensionScheme] = CookieStoreConfig(); - } else { - base::FilePath cookie_path = partition_path.Append( - chrome::kExtensionsCookieFilename); - (*configs)[extensions::kExtensionScheme] = - CookieStoreConfig(cookie_path, session_cookie_mode, NULL, NULL); - } - } -} - -} // namespace chrome_browser_net diff --git a/chrome/browser/net/cookie_store_util.h b/chrome/browser/net/cookie_store_util.h deleted file mode 100644 index 0e8cd28..0000000 --- a/chrome/browser/net/cookie_store_util.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NET_COOKIE_STORE_UTIL_H_ -#define CHROME_BROWSER_NET_COOKIE_STORE_UTIL_H_ - -#include "content/public/browser/browser_context.h" -#include "content/public/browser/cookie_store_factory.h" - -class Profile; - -namespace net { -class CookieMonsterDelegate; -} // namespace net - -namespace chrome_browser_net { - -// Returns true if cookie-like storage systems should enter record mode for -// debugging. -bool IsCookieRecordMode(); - -// Returns true if command line flags indicate that cookie-like storage systems -// should be forced to be in memory only. -bool ShouldUseInMemoryCookiesAndCache(); - -// Populates |configs| with a correctly configured set of CookieStores to -// handle http, https, chrome-extension and (depending on flags) file schemes. -void SetCookieStoreConfigs( - const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - content::CookieStoreConfig::SessionCookieMode session_cookie_mode, - quota::SpecialStoragePolicy* storage_policy, - net::CookieMonsterDelegate* cookie_delegate, - content::BrowserContext::CookieSchemeMap* configs); - -// Factory method for creating a CookieStore delegate that sends -// chrome::NOTIFICATION_COOKIE_CHANGED for the given profile. This -// delegate is stateless so only one is necessary per profile. -net::CookieMonsterDelegate* CreateCookieDelegate(Profile* profile); - -} // namespace chrome_browser_net - -#endif // CHROME_BROWSER_NET_COOKIE_STORE_UTIL_H_ diff --git a/chrome/browser/password_manager/password_form_manager_unittest.cc b/chrome/browser/password_manager/password_form_manager_unittest.cc index 067276b..33339e1 100644 --- a/chrome/browser/password_manager/password_form_manager_unittest.cc +++ b/chrome/browser/password_manager/password_form_manager_unittest.cc @@ -5,6 +5,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/password_manager/password_form_manager.h" @@ -16,7 +17,6 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/test/base/testing_profile.h" #include "content/public/common/password_form.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_utils.h" #include "testing/gmock/include/gmock/gmock.h" @@ -78,6 +78,8 @@ class TestPasswordFormManager : public PasswordFormManager { class PasswordFormManagerTest : public testing::Test { public: + PasswordFormManagerTest() { + } virtual void SetUp() { observed_form_.origin = GURL("http://accounts.google.com/a/LoginAuth"); observed_form_.action = GURL("http://accounts.google.com/a/Login"); @@ -94,6 +96,11 @@ class PasswordFormManagerTest : public testing::Test { saved_match_.password_value = ASCIIToUTF16("test1"); saved_match_.other_possible_usernames.push_back( ASCIIToUTF16("test2@gmail.com")); + profile_ = new TestingProfile(); + } + + virtual void TearDown() { + delete profile_; } PasswordForm* GetPendingCredentials(PasswordFormManager* p) { @@ -134,7 +141,7 @@ class PasswordFormManagerTest : public testing::Test { return p->IgnoreResult(*form); } - Profile* profile() { return &profile_; } + Profile* profile() { return profile_; } PasswordForm* observed_form() { return &observed_form_; } PasswordForm* saved_match() { return &saved_match_; } @@ -146,10 +153,9 @@ class PasswordFormManagerTest : public testing::Test { } private: - content::TestBrowserThreadBundle thread_bundle_; - TestingProfile profile_; PasswordForm observed_form_; PasswordForm saved_match_; + Profile* profile_; }; TEST_F(PasswordFormManagerTest, TestNewLogin) { @@ -331,6 +337,8 @@ TEST_F(PasswordFormManagerTest, TestDynamicAction) { } TEST_F(PasswordFormManagerTest, TestAlternateUsername) { + // Need a MessageLoop for callbacks. + base::MessageLoop message_loop; PasswordStoreFactory::GetInstance()->SetTestingFactory( profile(), &TestPasswordStore::Create); scoped_refptr<TestPasswordStore> password_store = diff --git a/chrome/browser/predictors/autocomplete_action_predictor_table_unittest.cc b/chrome/browser/predictors/autocomplete_action_predictor_table_unittest.cc index dc64735..9dd1b01 100644 --- a/chrome/browser/predictors/autocomplete_action_predictor_table_unittest.cc +++ b/chrome/browser/predictors/autocomplete_action_predictor_table_unittest.cc @@ -4,15 +4,14 @@ #include <vector> -#include "base/run_loop.h" +#include "base/message_loop/message_loop.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" #include "chrome/browser/predictors/predictor_database.h" #include "chrome/browser/predictors/predictor_database_factory.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "sql/statement.h" #include "testing/gtest/include/gtest/gtest.h" @@ -25,7 +24,10 @@ using predictors::AutocompleteActionPredictorTable; namespace predictors { class AutocompleteActionPredictorTableTest : public testing::Test { - protected: + public: + AutocompleteActionPredictorTableTest(); + virtual ~AutocompleteActionPredictorTableTest(); + virtual void SetUp(); virtual void TearDown(); @@ -38,6 +40,8 @@ class AutocompleteActionPredictorTableTest : public testing::Test { TestingProfile* profile() { return &profile_; } + protected: + // Test functions that can be run against this text fixture or // AutocompleteActionPredictorTableReopenTest that inherits from this. void TestGetRow(); @@ -48,14 +52,15 @@ class AutocompleteActionPredictorTableTest : public testing::Test { AutocompleteActionPredictorTable::Rows test_db_; private: - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; scoped_ptr<PredictorDatabase> db_; + base::MessageLoop loop_; + content::TestBrowserThread db_thread_; }; class AutocompleteActionPredictorTableReopenTest : public AutocompleteActionPredictorTableTest { - protected: + public: virtual void SetUp() { // By calling SetUp twice, we make sure that the table already exists for // this fixture. @@ -65,9 +70,17 @@ class AutocompleteActionPredictorTableReopenTest } }; +AutocompleteActionPredictorTableTest::AutocompleteActionPredictorTableTest() + : loop_(base::MessageLoop::TYPE_DEFAULT), + db_thread_(BrowserThread::DB, &loop_) { +} + +AutocompleteActionPredictorTableTest::~AutocompleteActionPredictorTableTest() { +} + void AutocompleteActionPredictorTableTest::SetUp() { db_.reset(new PredictorDatabase(&profile_)); - base::RunLoop().RunUntilIdle(); + loop_.RunUntilIdle(); test_db_.push_back(AutocompleteActionPredictorTable::Row( "BD85DBA2-8C29-49F9-84AE-48E1E90880DF", @@ -85,7 +98,7 @@ void AutocompleteActionPredictorTableTest::SetUp() { void AutocompleteActionPredictorTableTest::TearDown() { db_.reset(NULL); - base::RunLoop().RunUntilIdle(); + loop_.RunUntilIdle(); test_db_.clear(); } diff --git a/chrome/browser/prefs/pref_model_associator_unittest.cc b/chrome/browser/prefs/pref_model_associator_unittest.cc index 2a3f11d3c..74c985e 100644 --- a/chrome/browser/prefs/pref_model_associator_unittest.cc +++ b/chrome/browser/prefs/pref_model_associator_unittest.cc @@ -8,7 +8,6 @@ #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" class AbstractPreferenceMergeTest : public testing::Test { @@ -49,7 +48,6 @@ class AbstractPreferenceMergeTest : public testing::Test { pref_service_->Set(pref_name.c_str(), *empty_value); } - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; PrefService* pref_service_; }; diff --git a/chrome/browser/prerender/prerender_unittest.cc b/chrome/browser/prerender/prerender_unittest.cc index cbd12f7..5c1a466 100644 --- a/chrome/browser/prerender/prerender_unittest.cc +++ b/chrome/browser/prerender/prerender_unittest.cc @@ -5,6 +5,7 @@ #include "base/command_line.h" #include "base/format_macros.h" #include "base/memory/scoped_vector.h" +#include "base/message_loop/message_loop.h" #include "base/strings/stringprintf.h" #include "base/time/time.h" #include "chrome/browser/prerender/prerender_contents.h" @@ -15,9 +16,8 @@ #include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/render_view_host.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/size.h" #include "url/gurl.h" @@ -277,7 +277,8 @@ class PrerenderTest : public testing::Test { static const int kDefaultChildId = -1; static const int kDefaultRenderViewRouteId = -1; - PrerenderTest() : prerender_manager_(new UnitTestPrerenderManager( + PrerenderTest() : ui_thread_(BrowserThread::UI, &message_loop_), + prerender_manager_(new UnitTestPrerenderManager( &profile_, prerender_tracker())), prerender_link_manager_( new PrerenderLinkManager(prerender_manager_.get())), @@ -346,8 +347,9 @@ class PrerenderTest : public testing::Test { } // Needed to pass PrerenderManager's DCHECKs. - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; + base::MessageLoop message_loop_; + content::TestBrowserThread ui_thread_; scoped_ptr<UnitTestPrerenderManager> prerender_manager_; scoped_ptr<PrerenderLinkManager> prerender_link_manager_; int last_prerender_id_; diff --git a/chrome/browser/printing/print_dialog_cloud_unittest.cc b/chrome/browser/printing/print_dialog_cloud_unittest.cc index 4b4e9a8..c08ffa8 100644 --- a/chrome/browser/printing/print_dialog_cloud_unittest.cc +++ b/chrome/browser/printing/print_dialog_cloud_unittest.cc @@ -22,11 +22,10 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -149,20 +148,26 @@ class MockCloudPrintDataSenderHelper : public CloudPrintDataSenderHelper { }; class CloudPrintURLTest : public testing::Test { + public: + CloudPrintURLTest() {} + protected: - content::TestBrowserThreadBundle thread_bundle_; - TestingProfile profile_; + virtual void SetUp() { + profile_.reset(new TestingProfile()); + } + + scoped_ptr<Profile> profile_; }; TEST_F(CloudPrintURLTest, CheckDefaultURLs) { std::string service_url = - CloudPrintURL(&profile_). + CloudPrintURL(profile_.get()). GetCloudPrintServiceURL().spec(); EXPECT_THAT(service_url, HasSubstr("www.google.com")); EXPECT_THAT(service_url, HasSubstr("cloudprint")); std::string dialog_url = - CloudPrintURL(&profile_). + CloudPrintURL(profile_.get()). GetCloudPrintServiceDialogURL().spec(); EXPECT_THAT(dialog_url, HasSubstr("www.google.com")); EXPECT_THAT(dialog_url, HasSubstr("/cloudprint/")); @@ -172,7 +177,7 @@ TEST_F(CloudPrintURLTest, CheckDefaultURLs) { // Repeat to make sure there isn't a transient glitch. dialog_url = - CloudPrintURL(&profile_). + CloudPrintURL(profile_.get()). GetCloudPrintServiceDialogURL().spec(); EXPECT_THAT(dialog_url, HasSubstr("www.google.com")); EXPECT_THAT(dialog_url, HasSubstr("/cloudprint/")); @@ -181,7 +186,7 @@ TEST_F(CloudPrintURLTest, CheckDefaultURLs) { EXPECT_THAT(dialog_url, HasSubstr("/dialog.html")); std::string manage_url = - CloudPrintURL(&profile_). + CloudPrintURL(profile_.get()). GetCloudPrintServiceManageURL().spec(); EXPECT_THAT(manage_url, HasSubstr("www.google.com")); EXPECT_THAT(manage_url, HasSubstr("/cloudprint/")); @@ -208,6 +213,11 @@ TEST_F(CloudPrintURLTest, CheckDefaultURLs) { // Testing for CloudPrintDataSender needs a mock WebUI. class CloudPrintDataSenderTest : public testing::Test { + public: + CloudPrintDataSenderTest() + : file_thread_(BrowserThread::FILE, &message_loop_), + io_thread_(BrowserThread::IO, &message_loop_) {} + protected: virtual void SetUp() { mock_helper_.reset(new MockCloudPrintDataSenderHelper); @@ -225,7 +235,9 @@ class CloudPrintDataSenderTest : public testing::Test { scoped_refptr<CloudPrintDataSender> print_data_sender_; scoped_ptr<MockCloudPrintDataSenderHelper> mock_helper_; - content::TestBrowserThreadBundle thread_bundle_; + base::MessageLoop message_loop_; + content::TestBrowserThread file_thread_; + content::TestBrowserThread io_thread_; }; TEST_F(CloudPrintDataSenderTest, CanSend) { @@ -279,6 +291,10 @@ using internal_cloud_print_helpers::MockCloudPrintFlowHandler; using internal_cloud_print_helpers::CloudPrintWebDialogDelegate; class CloudPrintWebDialogDelegateTest : public testing::Test { + public: + CloudPrintWebDialogDelegateTest() + : ui_thread_(BrowserThread::UI, &message_loop_) {} + protected: virtual void SetUp() { string16 mock_title; @@ -300,7 +316,8 @@ class CloudPrintWebDialogDelegateTest : public testing::Test { delete mock_flow_handler_.get(); } - content::TestBrowserThreadBundle thread_bundle_; + base::MessageLoopForUI message_loop_; + content::TestBrowserThread ui_thread_; base::WeakPtr<MockCloudPrintFlowHandler> mock_flow_handler_; scoped_ptr<CloudPrintWebDialogDelegate> delegate_; }; diff --git a/chrome/browser/profile_resetter/profile_resetter_unittest.cc b/chrome/browser/profile_resetter/profile_resetter_unittest.cc index 804ba09..34b6110 100644 --- a/chrome/browser/profile_resetter/profile_resetter_unittest.cc +++ b/chrome/browser/profile_resetter/profile_resetter_unittest.cc @@ -25,7 +25,7 @@ #include "chrome/common/pref_names.h" #include "chrome/test/base/browser_with_test_window_test.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "extensions/common/manifest_constants.h" #include "net/http/http_response_headers.h" #include "net/url_request/test_url_fetcher_factory.h" @@ -176,13 +176,17 @@ class ConfigParserTest : public testing::Test { MOCK_METHOD0(Callback, void(void)); - content::TestBrowserThreadBundle thread_bundle_; + base::MessageLoop loop_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread io_thread_; URLFetcherRequestListener request_listener_; net::FakeURLFetcherFactory factory_; }; ConfigParserTest::ConfigParserTest() - : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), + : loop_(base::MessageLoop::TYPE_IO), + ui_thread_(content::BrowserThread::UI, &loop_), + io_thread_(content::BrowserThread::IO, &loop_), factory_(NULL, base::Bind(&ConfigParserTest::CreateFakeURLFetcher, base::Unretained(this))) { } diff --git a/chrome/browser/profiles/avatar_menu_model_unittest.cc b/chrome/browser/profiles/avatar_menu_model_unittest.cc index 50d74ca..3a140f8 100644 --- a/chrome/browser/profiles/avatar_menu_model_unittest.cc +++ b/chrome/browser/profiles/avatar_menu_model_unittest.cc @@ -14,7 +14,6 @@ #include "chrome/browser/profiles/profiles_state.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile_manager.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" @@ -56,7 +55,6 @@ class AvatarMenuModelTest : public testing::Test { TestingProfileManager* manager() { return &manager_; } private: - content::TestBrowserThreadBundle thread_bundle_; TestingProfileManager manager_; }; diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index 84726b1..4aacf82 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -30,7 +30,6 @@ #include "chrome/browser/io_thread.h" #include "chrome/browser/media/chrome_midi_permission_context.h" #include "chrome/browser/media/chrome_midi_permission_context_factory.h" -#include "chrome/browser/net/cookie_store_util.h" #include "chrome/browser/net/pref_proxy_config_tracker.h" #include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h" @@ -48,7 +47,6 @@ #include "components/browser_context_keyed_service/browser_context_dependency_manager.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/host_zoom_map.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/storage_partition.h" @@ -252,24 +250,6 @@ DownloadManagerDelegate* OffTheRecordProfileImpl::GetDownloadManagerDelegate() { GetDownloadManagerDelegate(); } -void OffTheRecordProfileImpl::OverrideCookieStoreConfigs( - const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - CookieSchemeMap* configs) { - // The delegate is stateless so it's silly to create more than one per - // profile. - if (!cookie_delegate_) { - cookie_delegate_ = chrome_browser_net::CreateCookieDelegate(this); - } - - // Force everything to be to be in-memory. - chrome_browser_net::SetCookieStoreConfigs( - base::FilePath(), true, is_default_partition, - content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - GetSpecialStoragePolicy(), cookie_delegate_, configs); -} - net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { return GetDefaultStoragePartition(this)->GetURLRequestContext(); } @@ -322,6 +302,11 @@ void OffTheRecordProfileImpl::RequestMIDISysExPermission( } net::URLRequestContextGetter* + OffTheRecordProfileImpl::GetRequestContextForExtensions() { + return io_data_.GetExtensionsRequestContextGetter().get(); +} + +net::URLRequestContextGetter* OffTheRecordProfileImpl::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index e1e6b87..85fced7 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -46,6 +46,8 @@ class OffTheRecordProfileImpl : public Profile { GetExtensionSpecialStoragePolicy() OVERRIDE; virtual PrefService* GetPrefs() OVERRIDE; virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; + virtual net::URLRequestContextGetter* + GetRequestContextForExtensions() OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( @@ -87,10 +89,6 @@ class OffTheRecordProfileImpl : public Profile { virtual bool IsOffTheRecord() const OVERRIDE; virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; - virtual void OverrideCookieStoreConfigs(const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - CookieSchemeMap* configs) OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( int renderer_child_id) OVERRIDE; @@ -142,8 +140,6 @@ class OffTheRecordProfileImpl : public Profile { content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; - scoped_refptr<net::CookieMonsterDelegate> cookie_delegate_; - DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); }; 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 5ce4499..842204e 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -85,6 +85,18 @@ OffTheRecordProfileIOData::Handle::CreateMainRequestContextGetter( } scoped_refptr<ChromeURLRequestContextGetter> +OffTheRecordProfileIOData::Handle::GetExtensionsRequestContextGetter() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + LazyInitialize(); + if (!extensions_request_context_getter_.get()) { + extensions_request_context_getter_ = + ChromeURLRequestContextGetter::CreateOffTheRecordForExtensions( + profile_, io_data_); + } + return extensions_request_context_getter_; +} + +scoped_refptr<ChromeURLRequestContextGetter> OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter( const base::FilePath& partition_path, bool in_memory) const { @@ -191,6 +203,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())); + net::HttpCache::BackendFactory* main_backend = net::HttpCache::DefaultBackend::InMemory(0); net::HttpNetworkSession::Params network_session_params; @@ -215,6 +230,52 @@ void OffTheRecordProfileIOData::InitializeInternal( network_delegate(), ftp_factory_.get()); main_context->set_job_factory(main_job_factory_.get()); + +#if defined(ENABLE_EXTENSIONS) + InitializeExtensionsRequestContext(profile_params); +#endif +} + +void OffTheRecordProfileIOData:: + InitializeExtensionsRequestContext(ProfileParams* profile_params) const { + ChromeURLRequestContext* extensions_context = extensions_request_context(); + + IOThread* const io_thread = profile_params->io_thread; + IOThread::Globals* const io_thread_globals = io_thread->globals(); + + ApplyProfileParamsToContext(extensions_context); + + extensions_context->set_transport_security_state(transport_security_state()); + + extensions_context->set_net_log(io_thread->net_log()); + + extensions_context->set_throttler_manager( + io_thread_globals->throttler_manager.get()); + + // 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); + // Enable cookies for devtools and extension URLs. + const char* schemes[] = {chrome::kChromeDevToolsScheme, + extensions::kExtensionScheme}; + extensions_cookie_store->SetCookieableSchemes(schemes, 2); + extensions_context->set_cookie_store(extensions_cookie_store); + + scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( + new net::URLRequestJobFactoryImpl()); + // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. + // Without a network_delegate, this protocol handler will never + // handle file: requests, but as a side effect it makes + // job_factory::IsHandledProtocol return true, which prevents attempts to + // handle the protocol externally. We pass NULL in to + // SetUpJobFactoryDefaults() to get this effect. + extensions_job_factory_ = SetUpJobFactoryDefaults( + extensions_job_factory.Pass(), + scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), + NULL, + ftp_factory_.get()); + extensions_context->set_job_factory(extensions_job_factory_.get()); } ChromeURLRequestContext* @@ -229,6 +290,11 @@ OffTheRecordProfileIOData::InitializeAppRequestContext( // Copy most state from the main context. context->CopyFrom(main_context); + // 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)); + // Use a separate in-memory cache for the app. net::HttpCache::BackendFactory* app_backend = net::HttpCache::DefaultBackend::InMemory(0); diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.h b/chrome/browser/profiles/off_the_record_profile_io_data.h index 7d4f046..2a40135 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.h +++ b/chrome/browser/profiles/off_the_record_profile_io_data.h @@ -51,6 +51,8 @@ class OffTheRecordProfileIOData : public ProfileIOData { CreateMainRequestContextGetter( content::ProtocolHandlerMap* protocol_handlers) const; scoped_refptr<ChromeURLRequestContextGetter> + GetExtensionsRequestContextGetter() const; + scoped_refptr<ChromeURLRequestContextGetter> GetIsolatedAppRequestContextGetter( const base::FilePath& partition_path, bool in_memory) const; @@ -81,6 +83,8 @@ class OffTheRecordProfileIOData : public ProfileIOData { // the ProfileIOData on the IO thread. mutable scoped_refptr<ChromeURLRequestContextGetter> main_request_context_getter_; + mutable scoped_refptr<ChromeURLRequestContextGetter> + extensions_request_context_getter_; mutable ChromeURLRequestContextGetterMap app_request_context_getter_map_; OffTheRecordProfileIOData* const io_data_; @@ -104,6 +108,8 @@ class OffTheRecordProfileIOData : public ProfileIOData { virtual void InitializeInternal( ProfileParams* profile_params, content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + virtual void InitializeExtensionsRequestContext( + ProfileParams* profile_params) const OVERRIDE; virtual ChromeURLRequestContext* InitializeAppRequestContext( ChromeURLRequestContext* main_context, const StoragePartitionDescriptor& partition_descriptor, @@ -135,6 +141,7 @@ class OffTheRecordProfileIOData : public ProfileIOData { mutable scoped_ptr<net::FtpTransactionFactory> ftp_factory_; mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_; + mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_; DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileIOData); }; diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 0d3ffcd..3af9eeb 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -230,6 +230,10 @@ class Profile : public content::BrowserContext { // Returns the main request context. virtual net::URLRequestContextGetter* GetRequestContext() = 0; + // Returns the request context used for extension-related requests. This + // is only used for a separate cookie store currently. + virtual net::URLRequestContextGetter* GetRequestContextForExtensions() = 0; + // Returns the SSLConfigService for this profile. virtual net::SSLConfigService* GetSSLConfigService() = 0; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index b5f2b11..1ad2bcf 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -48,7 +48,6 @@ #include "chrome/browser/media/chrome_midi_permission_context_factory.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/browser/net/cookie_store_util.h" #include "chrome/browser/net/net_pref_observer.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/net/pref_proxy_config_tracker.h" @@ -87,7 +86,6 @@ #include "components/user_prefs/pref_registry_syncable.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/dom_storage_context.h" #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_service.h" @@ -499,6 +497,8 @@ void ProfileImpl::DoFinalInit() { g_browser_process->background_mode_manager()->RegisterProfile(this); } + base::FilePath cookie_path = GetPath(); + cookie_path = cookie_path.Append(chrome::kCookieFilename); base::FilePath server_bound_cert_path = GetPath(); server_bound_cert_path = server_bound_cert_path.Append(chrome::kOBCertFilename); @@ -520,14 +520,28 @@ void ProfileImpl::DoFinalInit() { infinite_cache_path = infinite_cache_path.Append(FILE_PATH_LITERAL("Infinite Cache")); +#if defined(OS_ANDROID) + SessionStartupPref::Type startup_pref_type = + SessionStartupPref::GetDefaultStartupType(); +#else + SessionStartupPref::Type startup_pref_type = + StartupBrowserCreator::GetSessionStartupPref( + *CommandLine::ForCurrentProcess(), this).type; +#endif + bool restore_old_session_cookies = + (GetLastSessionExitType() == Profile::EXIT_CRASHED || + startup_pref_type == SessionStartupPref::LAST); + InitHostZoomMap(); // Make sure we initialize the ProfileIOData after everything else has been // initialized that we might be reading from the IO thread. - io_data_.Init(server_bound_cert_path, cache_path, + io_data_.Init(cookie_path, server_bound_cert_path, cache_path, cache_max_size, media_cache_path, media_cache_max_size, - GetPath(), infinite_cache_path, predictor_, + extensions_cookie_path, GetPath(), infinite_cache_path, + predictor_, + restore_old_session_cookies, GetSpecialStoragePolicy()); #if defined(ENABLE_PLUGINS) @@ -545,7 +559,7 @@ void ProfileImpl::DoFinalInit() { if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableRestoreSessionState)) { TRACE_EVENT0("browser", "ProfileImpl::SetSaveSessionStorageOnDisk") - GetDefaultStoragePartition(this)-> + content::BrowserContext::GetDefaultStoragePartition(this)-> GetDOMStorageContext()->SetSaveSessionStorageOnDisk(); } @@ -659,40 +673,8 @@ scoped_refptr<base::SequencedTaskRunner> ProfileImpl::GetIOTaskRunner() { GetPath(), BrowserThread::GetBlockingPool()); } -void ProfileImpl::OverrideCookieStoreConfigs( - const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - CookieSchemeMap* configs) { - using content::CookieStoreConfig; - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - // The delegate is stateless so it's silly to create more than one per - // profile. - if (!cookie_delegate_) { - cookie_delegate_ = chrome_browser_net::CreateCookieDelegate(this); - } - -#if defined(OS_ANDROID) - SessionStartupPref::Type startup_pref_type = - SessionStartupPref::GetDefaultStartupType(); -#else - SessionStartupPref::Type startup_pref_type = - StartupBrowserCreator::GetSessionStartupPref( - *CommandLine::ForCurrentProcess(), this).type; -#endif - - CookieStoreConfig::SessionCookieMode session_cookie_mode = - CookieStoreConfig::PERSISTANT_SESSION_COOKIES; - if (GetLastSessionExitType() == Profile::EXIT_CRASHED || - startup_pref_type == SessionStartupPref::LAST) { - session_cookie_mode = CookieStoreConfig::RESTORED_SESSION_COOKIES; - } - - chrome_browser_net::SetCookieStoreConfigs( - partition_path, in_memory_partition, is_default_partition, - session_cookie_mode, GetSpecialStoragePolicy(), cookie_delegate_, - configs); +bool ProfileImpl::IsOffTheRecord() const { + return false; } Profile* ProfileImpl::GetOffTheRecordProfile() { @@ -902,6 +884,10 @@ content::ResourceContext* ProfileImpl::GetResourceContext() { return io_data_.GetResourceContext(); } +net::URLRequestContextGetter* ProfileImpl::GetRequestContextForExtensions() { + return io_data_.GetExtensionsRequestContextGetter().get(); +} + net::URLRequestContextGetter* ProfileImpl::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 2d228aa..544091e 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -62,10 +62,6 @@ class ProfileImpl : public Profile { // content::BrowserContext implementation: virtual base::FilePath GetPath() const OVERRIDE; - virtual void OverrideCookieStoreConfigs(const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - CookieSchemeMap* configs) OVERRIDE; virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; @@ -93,6 +89,7 @@ class ProfileImpl : public Profile { // Note that this implementation returns the Google-services username, if any, // not the Chrome user's display name. virtual std::string GetProfileName() OVERRIDE; + virtual bool IsOffTheRecord() const OVERRIDE; virtual Profile* GetOffTheRecordProfile() OVERRIDE; virtual void DestroyOffTheRecordProfile() OVERRIDE; virtual bool HasOffTheRecordProfile() OVERRIDE; @@ -105,6 +102,8 @@ class ProfileImpl : public Profile { GetExtensionSpecialStoragePolicy() OVERRIDE; virtual PrefService* GetPrefs() OVERRIDE; virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; + virtual net::URLRequestContextGetter* + GetRequestContextForExtensions() OVERRIDE; virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; virtual bool IsSameProfile(Profile* profile) OVERRIDE; @@ -255,8 +254,6 @@ class ProfileImpl : public Profile { scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; - scoped_refptr<net::CookieMonsterDelegate> cookie_delegate_; - // STOP!!!! DO NOT ADD ANY MORE ITEMS HERE!!!! // // Instead, make your Service/Manager/whatever object you're hanging off the diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index 7ee0770..4026f4b 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -22,7 +22,6 @@ #include "chrome/browser/net/chrome_net_log.h" #include "chrome/browser/net/chrome_network_delegate.h" #include "chrome/browser/net/connect_interceptor.h" -#include "chrome/browser/net/cookie_store_util.h" #include "chrome/browser/net/http_server_properties_manager.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/net/sqlite_server_bound_cert_store.h" @@ -97,27 +96,33 @@ ProfileImplIOData::Handle::~Handle() { } void ProfileImplIOData::Handle::Init( + const base::FilePath& cookie_path, const base::FilePath& server_bound_cert_path, const base::FilePath& cache_path, int cache_max_size, const base::FilePath& media_cache_path, int media_cache_max_size, + const base::FilePath& extensions_cookie_path, const base::FilePath& profile_path, const base::FilePath& infinite_cache_path, chrome_browser_net::Predictor* predictor, + bool restore_old_session_cookies, quota::SpecialStoragePolicy* special_storage_policy) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!io_data_->lazy_params_); DCHECK(predictor); - LazyParams* lazy_params = new LazyParams(); + LazyParams* lazy_params = new LazyParams; + lazy_params->cookie_path = cookie_path; lazy_params->server_bound_cert_path = server_bound_cert_path; lazy_params->cache_path = cache_path; lazy_params->cache_max_size = cache_max_size; lazy_params->media_cache_path = media_cache_path; lazy_params->media_cache_max_size = media_cache_max_size; + lazy_params->extensions_cookie_path = extensions_cookie_path; lazy_params->infinite_cache_path = infinite_cache_path; + lazy_params->restore_old_session_cookies = restore_old_session_cookies; lazy_params->special_storage_policy = special_storage_policy; io_data_->lazy_params_.reset(lazy_params); @@ -186,6 +191,18 @@ ProfileImplIOData::Handle::GetMediaRequestContextGetter() const { } scoped_refptr<ChromeURLRequestContextGetter> +ProfileImplIOData::Handle::GetExtensionsRequestContextGetter() const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + LazyInitialize(); + if (!extensions_request_context_getter_.get()) { + extensions_request_context_getter_ = + ChromeURLRequestContextGetter::CreateOriginalForExtensions(profile_, + io_data_); + } + return extensions_request_context_getter_; +} + +scoped_refptr<ChromeURLRequestContextGetter> ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( const base::FilePath& partition_path, bool in_memory, @@ -291,7 +308,8 @@ void ProfileImplIOData::Handle::LazyInitialize() const { ProfileImplIOData::LazyParams::LazyParams() : cache_max_size(0), - media_cache_max_size(0) {} + media_cache_max_size(0), + restore_old_session_cookies(false) {} ProfileImplIOData::LazyParams::~LazyParams() {} @@ -312,6 +330,13 @@ void ProfileImplIOData::InitializeInternal( IOThread* const io_thread = profile_params->io_thread; IOThread::Globals* const io_thread_globals = io_thread->globals(); + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + // Only allow Record Mode if we are in a Debug build or where we are running + // a cycle, and the user has limited control. + bool record_mode = command_line.HasSwitch(switches::kRecordMode) && + (chrome::kRecordModeEnabled || + command_line.HasSwitch(switches::kVisitURLs)); + bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); network_delegate()->set_predictor(predictor_.get()); @@ -343,14 +368,32 @@ void ProfileImplIOData::InitializeInternal( main_context->set_proxy_service(proxy_service()); + scoped_refptr<net::CookieStore> cookie_store = NULL; net::ServerBoundCertService* server_bound_cert_service = NULL; - if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { + 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()); // Don't use existing server-bound certs and use an in-memory store. server_bound_cert_service = new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), base::WorkerPool::GetTaskRunner(true)); } + // setup cookie store + if (!cookie_store.get()) { + DCHECK(!lazy_params_->cookie_path.empty()); + + cookie_store = content::CreatePersistentCookieStore( + lazy_params_->cookie_path, + lazy_params_->restore_old_session_cookies, + lazy_params_->special_storage_policy.get(), + profile_params->cookie_monster_delegate.get()); + cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); + } + + main_context->set_cookie_store(cookie_store.get()); + // Setup server bound cert service. if (!server_bound_cert_service) { DCHECK(!lazy_params_->server_bound_cert_path.empty()); @@ -385,10 +428,9 @@ void ProfileImplIOData::InitializeInternal( ChromeDataReductionProxyAndroid::Init(main_cache->GetSession()); #endif - if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { + if (record_mode || playback_mode) { main_cache->set_mode( - chrome_browser_net::IsCookieRecordMode() ? - net::HttpCache::RECORD : net::HttpCache::PLAYBACK); + record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); } main_http_factory_.reset(main_cache); @@ -409,6 +451,10 @@ void ProfileImplIOData::InitializeInternal( ftp_factory_.get()); main_context->set_job_factory(main_job_factory_.get()); +#if defined(ENABLE_EXTENSIONS) + InitializeExtensionsRequestContext(profile_params); +#endif + // Create a media request context based on the main context, but using a // media cache. It shares the same job factory as the main context. StoragePartitionDescriptor details(profile_path_, false); @@ -418,6 +464,48 @@ void ProfileImplIOData::InitializeInternal( lazy_params_.reset(); } +void ProfileImplIOData:: + InitializeExtensionsRequestContext(ProfileParams* profile_params) const { + ChromeURLRequestContext* extensions_context = extensions_request_context(); + IOThread* const io_thread = profile_params->io_thread; + IOThread::Globals* const io_thread_globals = io_thread->globals(); + ApplyProfileParamsToContext(extensions_context); + + extensions_context->set_transport_security_state(transport_security_state()); + + extensions_context->set_net_log(io_thread->net_log()); + + extensions_context->set_throttler_manager( + io_thread_globals->throttler_manager.get()); + + net::CookieStore* extensions_cookie_store = + content::CreatePersistentCookieStore( + lazy_params_->extensions_cookie_path, + lazy_params_->restore_old_session_cookies, + NULL, + NULL); + // Enable cookies for devtools and extension URLs. + const char* schemes[] = {chrome::kChromeDevToolsScheme, + extensions::kExtensionScheme}; + extensions_cookie_store->GetCookieMonster()->SetCookieableSchemes(schemes, 2); + extensions_context->set_cookie_store(extensions_cookie_store); + + scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( + new net::URLRequestJobFactoryImpl()); + // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. + // Without a network_delegate, this protocol handler will never + // handle file: requests, but as a side effect it makes + // job_factory::IsHandledProtocol return true, which prevents attempts to + // handle the protocol externally. We pass NULL in to + // SetUpJobFactory() to get this effect. + extensions_job_factory_ = SetUpJobFactoryDefaults( + extensions_job_factory.Pass(), + scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>(), + NULL, + ftp_factory_.get()); + extensions_context->set_job_factory(extensions_job_factory_.get()); +} + ChromeURLRequestContext* ProfileImplIOData::InitializeAppRequestContext( ChromeURLRequestContext* main_context, @@ -429,9 +517,19 @@ ProfileImplIOData::InitializeAppRequestContext( AppRequestContext* context = new AppRequestContext(load_time_stats()); context->CopyFrom(main_context); + base::FilePath cookie_path = partition_descriptor.path.Append( + chrome::kCookieFilename); base::FilePath cache_path = partition_descriptor.path.Append(chrome::kCacheDirname); + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + // Only allow Record Mode if we are in a Debug build or where we are running + // a cycle, and the user has limited control. + bool record_mode = command_line.HasSwitch(switches::kRecordMode) && + (chrome::kRecordModeEnabled || + command_line.HasSwitch(switches::kVisitURLs)); + bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); + // Use a separate HTTP disk cache for isolated apps. net::HttpCache::BackendFactory* app_backend = NULL; if (partition_descriptor.in_memory) { @@ -450,12 +548,35 @@ ProfileImplIOData::InitializeAppRequestContext( net::HttpCache* app_http_cache = new net::HttpCache(main_network_session, app_backend); - if (chrome_browser_net::ShouldUseInMemoryCookiesAndCache()) { + scoped_refptr<net::CookieStore> cookie_store = NULL; + if (partition_descriptor.in_memory) { + cookie_store = new net::CookieMonster(NULL, 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); app_http_cache->set_mode( - chrome_browser_net::IsCookieRecordMode() ? - net::HttpCache::RECORD : net::HttpCache::PLAYBACK); + record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); + } + + // Use an app-specific cookie store. + if (!cookie_store.get()) { + DCHECK(!cookie_path.empty()); + + // 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 = content::CreatePersistentCookieStore( + cookie_path, + false, + NULL, + NULL); } + // Transfer ownership of the cookies and cache to AppRequestContext. + context->SetCookieStore(cookie_store.get()); context->SetHttpTransactionFactory( scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h index d6a1e92..bce32a9 100644 --- a/chrome/browser/profiles/profile_impl_io_data.h +++ b/chrome/browser/profiles/profile_impl_io_data.h @@ -36,14 +36,17 @@ class ProfileImplIOData : public ProfileIOData { // Init() must be called before ~Handle(). It records most of the // parameters needed to construct a ChromeURLRequestContextGetter. - void Init(const base::FilePath& server_bound_cert_path, + void Init(const base::FilePath& cookie_path, + const base::FilePath& server_bound_cert_path, const base::FilePath& cache_path, int cache_max_size, const base::FilePath& media_cache_path, int media_cache_max_size, + const base::FilePath& extensions_cookie_path, const base::FilePath& profile_path, const base::FilePath& infinite_cache_path, chrome_browser_net::Predictor* predictor, + bool restore_old_session_cookies, quota::SpecialStoragePolicy* special_storage_policy); // These Create*ContextGetter() functions are only exposed because the @@ -68,6 +71,8 @@ class ProfileImplIOData : public ProfileIOData { scoped_refptr<ChromeURLRequestContextGetter> GetMediaRequestContextGetter() const; scoped_refptr<ChromeURLRequestContextGetter> + GetExtensionsRequestContextGetter() const; + scoped_refptr<ChromeURLRequestContextGetter> GetIsolatedMediaRequestContextGetter( const base::FilePath& partition_path, bool in_memory) const; @@ -124,12 +129,15 @@ class ProfileImplIOData : public ProfileIOData { ~LazyParams(); // All of these parameters are intended to be read on the IO thread. + base::FilePath cookie_path; base::FilePath server_bound_cert_path; base::FilePath cache_path; int cache_max_size; base::FilePath media_cache_path; int media_cache_max_size; + base::FilePath extensions_cookie_path; base::FilePath infinite_cache_path; + bool restore_old_session_cookies; scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy; }; @@ -142,6 +150,8 @@ class ProfileImplIOData : public ProfileIOData { virtual void InitializeInternal( ProfileParams* profile_params, content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + virtual void InitializeExtensionsRequestContext( + ProfileParams* profile_params) const OVERRIDE; virtual ChromeURLRequestContext* InitializeAppRequestContext( ChromeURLRequestContext* main_context, const StoragePartitionDescriptor& partition_descriptor, diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index e972dbf..0e8e732 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -36,6 +36,7 @@ #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/net/about_protocol_handler.h" +#include "chrome/browser/net/chrome_cookie_notification_details.h" #include "chrome/browser/net/chrome_fraudulent_certificate_reporter.h" #include "chrome/browser/net/chrome_http_user_agent_settings.h" #include "chrome/browser/net/chrome_net_log.h" @@ -64,6 +65,7 @@ #include "extensions/common/constants.h" #include "net/cert/cert_verifier.h" #include "net/cookies/canonical_cookie.h" +#include "net/cookies/cookie_monster.h" #include "net/http/http_transaction_factory.h" #include "net/http/http_util.h" #include "net/proxy/proxy_config_service_fixed.h" @@ -99,6 +101,56 @@ using content::ResourceContext; namespace { +// ---------------------------------------------------------------------------- +// CookieMonster::Delegate implementation +// ---------------------------------------------------------------------------- +class ChromeCookieMonsterDelegate : public net::CookieMonster::Delegate { + public: + explicit ChromeCookieMonsterDelegate( + const base::Callback<Profile*(void)>& profile_getter) + : profile_getter_(profile_getter) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + } + + // net::CookieMonster::Delegate implementation. + virtual void OnCookieChanged( + const net::CanonicalCookie& cookie, + bool removed, + net::CookieMonster::Delegate::ChangeCause cause) OVERRIDE { + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&ChromeCookieMonsterDelegate::OnCookieChangedAsyncHelper, + this, cookie, removed, cause)); + } + + private: + virtual ~ChromeCookieMonsterDelegate() {} + + void OnCookieChangedAsyncHelper( + const net::CanonicalCookie& cookie, + bool removed, + net::CookieMonster::Delegate::ChangeCause cause) { + Profile* profile = profile_getter_.Run(); + if (profile) { + ChromeCookieDetails cookie_details(&cookie, removed, cause); + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_COOKIE_CHANGED, + content::Source<Profile>(profile), + content::Details<ChromeCookieDetails>(&cookie_details)); + } + } + + const base::Callback<Profile*(void)> profile_getter_; +}; + +Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(profile); + if (profile_manager->IsValidProfile(profile)) + return profile; + return NULL; +} + #if defined(DEBUG_DEVTOOLS) bool IsSupportedDevToolsURL(const GURL& url, base::FilePath* path) { std::string bundled_path_prefix(chrome::kChromeUIDevToolsBundledPath); @@ -202,6 +254,12 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) { params->cookie_settings = CookieSettings::Factory::GetForProfile(profile); params->host_content_settings_map = profile->GetHostContentSettingsMap(); params->ssl_config_service = profile->GetSSLConfigService(); + base::Callback<Profile*(void)> profile_getter = + base::Bind(&GetProfileOnUI, g_browser_process->profile_manager(), + profile); + params->cookie_monster_delegate = + new chrome_browser_net::EvictedDomainCookieCounter( + new ChromeCookieMonsterDelegate(profile_getter)); params->extension_info_map = extensions::ExtensionSystem::Get(profile)->info_map(); @@ -323,6 +381,12 @@ ProfileIOData::AppRequestContext::AppRequestContext( load_time_stats) { } +void ProfileIOData::AppRequestContext::SetCookieStore( + net::CookieStore* cookie_store) { + cookie_store_ = cookie_store; + set_cookie_store(cookie_store); +} + void ProfileIOData::AppRequestContext::SetHttpTransactionFactory( scoped_ptr<net::HttpTransactionFactory> http_factory) { http_factory_ = http_factory.Pass(); @@ -409,6 +473,8 @@ ProfileIOData::~ProfileIOData() { // are already done in the URLRequestContext destructor. if (main_request_context_) main_request_context_->AssertNoURLRequests(); + if (extensions_request_context_) + extensions_request_context_->AssertNoURLRequests(); current_context = 0; for (URLRequestContextMap::iterator it = app_request_context_map_.begin(); @@ -513,6 +579,11 @@ ChromeURLRequestContext* ProfileIOData::GetMediaRequestContext() const { return context; } +ChromeURLRequestContext* ProfileIOData::GetExtensionsRequestContext() const { + DCHECK(initialized_); + return extensions_request_context_.get(); +} + ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( ChromeURLRequestContext* main_context, const StoragePartitionDescriptor& partition_descriptor, @@ -692,6 +763,10 @@ void ProfileIOData::Init(content::ProtocolHandlerMap* protocol_handlers) const { main_request_context_.reset( new ChromeURLRequestContext(ChromeURLRequestContext::CONTEXT_TYPE_MAIN, load_time_stats_)); + extensions_request_context_.reset( + new ChromeURLRequestContext( + ChromeURLRequestContext::CONTEXT_TYPE_EXTENSIONS, + load_time_stats_)); ChromeNetworkDelegate* network_delegate = new ChromeNetworkDelegate( diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index d4e9a61..724a728 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -99,6 +99,7 @@ class ProfileIOData { ChromeURLRequestContext* GetMainRequestContext() const; ChromeURLRequestContext* GetMediaRequestContext() const; + ChromeURLRequestContext* GetExtensionsRequestContext() const; ChromeURLRequestContext* GetIsolatedAppRequestContext( ChromeURLRequestContext* main_context, const StoragePartitionDescriptor& partition_descriptor, @@ -152,6 +153,10 @@ class ProfileIOData { return &one_click_signin_rejected_email_list_; } + ChromeURLRequestContext* extensions_request_context() const { + return extensions_request_context_.get(); + } + BooleanPrefMember* safe_browsing_enabled() const { return &safe_browsing_enabled_; } @@ -220,6 +225,7 @@ class ProfileIOData { explicit AppRequestContext( chrome_browser_net::LoadTimeStats* load_time_stats); + void SetCookieStore(net::CookieStore* cookie_store); void SetHttpTransactionFactory( scoped_ptr<net::HttpTransactionFactory> http_factory); void SetJobFactory(scoped_ptr<net::URLRequestJobFactory> job_factory); @@ -227,6 +233,7 @@ class ProfileIOData { private: virtual ~AppRequestContext(); + scoped_refptr<net::CookieStore> cookie_store_; scoped_ptr<net::HttpTransactionFactory> http_factory_; scoped_ptr<net::URLRequestJobFactory> job_factory_; }; @@ -242,6 +249,7 @@ class ProfileIOData { scoped_refptr<CookieSettings> cookie_settings; scoped_refptr<HostContentSettingsMap> host_content_settings_map; scoped_refptr<net::SSLConfigService> ssl_config_service; + scoped_refptr<net::CookieMonster::Delegate> cookie_monster_delegate; scoped_refptr<ExtensionInfoMap> extension_info_map; scoped_ptr<chrome_browser_net::ResourcePrefetchPredictorObserver> resource_prefetch_predictor_observer_; @@ -384,6 +392,9 @@ class ProfileIOData { ProfileParams* profile_params, content::ProtocolHandlerMap* protocol_handlers) const = 0; + // Initializes the RequestContext for extensions. + virtual void InitializeExtensionsRequestContext( + ProfileParams* profile_params) const = 0; // Does an on-demand initialization of a RequestContext for the given // isolated app. virtual ChromeURLRequestContext* InitializeAppRequestContext( @@ -499,6 +510,7 @@ class ProfileIOData { // These are only valid in between LazyInitialize() and their accessor being // called. mutable scoped_ptr<ChromeURLRequestContext> main_request_context_; + mutable scoped_ptr<ChromeURLRequestContext> extensions_request_context_; // One URLRequestContext per isolated app for main and media requests. mutable URLRequestContextMap app_request_context_map_; mutable URLRequestContextMap isolated_media_request_context_map_; diff --git a/chrome/browser/profiles/profile_loader_unittest.cc b/chrome/browser/profiles/profile_loader_unittest.cc index bd24e41..6637ab9 100644 --- a/chrome/browser/profiles/profile_loader_unittest.cc +++ b/chrome/browser/profiles/profile_loader_unittest.cc @@ -12,18 +12,9 @@ #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_loader.h" -#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/testing_profile_manager.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/message_center/message_center.h" - -#if defined(OS_CHROMEOS) -#include "base/command_line.h" -#include "chrome/common/chrome_switches.h" -#endif // defined(OS_CHROMEOS) namespace { @@ -78,30 +69,8 @@ class MockCallback : public base::RefCountedThreadSafe<MockCallback> { MockCallback::MockCallback() {} MockCallback::~MockCallback() {} -class ProfileLoaderTest : public testing::Test { - protected: - static void SetUpTestCase() { -#if defined(OS_CHROMEOS) - // Needed to handle http://crbug.com/119175. - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kDisableZeroBrowsersOpenForTests); -#endif // defined(OS_CHROMEOS) - message_center::MessageCenter::Initialize(); - } - - static void TearDownTestCase() { - message_center::MessageCenter::Shutdown(); - } - - private: - content::TestBrowserThreadBundle thread_bundle_; -}; - -TEST_F(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) { - TestingProfileManager profile_manager(TestingBrowserProcess::GetGlobal()); - ASSERT_TRUE(profile_manager.SetUp()); - TestingProfile* profile = - profile_manager.CreateTestingProfile("TestProfile"); +TEST(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) { + TestingProfile profile; base::FilePath fake_profile_path_1 = base::FilePath::FromUTF8Unsafe("fake/profile 1"); base::FilePath fake_profile_path_2 = @@ -121,7 +90,7 @@ TEST_F(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) { // path_2 loads after the first request. EXPECT_CALL(loader, GetProfileByPath(fake_profile_path_2)) .WillOnce(Return(static_cast<Profile*>(NULL))) - .WillRepeatedly(Return(profile)); + .WillRepeatedly(Return(&profile)); EXPECT_CALL(loader, CreateProfileAsync(fake_profile_path_2, _, _, _, std::string())) .WillRepeatedly(WithArgs<0, 1>( @@ -133,7 +102,7 @@ TEST_F(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) { // path_2_load is called both times. StrictMock<MockCallback>* path_1_load = new StrictMock<MockCallback>(); StrictMock<MockCallback>* path_2_load = new StrictMock<MockCallback>(); - EXPECT_CALL(*path_2_load, Run(profile)) + EXPECT_CALL(*path_2_load, Run(&profile)) .Times(2); // Try to load path_1. @@ -146,9 +115,9 @@ TEST_F(ProfileLoaderTest, LoadProfileInvalidatingOtherLoads) { fake_profile_path_2, base::Bind(&MockCallback::Run, path_2_load)); // Finish the load request for path_1, then for path_2. - loader.RunCreateCallback(fake_profile_path_1, profile, + loader.RunCreateCallback(fake_profile_path_1, &profile, Profile::CREATE_STATUS_INITIALIZED); - loader.RunCreateCallback(fake_profile_path_2, profile, + loader.RunCreateCallback(fake_profile_path_2, &profile, Profile::CREATE_STATUS_INITIALIZED); EXPECT_FALSE(loader.IsAnyProfileLoading()); diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 3cfef1b..5ae4201 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -299,16 +299,15 @@ SafeBrowsingDatabaseManager* SafeBrowsingService::CreateDatabaseManager() { void SafeBrowsingService::InitURLRequestContextOnIOThread( net::URLRequestContextGetter* system_url_request_context_getter) { - using content::CookieStoreConfig; - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(!url_request_context_.get()); scoped_refptr<net::CookieStore> cookie_store( - CreateCookieStore( - CookieStoreConfig(CookieFilePath(), - CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - NULL, NULL))); + content::CreatePersistentCookieStore( + CookieFilePath(), + false, + NULL, + NULL)); url_request_context_.reset(new net::URLRequestContext); // |system_url_request_context_getter| may be NULL during tests. diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc index 2053089..d2e4db4 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc @@ -15,7 +15,6 @@ #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_pref_service_syncable.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" @@ -84,7 +83,6 @@ TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E', 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; for (size_t i = 0; i < arraysize(kCountryIds); ++i) { profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); @@ -104,7 +102,6 @@ TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { // Verifies that default search providers from the preferences file // override the built-in ones. TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, @@ -194,7 +191,6 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { } TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, @@ -248,7 +244,6 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { // Use United States. CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kCountry, "US"); - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; ScopedVector<TemplateURL> t_urls; size_t default_index; diff --git a/chrome/browser/signin/signin_manager_unittest.cc b/chrome/browser/signin/signin_manager_unittest.cc index 160a03a..f008430 100644 --- a/chrome/browser/signin/signin_manager_unittest.cc +++ b/chrome/browser/signin/signin_manager_unittest.cc @@ -23,9 +23,7 @@ #include "chrome/test/base/testing_profile.h" #include "components/webdata/encryptor/encryptor.h" #include "content/public/browser/child_process_security_policy.h" -#include "content/public/browser/storage_partition.h" #include "content/public/test/test_browser_thread_bundle.h" -#include "content/public/test/test_utils.h" #include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_urls.h" #include "net/cookies/cookie_monster.h" @@ -202,12 +200,6 @@ class SigninManagerTest : public TokenServiceTestHarness { manager_->SignOut(); } - net::CookieMonster* GetCookieMonster(const GURL& origin) { - // Since it's a unittest, assume default StoragePartition. - return content::BrowserContext::GetDefaultStoragePartition(profile())-> - GetCookieStoreForScheme(origin.scheme())->GetCookieMonster(); - } - net::TestURLFetcherFactory factory_; scoped_ptr<SigninManager> manager_; content::TestNotificationTracker google_login_success_; @@ -297,14 +289,14 @@ TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) { EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); // Set a valid LSID cookie in the test cookie store. - GURL origin("https://accounts.google.com"); - scoped_refptr<net::CookieMonster> cookie_monster = GetCookieMonster(origin); + scoped_refptr<net::CookieMonster> cookie_monster = + profile()->GetCookieMonster(); net::CookieOptions options; options.set_include_httponly(); cookie_monster->SetCookieWithOptionsAsync( - origin, - "LSID=1234; secure; httponly", options, - net::CookieMonster::SetCookiesCallback()); + GURL("https://accounts.google.com"), + "LSID=1234; secure; httponly", options, + net::CookieMonster::SetCookiesCallback()); // Since the password is empty, will verify the gaia cookies first. manager_->StartSignInWithCredentials( @@ -342,14 +334,14 @@ TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) { EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); // Set an invalid LSID cookie in the test cookie store. - GURL origin("https://accounts.google.com"); - scoped_refptr<net::CookieMonster> cookie_monster = GetCookieMonster(origin); + scoped_refptr<net::CookieMonster> cookie_monster = + profile()->GetCookieMonster(); net::CookieOptions options; options.set_include_httponly(); cookie_monster->SetCookieWithOptionsAsync( - origin, - "LSID=1234; domain=google.com; secure; httponly", options, - net::CookieMonster::SetCookiesCallback()); + GURL("https://accounts.google.com"), + "LSID=1234; domain=google.com; secure; httponly", options, + net::CookieMonster::SetCookiesCallback()); // Since the password is empty, must verify the gaia cookies first. manager_->StartSignInWithCredentials( diff --git a/chrome/browser/spellchecker/feedback_sender_unittest.cc b/chrome/browser/spellchecker/feedback_sender_unittest.cc index fe565ab..5c0b1db 100644 --- a/chrome/browser/spellchecker/feedback_sender_unittest.cc +++ b/chrome/browser/spellchecker/feedback_sender_unittest.cc @@ -20,7 +20,7 @@ #include "chrome/common/spellcheck_marker.h" #include "chrome/common/spellcheck_result.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "net/url_request/test_url_fetcher_factory.h" #include "testing/gtest/include/gtest/gtest.h" @@ -61,7 +61,7 @@ int CountOccurences(const std::string& haystack, const std::string& needle) { // A test fixture to help keep tests simple. class FeedbackSenderTest : public testing::Test { public: - FeedbackSenderTest() { + FeedbackSenderTest() : ui_thread_(content::BrowserThread::UI, &loop_) { // The command-line switch and the field trial are temporary. // TODO(rouslan): Remove the command-line switch and the field trial. // http://crbug.com/247726 @@ -125,8 +125,9 @@ class FeedbackSenderTest : public testing::Test { scoped_ptr<spellcheck::FeedbackSender> feedback_; private: - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; + base::MessageLoop loop_; + content::TestBrowserThread ui_thread_; scoped_ptr<base::FieldTrialList> field_trial_list_; scoped_refptr<base::FieldTrial> field_trial_; net::TestURLFetcherFactory fetchers_; diff --git a/chrome/browser/sync/sync_global_error_unittest.cc b/chrome/browser/sync/sync_global_error_unittest.cc index 0051d65..ee798ea 100644 --- a/chrome/browser/sync/sync_global_error_unittest.cc +++ b/chrome/browser/sync/sync_global_error_unittest.cc @@ -15,6 +15,7 @@ #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" #include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/testing_profile.h" +#include "content/public/test/test_browser_thread.h" #include "testing/gmock/include/gmock/gmock-actions.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/thumbnails/thumbnail_service_unittest.cc b/chrome/browser/thumbnails/thumbnail_service_unittest.cc index b7ef5cd..1b128e3 100644 --- a/chrome/browser/thumbnails/thumbnail_service_unittest.cc +++ b/chrome/browser/thumbnails/thumbnail_service_unittest.cc @@ -7,13 +7,9 @@ #include "base/memory/ref_counted.h" #include "chrome/browser/history/top_sites_impl.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" -class ThumbnailServiceTest : public testing::Test { - private: - content::TestBrowserThreadBundle thread_bundle_; -}; +typedef testing::Test ThumbnailServiceTest; // A mock version of TopSitesImpl, used for testing // ShouldAcquirePageThumbnail(). diff --git a/chrome/browser/ui/autofill/account_chooser_model_unittest.cc b/chrome/browser/ui/autofill/account_chooser_model_unittest.cc index a843407..f27c1be 100644 --- a/chrome/browser/ui/autofill/account_chooser_model_unittest.cc +++ b/chrome/browser/ui/autofill/account_chooser_model_unittest.cc @@ -8,7 +8,6 @@ #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" #include "components/autofill/core/browser/autofill_metrics.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -53,7 +52,6 @@ class AccountChooserModelTest : public testing::Test { const AutofillMetrics& metric_logger() { return metric_logger_; } private: - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; MockAccountChooserModelDelegate delegate_; TestAccountChooserModel model_; diff --git a/chrome/browser/ui/bookmarks/bookmark_ui_utils_unittest.cc b/chrome/browser/ui/bookmarks/bookmark_ui_utils_unittest.cc index 8d5d287..dbe485a 100644 --- a/chrome/browser/ui/bookmarks/bookmark_ui_utils_unittest.cc +++ b/chrome/browser/ui/bookmarks/bookmark_ui_utils_unittest.cc @@ -7,7 +7,6 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #if !defined(OS_ANDROID) && !defined(OS_IOS) @@ -56,7 +55,6 @@ TEST(BookmarkUIUtilsTest, HasBookmarkURLs) { TEST(BookmarkUIUtilsTest, HasBookmarkURLsAllowedInIncognitoMode) { BookmarkModel model(NULL); - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; std::vector<const BookmarkNode*> nodes; diff --git a/chrome/browser/ui/gtk/gtk_theme_service_unittest.cc b/chrome/browser/ui/gtk/gtk_theme_service_unittest.cc index d3eb8ed..8bc1ea4 100644 --- a/chrome/browser/ui/gtk/gtk_theme_service_unittest.cc +++ b/chrome/browser/ui/gtk/gtk_theme_service_unittest.cc @@ -10,7 +10,6 @@ #include "chrome/browser/ui/gtk/gtk_theme_service.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "grit/theme_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/skia_utils_gtk.h" @@ -28,7 +27,6 @@ class GtkThemeServiceTest : public testing::Test { } protected: - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; GtkThemeService* provider_; diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc index a1c98f2..c7f7859 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk_unittest.cc @@ -11,7 +11,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" +#include "content/public/test/test_browser_thread.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/platform_test.h" #include "ui/base/gtk/gtk_hig_constants.h" @@ -42,9 +42,11 @@ class OmniboxEditControllerMock : public OmniboxEditController { class OmniboxViewGtkTest : public PlatformTest { public: + OmniboxViewGtkTest() : file_thread_(content::BrowserThread::UI) {} + virtual void SetUp() { PlatformTest::SetUp(); - profile_.reset(new TestingProfile()); + profile_.reset(new TestingProfile); window_ = gtk_window_new(GTK_WINDOW_POPUP); controller_.reset(new OmniboxEditControllerMock); view_.reset(new OmniboxViewGtk(controller_.get(), NULL, profile_.get(), @@ -62,12 +64,15 @@ class OmniboxViewGtkTest : public PlatformTest { view_->paste_clipboard_requested_ = b; } - content::TestBrowserThreadBundle thread_bundle_; scoped_ptr<OmniboxEditControllerMock> controller_; scoped_ptr<TestingProfile> profile_; GtkTextBuffer* text_buffer_; scoped_ptr<OmniboxViewGtk> view_; GtkWidget* window_; + content::TestBrowserThread file_thread_; + + private: + DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtkTest); }; TEST_F(OmniboxViewGtkTest, InsertText) { diff --git a/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc b/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc index 65b0a33..4c855c3 100644 --- a/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc +++ b/chrome/browser/ui/omnibox/omnibox_controller_unittest.cc @@ -9,7 +9,6 @@ #include "chrome/browser/ui/omnibox/omnibox_controller.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" class OmniboxControllerTest : public testing::Test { @@ -26,7 +25,6 @@ class OmniboxControllerTest : public testing::Test { } private: - content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; scoped_ptr<OmniboxController> omnibox_controller_; diff --git a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc index 83ac9bb..4dd7d09 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_unittest.cc @@ -11,7 +11,6 @@ #include "chrome/browser/ui/toolbar/test_toolbar_model.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image.h" @@ -182,7 +181,6 @@ TEST_F(AutocompleteEditTest, AdjustTextForCopy) { }; TestingOmniboxEditController controller(toolbar_model()); TestingOmniboxView view(&controller); - content::TestBrowserThreadBundle thread_bundle; TestingProfile profile; // NOTE: The TemplateURLService must be created before the // AutocompleteClassifier so that the SearchProvider gets a non-NULL diff --git a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc index 3cebb63..a0b1d03 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc +++ b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc @@ -97,6 +97,10 @@ class TestProfileIOData : public ProfileIOData { content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE { NOTREACHED(); } + virtual void InitializeExtensionsRequestContext( + ProfileParams* profile_params) const OVERRIDE { + NOTREACHED(); + } virtual ChromeURLRequestContext* InitializeAppRequestContext( ChromeURLRequestContext* main_context, const StoragePartitionDescriptor& details, diff --git a/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc b/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc index 37fb546..57820cb 100644 --- a/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc +++ b/chrome/browser/ui/sync/one_click_signin_sync_starter_unittest.cc @@ -13,7 +13,6 @@ #include "chrome/browser/signin/signin_promo.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -29,6 +28,9 @@ class OneClickSigninSyncStarterTest : public testing::Test { // testing::Test: virtual void SetUp() OVERRIDE { + testing::Test::SetUp(); + profile_.reset(new TestingProfile()); + // Disable sync to simplify the creation of a OneClickSigninSyncStarter. CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); @@ -36,9 +38,9 @@ class OneClickSigninSyncStarterTest : public testing::Test { SigninManagerBase* signin_manager = static_cast<FakeSigninManager*>( SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( - &profile_, + profile_.get(), &OneClickSigninSyncStarterTest::BuildSigninManager)); - signin_manager->Initialize(&profile_, NULL); + signin_manager->Initialize(profile_.get(), NULL); signin_manager->SetAuthenticatedUsername(kTestingUsername); } @@ -52,7 +54,7 @@ class OneClickSigninSyncStarterTest : public testing::Test { protected: void CreateSyncStarter(OneClickSigninSyncStarter::Callback callback) { sync_starter_ = new OneClickSigninSyncStarter( - &profile_, + profile_.get(), NULL, std::string(), kTestingUsername, @@ -65,8 +67,7 @@ class OneClickSigninSyncStarterTest : public testing::Test { ); } - content::TestBrowserThreadBundle thread_bundle_; - TestingProfile profile_; + scoped_ptr<TestingProfile> profile_; // Deletes itself when SigninFailed() or SigninSuccess() is called. OneClickSigninSyncStarter* sync_starter_; diff --git a/chrome/browser/ui/sync/sync_promo_ui_unittest.cc b/chrome/browser/ui/sync/sync_promo_ui_unittest.cc index 20aa029..1a9d8d6 100644 --- a/chrome/browser/ui/sync/sync_promo_ui_unittest.cc +++ b/chrome/browser/ui/sync/sync_promo_ui_unittest.cc @@ -12,18 +12,26 @@ #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" class SyncPromoUITest : public testing::Test { + public: + SyncPromoUITest() {} + + // testing::Test: + virtual void SetUp() OVERRIDE { + testing::Test::SetUp(); + profile_.reset(new TestingProfile()); + } + protected: void CreateSigninManager(const std::string& username) { SigninManagerBase* signin_manager = static_cast<FakeSigninManagerBase*>( SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( - &profile_, + profile_.get(), &FakeSigninManagerBase::Build)); - signin_manager->Initialize(&profile_, NULL); + signin_manager->Initialize(profile_.get(), NULL); if (!username.empty()) { ASSERT_TRUE(signin_manager); @@ -35,8 +43,10 @@ class SyncPromoUITest : public testing::Test { CommandLine::ForCurrentProcess()->AppendSwitch(switches::kDisableSync); } - content::TestBrowserThreadBundle thread_bundle_; - TestingProfile profile_; + scoped_ptr<TestingProfile> profile_; + + private: + DISALLOW_COPY_AND_ASSIGN(SyncPromoUITest); }; // Verifies that ShouldShowSyncPromo returns false if sync is disabled by @@ -44,7 +54,7 @@ class SyncPromoUITest : public testing::Test { TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncDisabled) { CreateSigninManager(""); DisableSync(); - EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(&profile_)); + EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(profile_.get())); } // Verifies that ShouldShowSyncPromo returns true if all conditions to @@ -53,8 +63,8 @@ TEST_F(SyncPromoUITest, ShouldShowSyncPromoSyncEnabled) { CreateSigninManager(""); #if defined(OS_CHROMEOS) // No sync promo on CrOS. - EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(&profile_)); + EXPECT_FALSE(SyncPromoUI::ShouldShowSyncPromo(profile_.get())); #else - EXPECT_TRUE(SyncPromoUI::ShouldShowSyncPromo(&profile_)); + EXPECT_TRUE(SyncPromoUI::ShouldShowSyncPromo(profile_.get())); #endif } diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc index 4c7dd2d..62715e8 100644 --- a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc +++ b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc @@ -682,6 +682,7 @@ void NetInternalsMessageHandler::RegisterMessages() { proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), profile->GetRequestContext()); proxy_->AddRequestContextGetter(profile->GetMediaRequestContext()); + proxy_->AddRequestContextGetter(profile->GetRequestContextForExtensions()); #if defined(OS_CHROMEOS) syslogs_getter_.reset(new SystemLogsGetter(this, chromeos::system::SyslogsProvider::GetInstance())); diff --git a/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc b/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc index 69a79cb..9b749a8 100644 --- a/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc +++ b/chrome/browser/ui/webui/ntp/suggestions_combiner_unittest.cc @@ -15,7 +15,6 @@ #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" #include "chrome/browser/ui/webui/ntp/suggestions_source.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -208,23 +207,34 @@ class SuggestionsSourceStub : public SuggestionsSource { }; class SuggestionsCombinerTest : public testing::Test { + public: + SuggestionsCombinerTest() { + } + protected: + Profile* profile_; + SuggestionsHandler* suggestions_handler_; + SuggestionsCombiner* combiner_; + + void Reset() { + delete combiner_; + combiner_ = new SuggestionsCombiner(suggestions_handler_, profile_); + } + + private: virtual void SetUp() { - thread_bundle_.reset(new content::TestBrowserThreadBundle()); - profile_.reset(new TestingProfile()); - suggestions_handler_.reset(new SuggestionsHandler()); - Reset(); + profile_ = new TestingProfile(); + suggestions_handler_ = new SuggestionsHandler(); + combiner_ = new SuggestionsCombiner(suggestions_handler_, profile_); } - void Reset() { - combiner_.reset( - new SuggestionsCombiner(suggestions_handler_.get(), profile_.get())); + virtual void TearDown() { + delete combiner_; + delete suggestions_handler_; + delete profile_; } - scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; - scoped_ptr<Profile> profile_; - scoped_ptr<SuggestionsHandler> suggestions_handler_; - scoped_ptr<SuggestionsCombiner> combiner_; + DISALLOW_COPY_AND_ASSIGN(SuggestionsCombinerTest); }; TEST_F(SuggestionsCombinerTest, NoSource) { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1a68e39..c3f2552 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1148,8 +1148,6 @@ 'browser/net/connect_interceptor.h', 'browser/net/connection_tester.cc', 'browser/net/connection_tester.h', - 'browser/net/cookie_store_util.cc', - 'browser/net/cookie_store_util.h', 'browser/net/crl_set_fetcher.cc', 'browser/net/crl_set_fetcher.h', 'browser/net/dns_probe_runner.cc', diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc index bec4e02..3dd5bd3 100644 --- a/chrome/common/chrome_constants.cc +++ b/chrome/common/chrome_constants.cc @@ -153,6 +153,7 @@ const base::FilePath::CharType kArchivedHistoryFilename[] = FPL("Archived History"); const base::FilePath::CharType kBookmarksFileName[] = FPL("Bookmarks"); const base::FilePath::CharType kCacheDirname[] = FPL("Cache"); +const base::FilePath::CharType kCookieFilename[] = FPL("Cookies"); const base::FilePath::CharType kCRLSetFilename[] = FPL("Certificate Revocation Lists"); const base::FilePath::CharType kCustomDictionaryFileName[] = diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h index 051e917..1691e56 100644 --- a/chrome/common/chrome_constants.h +++ b/chrome/common/chrome_constants.h @@ -54,6 +54,7 @@ extern const base::FilePath::CharType kAndroidCacheFilename[]; extern const base::FilePath::CharType kArchivedHistoryFilename[]; extern const base::FilePath::CharType kBookmarksFileName[]; extern const base::FilePath::CharType kCacheDirname[]; +extern const base::FilePath::CharType kCookieFilename[]; extern const base::FilePath::CharType kCRLSetFilename[]; extern const base::FilePath::CharType kCustomDictionaryFileName[]; extern const base::FilePath::CharType kExtensionActivityLogFilename[]; diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 96efa80..c604b6c 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -583,6 +583,10 @@ const char kExtensionsInActionBox[] = "extensions-in-action-box"; // 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 0850299..7bd5c7b 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -171,6 +171,7 @@ extern const char kEnableDnsProbes[]; 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 kEnableInstantExtendedAPI[]; diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 587f430..f53c423 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -37,7 +37,6 @@ #include "chrome/browser/history/shortcuts_backend_factory.h" #include "chrome/browser/history/top_sites.h" #include "chrome/browser/history/web_history_service_factory.h" -#include "chrome/browser/net/cookie_store_util.h" #include "chrome/browser/net/pref_proxy_config_tracker.h" #include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/notifications/desktop_notification_service.h" @@ -63,7 +62,6 @@ #include "components/browser_context_keyed_service/browser_context_dependency_manager.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" @@ -113,6 +111,38 @@ class QuittingHistoryDBTask : public history::HistoryDBTask { DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask); }; +class TestExtensionURLRequestContext : public net::URLRequestContext { + public: + TestExtensionURLRequestContext() { + net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL); + const char* schemes[] = {extensions::kExtensionScheme}; + cookie_monster->SetCookieableSchemes(schemes, 1); + set_cookie_store(cookie_monster); + } + + virtual ~TestExtensionURLRequestContext() {} +}; + +class TestExtensionURLRequestContextGetter + : public net::URLRequestContextGetter { + public: + virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { + if (!context_.get()) + context_.reset(new TestExtensionURLRequestContext()); + return context_.get(); + } + virtual scoped_refptr<base::SingleThreadTaskRunner> + GetNetworkTaskRunner() const OVERRIDE { + return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); + } + + protected: + virtual ~TestExtensionURLRequestContextGetter() {} + + private: + scoped_ptr<net::URLRequestContext> context_; +}; + BrowserContextKeyedService* CreateTestDesktopNotificationService( content::BrowserContext* profile) { #if defined(ENABLE_NOTIFICATIONS) @@ -562,6 +592,13 @@ TestingProfile::GetExtensionSpecialStoragePolicy() { return extension_special_storage_policy_.get(); } +net::CookieMonster* TestingProfile::GetCookieMonster() { + if (!GetRequestContext()) + return NULL; + return GetRequestContext()->GetURLRequestContext()->cookie_store()-> + GetCookieMonster(); +} + void TestingProfile::CreateTestingPrefService() { DCHECK(!prefs_.get()); testing_prefs_ = new TestingPrefServiceSyncable(); @@ -606,18 +643,6 @@ DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() { return NULL; } -void TestingProfile::OverrideCookieStoreConfigs( - const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - CookieSchemeMap* configs) { - // Force this to be in-memory. - chrome_browser_net::SetCookieStoreConfigs( - base::FilePath(), true, is_default_partition, - content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - GetSpecialStoragePolicy(), NULL, configs); -} - net::URLRequestContextGetter* TestingProfile::GetRequestContext() { return GetDefaultStoragePartition(this)->GetURLRequestContext(); } @@ -661,6 +686,12 @@ void TestingProfile::RequestMIDISysExPermission( callback.Run(false); } +net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() { + if (!extensions_request_context_.get()) + extensions_request_context_ = new TestExtensionURLRequestContextGetter(); + return extensions_request_context_.get(); +} + net::SSLConfigService* TestingProfile::GetSSLConfigService() { if (!GetRequestContext()) return NULL; diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index 0d162fb..03c95d4 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -192,10 +192,6 @@ class TestingProfile : public Profile { virtual bool IsOffTheRecord() const OVERRIDE; virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; - virtual void OverrideCookieStoreConfigs(const base::FilePath& partition_path, - bool in_memory_partition, - bool is_default_partition, - CookieSchemeMap* configs) OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; @@ -239,6 +235,10 @@ class TestingProfile : public Profile { ExtensionSpecialStoragePolicy* extension_special_storage_policy); virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() OVERRIDE; + // TODO(ajwong): Remove this API in favor of directly retrieving the + // CookieStore from the StoragePartition after ExtensionURLRequestContext + // has been removed. + net::CookieMonster* GetCookieMonster(); virtual PrefService* GetPrefs() OVERRIDE; @@ -249,6 +249,8 @@ class TestingProfile : public Profile { virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( int renderer_child_id) OVERRIDE; virtual net::URLRequestContextGetter* + GetRequestContextForExtensions() OVERRIDE; + virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory) OVERRIDE; |