Chromium Code Reviews| Index: content/browser/notifications/platform_notification_context_impl.cc |
| diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc |
| index 99c9591c1fbbb000f8fd7413b123dc777fc0743f..9151f893689fd27c9dec9cb7b11cad83d8af7b51 100644 |
| --- a/content/browser/notifications/platform_notification_context_impl.cc |
| +++ b/content/browser/notifications/platform_notification_context_impl.cc |
| @@ -6,10 +6,14 @@ |
| #include "base/bind_helpers.h" |
| #include "base/files/file_util.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/metrics/histogram_macros.h" |
| +#include "base/stl_util.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| +#include "content/browser/notifications/blink_notification_service_impl.h" |
| #include "content/browser/notifications/notification_database.h" |
| #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| +#include "content/public/browser/browser_context.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/notification_database_data.h" |
| @@ -30,7 +34,8 @@ PlatformNotificationContextImpl::PlatformNotificationContextImpl( |
| const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
| : path_(path), |
| browser_context_(browser_context), |
| - service_worker_context_(service_worker_context) { |
| + service_worker_context_(service_worker_context), |
| + weak_factory_to_io_(this) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| } |
| @@ -94,11 +99,46 @@ void PlatformNotificationContextImpl::Shutdown() { |
| void PlatformNotificationContextImpl::ShutdownOnIO() { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + services_.clear(); |
| + |
| // |service_worker_context_| may be NULL in tests. |
| if (service_worker_context_) |
| service_worker_context_->RemoveObserver(this); |
| } |
| +void PlatformNotificationContextImpl::CreateService( |
| + int render_process_id, |
| + mojo::InterfaceRequest<blink::mojom::NotificationService> request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&PlatformNotificationContextImpl::CreateServiceOnIO, |
| + weak_factory_to_io_.GetWeakPtr(), render_process_id, |
|
yzshen1
2016/05/18 15:28:56
Not sure whether it is relevant to the hang that y
|
| + browser_context_->GetResourceContext(), |
| + base::Passed(&request))); |
| +} |
| + |
| +void PlatformNotificationContextImpl::CreateServiceOnIO( |
| + int render_process_id, |
| + ResourceContext* resource_context, |
| + mojo::InterfaceRequest<blink::mojom::NotificationService> request) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + services_.push_back(base::WrapUnique(new BlinkNotificationServiceImpl( |
| + this, resource_context, render_process_id, std::move(request)))); |
| +} |
| + |
| +void PlatformNotificationContextImpl::RemoveService( |
| + BlinkNotificationServiceImpl* service) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + auto services_to_remove = std::remove_if( |
| + services_.begin(), services_.end(), |
| + [service](const std::unique_ptr<BlinkNotificationServiceImpl>& ptr) { |
| + return ptr.get() == service; |
| + }); |
| + |
| + services_.erase(services_to_remove, services_.end()); |
| +} |
| + |
| void PlatformNotificationContextImpl::ReadNotificationData( |
| int64_t notification_id, |
| const GURL& origin, |