diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 18b5fd855e25..465cbce43904 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -4,15 +4,19 @@ #include "browser/browser_client.h" +#include "base/path_service.h" #include "browser/browser_context.h" #include "browser/browser_main_parts.h" #include "browser/devtools_manager_delegate.h" #include "browser/media/media_capture_devices_dispatcher.h" -#include "browser/platform_notification_service_impl.h" - -#include "base/path_service.h" +#include "browser/notification_presenter.h" +#include "browser/platform_notification_service.h" #include "content/public/common/url_constants.h" +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + namespace brightray { namespace { @@ -38,6 +42,20 @@ BrowserContext* BrowserClient::browser_context() { return browser_main_parts_->browser_context(); } +NotificationPresenter* BrowserClient::GetNotificationPresenter() { + #if defined(OS_WIN) + // Bail out if on Windows 7 or even lower, no operating will follow + if (base::win::GetVersion() < base::win::VERSION_WIN8) + return nullptr; + #endif + + if (!notification_presenter_) { + // Create a new presenter if on OS X, Linux, or Windows 8+ + notification_presenter_.reset(NotificationPresenter::Create()); + } + return notification_presenter_.get(); +} + BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts( const content::MainFunctionParams&) { return new BrowserMainParts; @@ -65,7 +83,9 @@ content::MediaObserver* BrowserClient::GetMediaObserver() { } content::PlatformNotificationService* BrowserClient::GetPlatformNotificationService() { - return PlatformNotificationServiceImpl::GetInstance(); + if (!notification_service_) + notification_service_.reset(new PlatformNotificationService(this)); + return notification_service_.get(); } void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 0612e56d2552..bb6575c9b2b6 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -13,6 +13,8 @@ namespace brightray { class BrowserContext; class BrowserMainParts; class NetLog; +class NotificationPresenter; +class PlatformNotificationService; class BrowserClient : public content::ContentBrowserClient { public: @@ -24,6 +26,8 @@ class BrowserClient : public content::ContentBrowserClient { BrowserContext* browser_context(); BrowserMainParts* browser_main_parts() { return browser_main_parts_; } + NotificationPresenter* GetNotificationPresenter(); + protected: // Subclasses should override this to provide their own BrowserMainParts // implementation. The lifetime of the returned instance is managed by the @@ -51,6 +55,9 @@ class BrowserClient : public content::ContentBrowserClient { NetLog net_log_; private: + scoped_ptr notification_service_; + scoped_ptr notification_presenter_; + DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service.cc similarity index 50% rename from brightray/browser/platform_notification_service_impl.cc rename to brightray/browser/platform_notification_service.cc index 98c41b3bae19..a480771e8c8a 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service.cc @@ -2,68 +2,48 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "browser/platform_notification_service_impl.h" +#include "browser/platform_notification_service.h" +#include "browser/browser_client.h" #include "browser/notification_presenter.h" - #include "content/public/browser/desktop_notification_delegate.h" -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#endif - namespace brightray { -// static -PlatformNotificationServiceImpl* -PlatformNotificationServiceImpl::GetInstance() { - return base::Singleton::get(); +PlatformNotificationService::PlatformNotificationService( + BrowserClient* browser_client) + : browser_client_(browser_client) { } -PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} -PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} +PlatformNotificationService::~PlatformNotificationService() {} -NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() { - #if defined(OS_WIN) - // Bail out if on Windows 7 or even lower, no operating will follow - if (base::win::GetVersion() < base::win::VERSION_WIN8) - return nullptr; - #endif - - if (!notification_presenter_) { - // Create a new presenter if on OS X, Linux, or Windows 8+ - notification_presenter_.reset(NotificationPresenter::Create()); - } - return notification_presenter_.get(); -} - -blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnUIThread( +blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnUIThread( content::BrowserContext* browser_context, const GURL& origin, int render_process_id) { return blink::WebNotificationPermissionAllowed; } -blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnIOThread( +blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnIOThread( content::ResourceContext* resource_context, const GURL& origin, int render_process_id) { return blink::WebNotificationPermissionAllowed; } -void PlatformNotificationServiceImpl::DisplayNotification( +void PlatformNotificationService::DisplayNotification( content::BrowserContext* browser_context, const GURL& origin, const SkBitmap& icon, const content::PlatformNotificationData& notification_data, scoped_ptr delegate, base::Closure* cancel_callback) { - auto presenter = notification_presenter(); + auto presenter = browser_client_->GetNotificationPresenter(); if (presenter) presenter->ShowNotification(notification_data, icon, delegate.Pass(), cancel_callback); } -void PlatformNotificationServiceImpl::DisplayPersistentNotification( +void PlatformNotificationService::DisplayPersistentNotification( content::BrowserContext* browser_context, int64_t service_worker_registration_id, const GURL& origin, @@ -71,12 +51,12 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( const content::PlatformNotificationData& notification_data) { } -void PlatformNotificationServiceImpl::ClosePersistentNotification( +void PlatformNotificationService::ClosePersistentNotification( content::BrowserContext* browser_context, int64_t persistent_notification_id) { } -bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( +bool PlatformNotificationService::GetDisplayedPersistentNotifications( content::BrowserContext* browser_context, std::set* displayed_notifications) { return false; diff --git a/brightray/browser/platform_notification_service_impl.h b/brightray/browser/platform_notification_service.h similarity index 67% rename from brightray/browser/platform_notification_service_impl.h rename to brightray/browser/platform_notification_service.h index 9b657d5395e0..0c598965df4e 100644 --- a/brightray/browser/platform_notification_service_impl.h +++ b/brightray/browser/platform_notification_service.h @@ -2,31 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ -#define BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ +#ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ +#define BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ -#include "base/memory/singleton.h" #include "content/public/browser/platform_notification_service.h" namespace brightray { -class NotificationPresenter; +class BrowserClient; -class PlatformNotificationServiceImpl +class PlatformNotificationService : public content::PlatformNotificationService { public: - // Returns the active instance of the service in the browser process. Safe to - // be called from any thread. - static PlatformNotificationServiceImpl* GetInstance(); - - NotificationPresenter* notification_presenter(); - - private: - friend struct base::DefaultSingletonTraits; - - PlatformNotificationServiceImpl(); - ~PlatformNotificationServiceImpl() override; + explicit PlatformNotificationService(BrowserClient* browser_client); + ~PlatformNotificationService() override; + protected: // content::PlatformNotificationService: blink::WebNotificationPermission CheckPermissionOnUIThread( content::BrowserContext* browser_context, @@ -56,11 +47,12 @@ class PlatformNotificationServiceImpl content::BrowserContext* browser_context, std::set* displayed_notifications) override; - scoped_ptr notification_presenter_; + private: + BrowserClient* browser_client_; - DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); + DISALLOW_COPY_AND_ASSIGN(PlatformNotificationService); }; } // namespace brightray -#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ +#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index e8d3b1800917..1e4868b79224 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -64,8 +64,8 @@ 'browser/notification.h', 'browser/permission_manager.cc', 'browser/permission_manager.h', - 'browser/platform_notification_service_impl.cc', - 'browser/platform_notification_service_impl.h', + 'browser/platform_notification_service.cc', + 'browser/platform_notification_service.h', 'browser/linux/libnotify_loader.h', 'browser/linux/libnotify_loader.cc', 'browser/linux/notification_presenter_linux.h',