| 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/public/browser/push_messaging_service.h" | 5 #include "content/public/browser/push_messaging_service.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "content/browser/push_messaging/push_messaging_message_filter.h" | 8 #include "content/browser/push_messaging/push_messaging_message_filter.h" |
| 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 52 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
| 53 int64_t service_worker_registration_id, | 53 int64_t service_worker_registration_id, |
| 54 const base::Closure& callback) { | 54 const base::Closure& callback) { |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 56 | 56 |
| 57 service_worker_context->ClearRegistrationUserData( | 57 service_worker_context->ClearRegistrationUserData( |
| 58 service_worker_registration_id, {kPushRegistrationIdServiceWorkerKey}, | 58 service_worker_registration_id, {kPushRegistrationIdServiceWorkerKey}, |
| 59 base::Bind(&CallClosureFromIO, callback)); | 59 base::Bind(&CallClosureFromIO, callback)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void StorePushSubscriptionOnIOForTesting( |
| 63 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
| 64 int64_t service_worker_registration_id, |
| 65 const GURL& origin, |
| 66 const std::string& subscription_id, |
| 67 const std::string& sender_id, |
| 68 const base::Closure& callback) { |
| 69 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 70 |
| 71 service_worker_context->StoreRegistrationUserData( |
| 72 service_worker_registration_id, origin, |
| 73 {{kPushRegistrationIdServiceWorkerKey, subscription_id}, |
| 74 {kPushSenderIdServiceWorkerKey, sender_id}}, |
| 75 base::Bind(&CallClosureFromIO, callback)); |
| 76 } |
| 77 |
| 62 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( | 78 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( |
| 63 BrowserContext* browser_context, const GURL& origin) { | 79 BrowserContext* browser_context, const GURL& origin) { |
| 64 StoragePartition* partition = | 80 StoragePartition* partition = |
| 65 BrowserContext::GetStoragePartitionForSite(browser_context, origin); | 81 BrowserContext::GetStoragePartitionForSite(browser_context, origin); |
| 66 return make_scoped_refptr( | 82 return make_scoped_refptr( |
| 67 static_cast<ServiceWorkerContextWrapper*>( | 83 static_cast<ServiceWorkerContextWrapper*>( |
| 68 partition->GetServiceWorkerContext())); | 84 partition->GetServiceWorkerContext())); |
| 69 } | 85 } |
| 70 | 86 |
| 71 } // anonymous namespace | 87 } // anonymous namespace |
| (...skipping 23 matching lines...) Expand all Loading... |
| 95 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 96 BrowserThread::PostTask( | 112 BrowserThread::PostTask( |
| 97 BrowserThread::IO, | 113 BrowserThread::IO, |
| 98 FROM_HERE, | 114 FROM_HERE, |
| 99 base::Bind(&ClearPushSubscriptionIDOnIO, | 115 base::Bind(&ClearPushSubscriptionIDOnIO, |
| 100 GetServiceWorkerContext(browser_context, origin), | 116 GetServiceWorkerContext(browser_context, origin), |
| 101 service_worker_registration_id, | 117 service_worker_registration_id, |
| 102 callback)); | 118 callback)); |
| 103 } | 119 } |
| 104 | 120 |
| 121 // static |
| 122 void PushMessagingService::StorePushSubscriptionForTesting( |
| 123 BrowserContext* browser_context, |
| 124 const GURL& origin, |
| 125 int64_t service_worker_registration_id, |
| 126 const std::string& subscription_id, |
| 127 const std::string& sender_id, |
| 128 const base::Closure& callback) { |
| 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 130 BrowserThread::PostTask( |
| 131 BrowserThread::IO, |
| 132 FROM_HERE, |
| 133 base::Bind(&StorePushSubscriptionOnIOForTesting, |
| 134 GetServiceWorkerContext(browser_context, origin), |
| 135 service_worker_registration_id, |
| 136 origin, |
| 137 subscription_id, |
| 138 sender_id, |
| 139 callback)); |
| 140 } |
| 141 |
| 105 } // namespace content | 142 } // namespace content |
| OLD | NEW |