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

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

Issue 1948223004: Introduce the Blink NotificationService, move permission checks there (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/notifications/blink_notification_service_impl.h"
6
7 #include "base/logging.h"
8 #include "content/browser/notifications/platform_notification_context_impl.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/content_browser_client.h"
11 #include "content/public/browser/platform_notification_service.h"
12 #include "content/public/common/content_client.h"
13 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
14 #include "url/gurl.h"
15
16 namespace content {
17
18 namespace {
19
20 // Returns the implementation of the PlatformNotificationService. May be NULL.
21 PlatformNotificationService* service() {
22 return GetContentClient()->browser()->GetPlatformNotificationService();
23 }
24
25 } // namespace
26
27 BlinkNotificationServiceImpl::BlinkNotificationServiceImpl(
28 PlatformNotificationContextImpl* notification_context,
29 ResourceContext* resource_context,
30 int render_process_id,
31 mojo::InterfaceRequest<blink::mojom::NotificationService> request)
32 : resource_context_(resource_context),
33 render_process_id_(render_process_id),
34 binding_(this, std::move(request)) {
35 DCHECK_CURRENTLY_ON(BrowserThread::IO);
36 DCHECK(notification_context_);
37 DCHECK(resource_context_);
38
39 binding_.set_connection_error_handler(
40 base::Bind(&BlinkNotificationServiceImpl::OnConnectionError,
41 base::Unretained(this) /* the channel is owned by this */));
42 }
43
44 BlinkNotificationServiceImpl::~BlinkNotificationServiceImpl() {
45 DCHECK_CURRENTLY_ON(BrowserThread::IO);
46 }
47
48 void BlinkNotificationServiceImpl::GetPermissionStatus(
49 const mojo::String& origin,
50 const GetPermissionStatusCallback& callback) {
51 DCHECK_CURRENTLY_ON(BrowserThread::IO);
52
53 if (!service()) {
54 callback.Run(blink::mojom::PermissionStatus::DENIED);
55 return;
56 }
57
58 blink::mojom::PermissionStatus permission_status =
59 service()->CheckPermissionOnIOThread(
60 resource_context_, GURL(origin.get()), render_process_id_);
61
62 callback.Run(permission_status);
63 }
64
65 void BlinkNotificationServiceImpl::OnConnectionError() {
66 notification_context_->RemoveService(this);
67 // |this| has now been deleted.
68 }
69
70 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698