diff options
| author | jkarlin <jkarlin@chromium.org> | 2015-10-06 08:13:35 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2015-10-06 15:14:39 +0000 |
| commit | 6f5078ed47fa34af63cec4139db3347bcb74ecb4 (patch) | |
| tree | 55a05742fe85dff9300f051f8448483148993b12 | |
| parent | 75a0abfba2569e38b0d8cd6bfd6a7f135d2fffe2 (diff) | |
| download | chromium_src-6f5078ed47fa34af63cec4139db3347bcb74ecb4.zip chromium_src-6f5078ed47fa34af63cec4139db3347bcb74ecb4.tar.gz chromium_src-6f5078ed47fa34af63cec4139db3347bcb74ecb4.tar.bz2 | |
[BackgroundSync] Add BackgroundSyncController to Chrome
The new BackgroundSyncController allows content::BackgroundSyncManager to access Chrome features like Rappor and, in a followup CL, the BackgroundSyncLauncher.
BUG=538640
Review URL: https://codereview.chromium.org/1369823003
Cr-Commit-Position: refs/heads/master@{#352605}
33 files changed, 355 insertions, 0 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 713b308..1591078 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -410,6 +410,11 @@ content::PermissionManager* AwBrowserContext::GetPermissionManager() { return permission_manager_.get(); } +content::BackgroundSyncController* +AwBrowserContext::GetBackgroundSyncController() { + return nullptr; +} + policy::URLBlacklistManager* AwBrowserContext::GetURLBlacklistManager() { // Should not be called until the end of PreMainMessageLoopRun, where // blacklist_manager_ is initialized. diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h index 053ed6a..9028da0 100644 --- a/android_webview/browser/aw_browser_context.h +++ b/android_webview/browser/aw_browser_context.h @@ -128,6 +128,7 @@ class AwBrowserContext : public content::BrowserContext, content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; // visitedlink::VisitedLinkDelegate implementation. void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; diff --git a/chrome/browser/background_sync/OWNERS b/chrome/browser/background_sync/OWNERS new file mode 100644 index 0000000..1e6deee --- /dev/null +++ b/chrome/browser/background_sync/OWNERS @@ -0,0 +1 @@ +jkarlin@chromium.org diff --git a/chrome/browser/background_sync/PRESUBMIT.py b/chrome/browser/background_sync/PRESUBMIT.py new file mode 100644 index 0000000..7df0d54 --- /dev/null +++ b/chrome/browser/background_sync/PRESUBMIT.py @@ -0,0 +1,12 @@ +# Copyright 2015 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. + +"""Top-level presubmit script for src/chrome/browser/background_sync/ + +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts +for more details about the presubmit API built into depot_tools. +""" + +def CheckChangeOnUpload(input_api, output_api): + return input_api.canned_checks.CheckPatchFormatted(input_api, output_api) diff --git a/chrome/browser/background_sync/background_sync_controller_factory.cc b/chrome/browser/background_sync/background_sync_controller_factory.cc new file mode 100644 index 0000000..aefa72b --- /dev/null +++ b/chrome/browser/background_sync/background_sync_controller_factory.cc @@ -0,0 +1,41 @@ +// Copyright 2015 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 "background_sync_controller_factory.h" + +#include "chrome/browser/background_sync/background_sync_controller_impl.h" +#include "chrome/browser/profiles/incognito_helpers.h" +#include "chrome/browser/profiles/profile.h" +#include "components/keyed_service/content/browser_context_dependency_manager.h" + +// static +BackgroundSyncControllerImpl* BackgroundSyncControllerFactory::GetForProfile( + Profile* profile) { + return static_cast<BackgroundSyncControllerImpl*>( + GetInstance()->GetServiceForBrowserContext(profile, true)); +} + +// static +BackgroundSyncControllerFactory* +BackgroundSyncControllerFactory::GetInstance() { + return base::Singleton<BackgroundSyncControllerFactory>::get(); +} + +BackgroundSyncControllerFactory::BackgroundSyncControllerFactory() + : BrowserContextKeyedServiceFactory( + "BackgroundSyncService", + BrowserContextDependencyManager::GetInstance()) {} + +BackgroundSyncControllerFactory::~BackgroundSyncControllerFactory() {} + +KeyedService* BackgroundSyncControllerFactory::BuildServiceInstanceFor( + content::BrowserContext* context) const { + return new BackgroundSyncControllerImpl(Profile::FromBrowserContext(context)); +} + +content::BrowserContext* +BackgroundSyncControllerFactory::GetBrowserContextToUse( + content::BrowserContext* context) const { + return chrome::GetBrowserContextOwnInstanceInIncognito(context); +} diff --git a/chrome/browser/background_sync/background_sync_controller_factory.h b/chrome/browser/background_sync/background_sync_controller_factory.h new file mode 100644 index 0000000..b93dbe9 --- /dev/null +++ b/chrome/browser/background_sync/background_sync_controller_factory.h @@ -0,0 +1,35 @@ +// Copyright 2015 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_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_FACTORY_H_ +#define CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_FACTORY_H_ + +#include "base/memory/singleton.h" +#include "components/keyed_service/content/browser_context_keyed_service_factory.h" + +class BackgroundSyncControllerImpl; +class Profile; + +class BackgroundSyncControllerFactory + : public BrowserContextKeyedServiceFactory { + public: + static BackgroundSyncControllerImpl* GetForProfile(Profile* profile); + static BackgroundSyncControllerFactory* GetInstance(); + + private: + friend struct base::DefaultSingletonTraits<BackgroundSyncControllerFactory>; + + BackgroundSyncControllerFactory(); + ~BackgroundSyncControllerFactory() override; + + // BrowserContextKeyedBaseFactory methods: + KeyedService* BuildServiceInstanceFor( + content::BrowserContext* context) const override; + content::BrowserContext* GetBrowserContextToUse( + content::BrowserContext* context) const override; + + DISALLOW_COPY_AND_ASSIGN(BackgroundSyncControllerFactory); +}; + +#endif // CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_FACTORY_H_ diff --git a/chrome/browser/background_sync/background_sync_controller_impl.cc b/chrome/browser/background_sync/background_sync_controller_impl.cc new file mode 100644 index 0000000..7668229 --- /dev/null +++ b/chrome/browser/background_sync/background_sync_controller_impl.cc @@ -0,0 +1,30 @@ +// Copyright 2015 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/background_sync/background_sync_controller_impl.h" + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/profiles/profile.h" +#include "components/rappor/rappor_utils.h" + +BackgroundSyncControllerImpl::BackgroundSyncControllerImpl(Profile* profile) + : profile_(profile) {} + +BackgroundSyncControllerImpl::~BackgroundSyncControllerImpl() = default; + +rappor::RapporService* BackgroundSyncControllerImpl::GetRapporService() { + return g_browser_process->rappor_service(); +} + +void BackgroundSyncControllerImpl::NotifyBackgroundSyncRegistered( + const GURL& origin) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK_EQ(origin, origin.GetOrigin()); + + if (profile_->IsOffTheRecord()) + return; + + rappor::SampleDomainAndRegistryFromGURL( + GetRapporService(), "BackgroundSync.Register.Origin", origin); +} diff --git a/chrome/browser/background_sync/background_sync_controller_impl.h b/chrome/browser/background_sync/background_sync_controller_impl.h new file mode 100644 index 0000000..156a6244 --- /dev/null +++ b/chrome/browser/background_sync/background_sync_controller_impl.h @@ -0,0 +1,38 @@ +// Copyright 2015 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_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_IMPL_H_ +#define CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_IMPL_H_ + +#include "content/public/browser/background_sync_controller.h" + +#include "components/keyed_service/core/keyed_service.h" +#include "content/public/browser/browser_thread.h" + +namespace rappor { +class RapporService; +} + +class Profile; + +class BackgroundSyncControllerImpl : public content::BackgroundSyncController, + public KeyedService { + public: + explicit BackgroundSyncControllerImpl(Profile* profile); + ~BackgroundSyncControllerImpl() override; + + // content::BackgroundSyncController overrides. + void NotifyBackgroundSyncRegistered(const GURL& origin) override; + + protected: + // Virtual for testing. + virtual rappor::RapporService* GetRapporService(); + + private: + Profile* profile_; // This object is owned by profile_. + + DISALLOW_COPY_AND_ASSIGN(BackgroundSyncControllerImpl); +}; + +#endif // CHROME_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_CONTROLLER_IMPL_H_ diff --git a/chrome/browser/background_sync/background_sync_controller_impl_unittest.cc b/chrome/browser/background_sync/background_sync_controller_impl_unittest.cc new file mode 100644 index 0000000..1e20813 --- /dev/null +++ b/chrome/browser/background_sync/background_sync_controller_impl_unittest.cc @@ -0,0 +1,70 @@ +// Copyright 2015 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/background_sync/background_sync_controller_impl.h" + +#include "chrome/test/base/testing_profile.h" +#include "components/rappor/test_rappor_service.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace { + +class TestBackgroundSyncControllerImpl : public BackgroundSyncControllerImpl { + public: + TestBackgroundSyncControllerImpl(Profile* profile, + rappor::TestRapporService* rappor_service) + : BackgroundSyncControllerImpl(profile), + rappor_service_(rappor_service) {} + + protected: + rappor::RapporService* GetRapporService() override { return rappor_service_; } + + private: + rappor::TestRapporService* rappor_service_; + + DISALLOW_COPY_AND_ASSIGN(TestBackgroundSyncControllerImpl); +}; + +class BackgroundSyncControllerImplTest : public testing::Test { + protected: + BackgroundSyncControllerImplTest() + : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), + controller_(new TestBackgroundSyncControllerImpl(&profile_, + &rappor_service_)) {} + + content::TestBrowserThreadBundle thread_bundle_; + TestingProfile profile_; + rappor::TestRapporService rappor_service_; + scoped_ptr<TestBackgroundSyncControllerImpl> controller_; + + DISALLOW_COPY_AND_ASSIGN(BackgroundSyncControllerImplTest); +}; + +TEST_F(BackgroundSyncControllerImplTest, RapporTest) { + GURL url("http://www.example.com/foo/"); + EXPECT_EQ(0, rappor_service_.GetReportsCount()); + controller_->NotifyBackgroundSyncRegistered(url.GetOrigin()); + EXPECT_EQ(1, rappor_service_.GetReportsCount()); + + std::string sample; + rappor::RapporType type; + LOG(ERROR) << url.GetOrigin().GetOrigin(); + EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric( + "BackgroundSync.Register.Origin", &sample, &type)); + EXPECT_EQ("example.com", sample); + EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); +} + +TEST_F(BackgroundSyncControllerImplTest, NoRapporWhenOffTheRecord) { + GURL url("http://www.example.com/foo/"); + controller_.reset(new TestBackgroundSyncControllerImpl( + profile_.GetOffTheRecordProfile(), &rappor_service_)); + + controller_->NotifyBackgroundSyncRegistered(url.GetOrigin()); + EXPECT_EQ(0, rappor_service_.GetReportsCount()); +} + +} // namespace diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index 3560021..0cb75f4 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -14,6 +14,8 @@ #include "base/strings/string_util.h" #include "build/build_config.h" #include "chrome/browser/background/background_contents_service_factory.h" +#include "chrome/browser/background_sync/background_sync_controller_factory.h" +#include "chrome/browser/background_sync/background_sync_controller_impl.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/dom_distiller/profile_utils.h" @@ -408,6 +410,11 @@ content::PermissionManager* OffTheRecordProfileImpl::GetPermissionManager() { return PermissionManagerFactory::GetForProfile(this); } +content::BackgroundSyncController* +OffTheRecordProfileImpl::GetBackgroundSyncController() { + return BackgroundSyncControllerFactory::GetForProfile(this); +} + bool OffTheRecordProfileImpl::IsSameProfile(Profile* profile) { return (profile == this) || (profile == profile_); } diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index 54b9224..17e2a0c 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -106,6 +106,7 @@ class OffTheRecordProfileImpl : public Profile { content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; private: void InitIoData(); diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 5c8bc99..5c659b6 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -29,6 +29,8 @@ #include "base/trace_event/trace_event.h" #include "base/version.h" #include "chrome/browser/background/background_contents_service_factory.h" +#include "chrome/browser/background_sync/background_sync_controller_factory.h" +#include "chrome/browser/background_sync/background_sync_controller_impl.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" @@ -1024,6 +1026,10 @@ content::PermissionManager* ProfileImpl::GetPermissionManager() { return PermissionManagerFactory::GetForProfile(this); } +content::BackgroundSyncController* ProfileImpl::GetBackgroundSyncController() { + return BackgroundSyncControllerFactory::GetForProfile(this); +} + bool ProfileImpl::IsSameProfile(Profile* profile) { if (profile == static_cast<Profile*>(this)) return true; diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 89b98ab..b53f6f6 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -93,6 +93,7 @@ class ProfileImpl : public Profile { content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; // Profile implementation: scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override; diff --git a/chrome/browser/ui/app_list/test/fake_profile.cc b/chrome/browser/ui/app_list/test/fake_profile.cc index 8ea04ec..8a8108a 100644 --- a/chrome/browser/ui/app_list/test/fake_profile.cc +++ b/chrome/browser/ui/app_list/test/fake_profile.cc @@ -84,6 +84,10 @@ content::PermissionManager* FakeProfile::GetPermissionManager() { return nullptr; } +content::BackgroundSyncController* FakeProfile::GetBackgroundSyncController() { + return nullptr; +} + scoped_refptr<base::SequencedTaskRunner> FakeProfile::GetIOTaskRunner() { return scoped_refptr<base::SequencedTaskRunner>(); diff --git a/chrome/browser/ui/app_list/test/fake_profile.h b/chrome/browser/ui/app_list/test/fake_profile.h index ce56c3d..ad0dcac 100644 --- a/chrome/browser/ui/app_list/test/fake_profile.h +++ b/chrome/browser/ui/app_list/test/fake_profile.h @@ -52,6 +52,7 @@ class FakeProfile : public Profile { content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override; Profile* GetOffTheRecordProfile() override; void DestroyOffTheRecordProfile() override; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 54b9fe5..9e7b4f0 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -277,6 +277,10 @@ 'browser/autofill/risk_util.h', 'browser/autofill/validation_rules_storage_factory.cc', 'browser/autofill/validation_rules_storage_factory.h', + 'browser/background_sync/background_sync_controller_factory.cc', + 'browser/background_sync/background_sync_controller_factory.h', + 'browser/background_sync/background_sync_controller_impl.cc', + 'browser/background_sync/background_sync_controller_implh.h', 'browser/bad_message.cc', 'browser/bad_message.h', 'browser/banners/app_banner_data_fetcher.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index a116584..fe7aefb 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -37,6 +37,7 @@ 'browser/autocomplete/shortcuts_provider_unittest.cc', 'browser/autocomplete/zero_suggest_provider_unittest.cc', 'browser/autofill/autofill_cc_infobar_delegate_unittest.cc', + 'browser/background_sync/background_sync_controller_impl_unittest.cc', 'browser/banners/app_banner_data_fetcher_unittest.cc', 'browser/banners/app_banner_settings_helper_unittest.cc', 'browser/bitmap_fetcher/bitmap_fetcher_service_unittest.cc', diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 7b31c30..f196614 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -953,6 +953,11 @@ content::PermissionManager* TestingProfile::GetPermissionManager() { return NULL; } +content::BackgroundSyncController* +TestingProfile::GetBackgroundSyncController() { + return nullptr; +} + bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) { return true; } diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index 6663fa5..7c3eb34 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -227,6 +227,7 @@ class TestingProfile : public Profile { content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; TestingProfile* AsTestingProfile() override; diff --git a/chromecast/browser/cast_browser_context.cc b/chromecast/browser/cast_browser_context.cc index 51a9fc0..bdbd9e8 100644 --- a/chromecast/browser/cast_browser_context.cc +++ b/chromecast/browser/cast_browser_context.cc @@ -152,5 +152,10 @@ content::PermissionManager* CastBrowserContext::GetPermissionManager() { return permission_manager_.get(); } +content::BackgroundSyncController* +CastBrowserContext::GetBackgroundSyncController() { + return nullptr; +} + } // namespace shell } // namespace chromecast diff --git a/chromecast/browser/cast_browser_context.h b/chromecast/browser/cast_browser_context.h index ae0cf13..7d635f2 100644 --- a/chromecast/browser/cast_browser_context.h +++ b/chromecast/browser/cast_browser_context.h @@ -46,6 +46,7 @@ class CastBrowserContext : public content::BrowserContext { content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; net::URLRequestContextGetter* GetSystemRequestContext(); diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc index 9461de7..3560267 100644 --- a/content/browser/background_sync/background_sync_manager.cc +++ b/content/browser/background_sync/background_sync_manager.cc @@ -17,6 +17,9 @@ #include "content/browser/background_sync/background_sync_registration_options.h" #include "content/browser/service_worker/service_worker_context_wrapper.h" #include "content/browser/service_worker/service_worker_storage.h" +#include "content/browser/storage_partition_impl.h" +#include "content/public/browser/background_sync_controller.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #if defined(OS_ANDROID) @@ -59,6 +62,25 @@ bool ShouldDisableForFieldTrial() { base::CompareCase::INSENSITIVE_ASCII); } +void NotifyBackgroundSyncRegisteredOnUIThread( + const scoped_refptr<ServiceWorkerContextWrapper>& sw_context_wrapper, + const GURL& origin) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + StoragePartitionImpl* storage_partition_impl = + sw_context_wrapper->storage_partition(); + if (!storage_partition_impl) // happens in tests + return; + + BackgroundSyncController* background_sync_controller = + storage_partition_impl->browser_context()->GetBackgroundSyncController(); + + if (!background_sync_controller) + return; + + background_sync_controller->NotifyBackgroundSyncRegistered(origin); +} + } // namespace BackgroundSyncManager::BackgroundSyncRegistrations:: @@ -386,6 +408,11 @@ void BackgroundSyncManager::RegisterImpl( return; } + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + base::Bind(&NotifyBackgroundSyncRegisteredOnUIThread, + service_worker_context_, + sw_registration->pattern().GetOrigin())); + RefCountedRegistration* existing_registration_ref = LookupActiveRegistration(sw_registration_id, RegistrationKey(options)); if (existing_registration_ref) { diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc index d4f9233..36c074b 100644 --- a/content/browser/download/download_manager_impl_unittest.cc +++ b/content/browser/download/download_manager_impl_unittest.cc @@ -422,6 +422,7 @@ class MockBrowserContext : public BrowserContext { MOCK_METHOD0(GetPushMessagingService, PushMessagingService*()); MOCK_METHOD0(GetSSLHostStateDelegate, SSLHostStateDelegate*()); MOCK_METHOD0(GetPermissionManager, PermissionManager*()); + MOCK_METHOD0(GetBackgroundSyncController, BackgroundSyncController*()); scoped_ptr<ZoomLevelDelegate> CreateZoomLevelDelegate( const base::FilePath& path) override { diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 3ae9d56..0144b99 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -82,6 +82,7 @@ 'public/browser/ax_event_notification_details.cc', 'public/browser/ax_event_notification_details.h', 'public/browser/background_sync_context.h', + 'public/browser/background_sync_controller.h', 'public/browser/background_tracing_config.cc', 'public/browser/background_tracing_config.h', 'public/browser/background_tracing_manager.h', diff --git a/content/public/browser/background_sync_controller.h b/content/public/browser/background_sync_controller.h new file mode 100644 index 0000000..4b2ce63 --- /dev/null +++ b/content/public/browser/background_sync_controller.h @@ -0,0 +1,26 @@ +// Copyright 2015 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 CONTENT_PUBLIC_BROWSER_BACKGROUND_SYNC_CONTROLLER_H_ +#define CONTENT_PUBLIC_BROWSER_BACKGROUND_SYNC_CONTROLLER_H_ + +#include "content/common/content_export.h" +#include "url/gurl.h" + +namespace content { + +// An interface that the Background Sync API uses to access services from the +// embedder. Must only be used on the UI thread. +class CONTENT_EXPORT BackgroundSyncController { + public: + virtual ~BackgroundSyncController() {} + + // Notification that a service worker registration with origin |origin| just + // registered a background sync event. + virtual void NotifyBackgroundSyncRegistered(const GURL& origin) {} +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_SYNC_CONTROLLER_H_ diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index 1c17429..cff0985 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -34,6 +34,7 @@ class SpecialStoragePolicy; namespace content { +class BackgroundSyncController; class BlobHandle; class BrowserPluginGuestManager; class DownloadManager; @@ -189,6 +190,10 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { // Returns the PermissionManager associated with that context if any, nullptr // otherwise. virtual PermissionManager* GetPermissionManager() = 0; + + // Returns the BackgroundSyncController associated with that context if any, + // nullptr otherwise. + virtual BackgroundSyncController* GetBackgroundSyncController() = 0; }; } // namespace content diff --git a/content/public/test/test_browser_context.cc b/content/public/test/test_browser_context.cc index 06bb58a..dd038b6 100644 --- a/content/public/test/test_browser_context.cc +++ b/content/public/test/test_browser_context.cc @@ -134,4 +134,8 @@ PermissionManager* TestBrowserContext::GetPermissionManager() { return NULL; } +BackgroundSyncController* TestBrowserContext::GetBackgroundSyncController() { + return nullptr; +} + } // namespace content diff --git a/content/public/test/test_browser_context.h b/content/public/test/test_browser_context.h index 62fc750..e33de18 100644 --- a/content/public/test/test_browser_context.h +++ b/content/public/test/test_browser_context.h @@ -48,6 +48,7 @@ class TestBrowserContext : public BrowserContext { PushMessagingService* GetPushMessagingService() override; SSLHostStateDelegate* GetSSLHostStateDelegate() override; PermissionManager* GetPermissionManager() override; + BackgroundSyncController* GetBackgroundSyncController() override; private: scoped_refptr<net::URLRequestContextGetter> request_context_; diff --git a/content/shell/browser/layout_test/layout_test_browser_context.cc b/content/shell/browser/layout_test/layout_test_browser_context.cc index be19bb2..e81439b 100644 --- a/content/shell/browser/layout_test/layout_test_browser_context.cc +++ b/content/shell/browser/layout_test/layout_test_browser_context.cc @@ -75,6 +75,11 @@ PermissionManager* LayoutTestBrowserContext::GetPermissionManager() { return permission_manager_.get(); } +BackgroundSyncController* +LayoutTestBrowserContext::GetBackgroundSyncController() { + return nullptr; +} + LayoutTestPermissionManager* LayoutTestBrowserContext::GetLayoutTestPermissionManager() { return static_cast<LayoutTestPermissionManager*>(GetPermissionManager()); diff --git a/content/shell/browser/layout_test/layout_test_browser_context.h b/content/shell/browser/layout_test/layout_test_browser_context.h index 93fd10e..43e2699 100644 --- a/content/shell/browser/layout_test/layout_test_browser_context.h +++ b/content/shell/browser/layout_test/layout_test_browser_context.h @@ -14,6 +14,7 @@ class NetLog; namespace content { +class BackgroundSyncController; class DownloadManagerDelegate; class LayoutTestPermissionManager; class LayoutTestPushMessagingService; @@ -29,6 +30,7 @@ class LayoutTestBrowserContext : public ShellBrowserContext { DownloadManagerDelegate* GetDownloadManagerDelegate() override; PushMessagingService* GetPushMessagingService() override; PermissionManager* GetPermissionManager() override; + BackgroundSyncController* GetBackgroundSyncController() override; LayoutTestPermissionManager* GetLayoutTestPermissionManager(); diff --git a/content/shell/browser/shell_browser_context.cc b/content/shell/browser/shell_browser_context.cc index b81ae1c..273c832 100644 --- a/content/shell/browser/shell_browser_context.cc +++ b/content/shell/browser/shell_browser_context.cc @@ -206,4 +206,8 @@ PermissionManager* ShellBrowserContext::GetPermissionManager() { return permission_manager_.get(); } +BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() { + return nullptr; +} + } // namespace content diff --git a/content/shell/browser/shell_browser_context.h b/content/shell/browser/shell_browser_context.h index 07802ee..bf1be90 100644 --- a/content/shell/browser/shell_browser_context.h +++ b/content/shell/browser/shell_browser_context.h @@ -21,6 +21,7 @@ class NetLog; namespace content { +class BackgroundSyncController; class DownloadManagerDelegate; class PermissionManager; class ShellDownloadManagerDelegate; @@ -57,6 +58,7 @@ class ShellBrowserContext : public BrowserContext { PushMessagingService* GetPushMessagingService() override; SSLHostStateDelegate* GetSSLHostStateDelegate() override; PermissionManager* GetPermissionManager() override; + BackgroundSyncController* GetBackgroundSyncController() override; net::URLRequestContextGetter* CreateRequestContext( ProtocolHandlerMap* protocol_handlers, diff --git a/tools/metrics/rappor/rappor.xml b/tools/metrics/rappor/rappor.xml index 26d9a08..e8ce7fc 100644 --- a/tools/metrics/rappor/rappor.xml +++ b/tools/metrics/rappor/rappor.xml @@ -135,6 +135,13 @@ components/rappor/rappor_service.cc. </summary> </rappor-metric> +<rappor-metric name="BackgroundSync.Register.Origin" type="UMA_RAPPOR_TYPE"> + <owner>jkarlin@chromium.org</owner> + <summary> + The eTLD+1 of a URL which registered a Background Sync event. + </summary> +</rappor-metric> + <rappor-metric name="ContentSettings.MixedScript.DisplayedShield" type="ETLD_PLUS_ONE"> <owner>lgarron@chromium.org</owner> |
