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/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" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/storage_partition.h" | 12 #include "content/public/browser/storage_partition.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 void CallStringCallbackFromIO( | 18 void CallStringCallbackFromIO( |
| 19 const PushMessagingService::StringCallback& callback, | 19 const PushMessagingService::StringCallback& callback, |
| 20 const std::string& data, | 20 const std::vector<std::string>& data, |
| 21 ServiceWorkerStatusCode service_worker_status) { | 21 ServiceWorkerStatusCode service_worker_status) { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 22 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
|
michaeln
2016/05/03 19:38:06
maybe DCHECK_LE(data.size(), 1)
johnme
2016/05/05 10:54:04
I put a DCHECK_EQ(1u, data.size()); in the success
| |
| 23 bool success = service_worker_status == SERVICE_WORKER_OK; | 23 bool success = service_worker_status == SERVICE_WORKER_OK; |
| 24 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; | 24 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; |
| 25 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 25 BrowserThread::PostTask( |
| 26 base::Bind(callback, data, success, not_found)); | 26 BrowserThread::UI, FROM_HERE, |
| 27 base::Bind(callback, success ? data[0] : std::string(), success, | |
| 28 not_found)); | |
| 27 } | 29 } |
| 28 | 30 |
| 29 void CallClosureFromIO(const base::Closure& callback, | 31 void CallClosureFromIO(const base::Closure& callback, |
| 30 ServiceWorkerStatusCode status) { | 32 ServiceWorkerStatusCode status) { |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 33 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 32 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 34 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void GetUserDataOnIO( | 37 void GetUserDataOnIO( |
| 36 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, | 38 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, |
| 37 int64_t service_worker_registration_id, | 39 int64_t service_worker_registration_id, |
| 38 const std::string& key, | 40 const std::string& key, |
| 39 const PushMessagingService::StringCallback& callback) { | 41 const PushMessagingService::StringCallback& callback) { |
| 40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 42 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 41 service_worker_context_wrapper->GetRegistrationUserData( | 43 service_worker_context_wrapper->GetRegistrationUserData( |
| 42 service_worker_registration_id, key, | 44 service_worker_registration_id, {key}, |
| 43 base::Bind(&CallStringCallbackFromIO, callback)); | 45 base::Bind(&CallStringCallbackFromIO, callback)); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void ClearPushSubscriptionIDOnIO( | 48 void ClearPushSubscriptionIDOnIO( |
| 47 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 49 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
| 48 int64_t service_worker_registration_id, | 50 int64_t service_worker_registration_id, |
| 49 const base::Closure& callback) { | 51 const base::Closure& callback) { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 51 | 53 |
| 52 service_worker_context->ClearRegistrationUserData( | 54 service_worker_context->ClearRegistrationUserData( |
| 53 service_worker_registration_id, | 55 service_worker_registration_id, {kPushRegistrationIdServiceWorkerKey}, |
| 54 kPushRegistrationIdServiceWorkerKey, | |
| 55 base::Bind(&CallClosureFromIO, callback)); | 56 base::Bind(&CallClosureFromIO, callback)); |
| 56 } | 57 } |
| 57 | 58 |
| 58 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( | 59 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( |
| 59 BrowserContext* browser_context, const GURL& origin) { | 60 BrowserContext* browser_context, const GURL& origin) { |
| 60 StoragePartition* partition = | 61 StoragePartition* partition = |
| 61 BrowserContext::GetStoragePartitionForSite(browser_context, origin); | 62 BrowserContext::GetStoragePartitionForSite(browser_context, origin); |
| 62 return make_scoped_refptr( | 63 return make_scoped_refptr( |
| 63 static_cast<ServiceWorkerContextWrapper*>( | 64 static_cast<ServiceWorkerContextWrapper*>( |
| 64 partition->GetServiceWorkerContext())); | 65 partition->GetServiceWorkerContext())); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 92 BrowserThread::PostTask( | 93 BrowserThread::PostTask( |
| 93 BrowserThread::IO, | 94 BrowserThread::IO, |
| 94 FROM_HERE, | 95 FROM_HERE, |
| 95 base::Bind(&ClearPushSubscriptionIDOnIO, | 96 base::Bind(&ClearPushSubscriptionIDOnIO, |
| 96 GetServiceWorkerContext(browser_context, origin), | 97 GetServiceWorkerContext(browser_context, origin), |
| 97 service_worker_registration_id, | 98 service_worker_registration_id, |
| 98 callback)); | 99 callback)); |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace content | 102 } // namespace content |
| OLD | NEW |