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

Side by Side Diff: content/public/browser/push_messaging_service.cc

Issue 930083002: Unregister with push service and SW database when permission is lost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 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
« no previous file with comments | « content/public/browser/push_messaging_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/public/browser/push_messaging_service.h" 5 #include "content/public/browser/push_messaging_service.h"
6 6
7 #include "content/browser/push_messaging/push_messaging_message_filter.h"
7 #include "content/browser/service_worker/service_worker_context_wrapper.h" 8 #include "content/browser/service_worker/service_worker_context_wrapper.h"
9 #include "content/public/browser/browser_context.h"
8 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/storage_partition.h"
12
13 namespace content {
9 14
10 namespace { 15 namespace {
11 16
12 const char kNotificationsShownServiceWorkerKey[] = 17 const char kNotificationsShownServiceWorkerKey[] =
13 "notifications_shown_by_last_few_pushes"; 18 "notifications_shown_by_last_few_pushes";
14 19
15 } // namespace 20 void CallGetNotificationsShownCallbackFromIO(
16
17 namespace content {
18
19 static void CallGetNotificationsShownCallbackFromIO(
20 const PushMessagingService::GetNotificationsShownCallback& callback, 21 const PushMessagingService::GetNotificationsShownCallback& callback,
21 const std::string& data, 22 const std::string& data,
22 ServiceWorkerStatusCode service_worker_status) { 23 ServiceWorkerStatusCode service_worker_status) {
23 DCHECK_CURRENTLY_ON(BrowserThread::IO); 24 DCHECK_CURRENTLY_ON(BrowserThread::IO);
24 bool success = service_worker_status == SERVICE_WORKER_OK; 25 bool success = service_worker_status == SERVICE_WORKER_OK;
25 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; 26 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND;
26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 27 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
27 base::Bind(callback, data, success, not_found)); 28 base::Bind(callback, data, success, not_found));
28 } 29 }
29 30
30 static void CallResultCallbackFromIO( 31 void CallResultCallbackFromIO(
31 const ServiceWorkerContext::ResultCallback& callback, 32 const ServiceWorkerContext::ResultCallback& callback,
32 ServiceWorkerStatusCode service_worker_status) { 33 ServiceWorkerStatusCode service_worker_status) {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO); 34 DCHECK_CURRENTLY_ON(BrowserThread::IO);
34 bool success = service_worker_status == SERVICE_WORKER_OK; 35 bool success = service_worker_status == SERVICE_WORKER_OK;
35 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 36 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
36 base::Bind(callback, success)); 37 base::Bind(callback, success));
37 } 38 }
38 39
39 static void GetNotificationsShownOnIO( 40 void GetNotificationsShownOnIO(
40 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, 41 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
41 int64 service_worker_registration_id, 42 int64 service_worker_registration_id,
42 const PushMessagingService::GetNotificationsShownCallback& callback) { 43 const PushMessagingService::GetNotificationsShownCallback& callback) {
43 DCHECK_CURRENTLY_ON(BrowserThread::IO); 44 DCHECK_CURRENTLY_ON(BrowserThread::IO);
44 service_worker_context_wrapper->context()->storage()->GetUserData( 45 service_worker_context_wrapper->context()->storage()->GetUserData(
45 service_worker_registration_id, kNotificationsShownServiceWorkerKey, 46 service_worker_registration_id, kNotificationsShownServiceWorkerKey,
46 base::Bind(&CallGetNotificationsShownCallbackFromIO, callback)); 47 base::Bind(&CallGetNotificationsShownCallbackFromIO, callback));
47 } 48 }
48 49
49 static void SetNotificationsShownOnIO( 50 void SetNotificationsShownOnIO(
50 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, 51 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
51 int64 service_worker_registration_id, const GURL& origin, 52 int64 service_worker_registration_id, const GURL& origin,
52 const std::string& data, 53 const std::string& data,
53 const PushMessagingService::ResultCallback& callback) { 54 const PushMessagingService::ResultCallback& callback) {
54 DCHECK_CURRENTLY_ON(BrowserThread::IO); 55 DCHECK_CURRENTLY_ON(BrowserThread::IO);
55 service_worker_context_wrapper->context()->storage()->StoreUserData( 56 service_worker_context_wrapper->context()->storage()->StoreUserData(
56 service_worker_registration_id, origin, 57 service_worker_registration_id, origin,
57 kNotificationsShownServiceWorkerKey, data, 58 kNotificationsShownServiceWorkerKey, data,
58 base::Bind(&CallResultCallbackFromIO, callback)); 59 base::Bind(&CallResultCallbackFromIO, callback));
59 } 60 }
60 61
62 void OnClearPushRegistrationServiceWorkerKey(ServiceWorkerStatusCode status) {
63 }
64
65 void ClearPushRegistrationIDOnIO(
66 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
67 int64 service_worker_registration_id) {
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
69
70 service_worker_context->context()->storage()->ClearUserData(
71 service_worker_registration_id,
72 kPushRegistrationIdServiceWorkerKey,
73 base::Bind(&OnClearPushRegistrationServiceWorkerKey));
74 }
75
76 } // anonymous namespace
77
61 // static 78 // static
62 void PushMessagingService::GetNotificationsShownByLastFewPushes( 79 void PushMessagingService::GetNotificationsShownByLastFewPushes(
63 ServiceWorkerContext* service_worker_context, 80 ServiceWorkerContext* service_worker_context,
64 int64 service_worker_registration_id, 81 int64 service_worker_registration_id,
65 const GetNotificationsShownCallback& callback) { 82 const GetNotificationsShownCallback& callback) {
66 DCHECK_CURRENTLY_ON(BrowserThread::UI); 83 DCHECK_CURRENTLY_ON(BrowserThread::UI);
67 scoped_refptr<ServiceWorkerContextWrapper> wrapper = 84 scoped_refptr<ServiceWorkerContextWrapper> wrapper =
68 static_cast<ServiceWorkerContextWrapper*>(service_worker_context); 85 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
69 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 86 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
70 base::Bind(&GetNotificationsShownOnIO, 87 base::Bind(&GetNotificationsShownOnIO,
(...skipping 14 matching lines...) Expand all
85 static_cast<ServiceWorkerContextWrapper*>(service_worker_context); 102 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
86 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 103 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
87 base::Bind(&SetNotificationsShownOnIO, 104 base::Bind(&SetNotificationsShownOnIO,
88 wrapper, 105 wrapper,
89 service_worker_registration_id, 106 service_worker_registration_id,
90 origin, 107 origin,
91 notifications_shown, 108 notifications_shown,
92 callback)); 109 callback));
93 } 110 }
94 111
112 // static
113 void PushMessagingService::ClearPushRegistrationID(
114 BrowserContext* browser_context,
115 const GURL& origin,
116 int64 service_worker_registration_id) {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
118 StoragePartition* partition =
119 BrowserContext::GetStoragePartitionForSite(browser_context, origin);
120 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context =
121 static_cast<ServiceWorkerContextWrapper*>(
122 partition->GetServiceWorkerContext());
123
124 BrowserThread::PostTask(
125 BrowserThread::IO,
126 FROM_HERE,
127 base::Bind(&ClearPushRegistrationIDOnIO,
128 service_worker_context,
129 service_worker_registration_id));
130 }
131
95 } // namespace content 132 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/push_messaging_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698