Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/notifications/platform_notification_context_impl.h" | 5 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/stl_util.h" | |
| 10 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "content/browser/notifications/blink_notification_service_impl.h" | |
| 11 #include "content/browser/notifications/notification_database.h" | 13 #include "content/browser/notifications/notification_database.h" |
| 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 15 #include "content/public/browser/browser_context.h" | |
| 13 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 15 #include "content/public/browser/notification_database_data.h" | 18 #include "content/public/browser/notification_database_data.h" |
| 16 #include "content/public/browser/platform_notification_service.h" | 19 #include "content/public/browser/platform_notification_service.h" |
| 17 | 20 |
| 18 using base::DoNothing; | 21 using base::DoNothing; |
| 19 | 22 |
| 20 namespace content { | 23 namespace content { |
| 21 | 24 |
| 22 // Name of the directory in the user's profile directory where the notification | 25 // Name of the directory in the user's profile directory where the notification |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 void PlatformNotificationContextImpl::Shutdown() { | 90 void PlatformNotificationContextImpl::Shutdown() { |
| 88 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 91 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 89 BrowserThread::PostTask( | 92 BrowserThread::PostTask( |
| 90 BrowserThread::IO, FROM_HERE, | 93 BrowserThread::IO, FROM_HERE, |
| 91 base::Bind(&PlatformNotificationContextImpl::ShutdownOnIO, this)); | 94 base::Bind(&PlatformNotificationContextImpl::ShutdownOnIO, this)); |
| 92 } | 95 } |
| 93 | 96 |
| 94 void PlatformNotificationContextImpl::ShutdownOnIO() { | 97 void PlatformNotificationContextImpl::ShutdownOnIO() { |
| 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 96 | 99 |
| 100 STLDeleteElements(&services_); | |
| 101 | |
| 97 // |service_worker_context_| may be NULL in tests. | 102 // |service_worker_context_| may be NULL in tests. |
| 98 if (service_worker_context_) | 103 if (service_worker_context_) |
| 99 service_worker_context_->RemoveObserver(this); | 104 service_worker_context_->RemoveObserver(this); |
| 100 } | 105 } |
| 101 | 106 |
| 107 void PlatformNotificationContextImpl::CreateService( | |
| 108 int render_process_id, | |
| 109 mojo::InterfaceRequest<blink::mojom::NotificationService> request) { | |
| 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 111 BrowserThread::PostTask( | |
| 112 BrowserThread::IO, FROM_HERE, | |
| 113 base::Bind(&PlatformNotificationContextImpl::CreateServiceOnIO, this, | |
|
Michael van Ouwerkerk
2016/05/06 11:45:20
Should this use a weak ptr?
Peter Beverloo
2016/05/06 14:51:32
There's no need to keep the object alive for this,
| |
| 114 render_process_id, browser_context_->GetResourceContext(), | |
| 115 base::Passed(&request))); | |
| 116 } | |
| 117 | |
| 118 void PlatformNotificationContextImpl::CreateServiceOnIO( | |
| 119 int render_process_id, | |
| 120 ResourceContext* resource_context, | |
| 121 mojo::InterfaceRequest<blink::mojom::NotificationService> request) { | |
| 122 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 123 services_.insert(new BlinkNotificationServiceImpl( | |
| 124 this, resource_context, render_process_id, std::move(request))); | |
| 125 } | |
| 126 | |
| 127 void PlatformNotificationContextImpl::RemoveService( | |
| 128 BlinkNotificationServiceImpl* service) { | |
| 129 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 130 DCHECK(ContainsValue(services_, service)); | |
| 131 | |
| 132 services_.erase(service); | |
| 133 delete service; | |
| 134 } | |
| 135 | |
| 102 void PlatformNotificationContextImpl::ReadNotificationData( | 136 void PlatformNotificationContextImpl::ReadNotificationData( |
| 103 int64_t notification_id, | 137 int64_t notification_id, |
| 104 const GURL& origin, | 138 const GURL& origin, |
| 105 const ReadResultCallback& callback) { | 139 const ReadResultCallback& callback) { |
| 106 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 140 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 107 LazyInitialize( | 141 LazyInitialize( |
| 108 base::Bind(&PlatformNotificationContextImpl::DoReadNotificationData, this, | 142 base::Bind(&PlatformNotificationContextImpl::DoReadNotificationData, this, |
| 109 notification_id, origin, callback), | 143 notification_id, origin, callback), |
| 110 base::Bind(callback, false /* success */, NotificationDatabaseData())); | 144 base::Bind(callback, false /* success */, NotificationDatabaseData())); |
| 111 } | 145 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 | 436 |
| 403 return path_.Append(kPlatformNotificationsDirectory); | 437 return path_.Append(kPlatformNotificationsDirectory); |
| 404 } | 438 } |
| 405 | 439 |
| 406 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( | 440 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( |
| 407 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 441 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 408 task_runner_ = task_runner; | 442 task_runner_ = task_runner; |
| 409 } | 443 } |
| 410 | 444 |
| 411 } // namespace content | 445 } // namespace content |
| OLD | NEW |