Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1698)

Side by Side Diff: content/browser/notifications/platform_notification_context_impl.cc

Issue 2003023002: Introduce the Blink NotificationService, move permission checks there (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.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
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 services_.clear();
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,
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_.push_back(base::WrapUnique(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 auto services_to_remove = std::remove_if(
131 services_.begin(), services_.end(),
132 [service](const std::unique_ptr<BlinkNotificationServiceImpl>& ptr) {
133 return ptr.get() == service;
134 });
135
136 services_.erase(services_to_remove, services_.end());
137 }
138
102 void PlatformNotificationContextImpl::ReadNotificationData( 139 void PlatformNotificationContextImpl::ReadNotificationData(
103 int64_t notification_id, 140 int64_t notification_id,
104 const GURL& origin, 141 const GURL& origin,
105 const ReadResultCallback& callback) { 142 const ReadResultCallback& callback) {
106 DCHECK_CURRENTLY_ON(BrowserThread::IO); 143 DCHECK_CURRENTLY_ON(BrowserThread::IO);
107 LazyInitialize( 144 LazyInitialize(
108 base::Bind(&PlatformNotificationContextImpl::DoReadNotificationData, this, 145 base::Bind(&PlatformNotificationContextImpl::DoReadNotificationData, this,
109 notification_id, origin, callback), 146 notification_id, origin, callback),
110 base::Bind(callback, false /* success */, NotificationDatabaseData())); 147 base::Bind(callback, false /* success */, NotificationDatabaseData()));
111 } 148 }
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 439
403 return path_.Append(kPlatformNotificationsDirectory); 440 return path_.Append(kPlatformNotificationsDirectory);
404 } 441 }
405 442
406 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( 443 void PlatformNotificationContextImpl::SetTaskRunnerForTesting(
407 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { 444 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
408 task_runner_ = task_runner; 445 task_runner_ = task_runner;
409 } 446 }
410 447
411 } // namespace content 448 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698