| 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/browser/background_sync/background_sync_manager.h" | 5 #include "content/browser/background_sync/background_sync_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 BrowserContext* browser_context = | 73 BrowserContext* browser_context = |
| 74 GetBrowserContextOnUIThread(service_worker_context); | 74 GetBrowserContextOnUIThread(service_worker_context); |
| 75 if (!browser_context) | 75 if (!browser_context) |
| 76 return nullptr; | 76 return nullptr; |
| 77 | 77 |
| 78 return browser_context->GetBackgroundSyncController(); | 78 return browser_context->GetBackgroundSyncController(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Returns PermissionStatus::DENIED if the permission manager cannot be | 81 // Returns PermissionStatus::DENIED if the permission manager cannot be |
| 82 // accessed for any reason. | 82 // accessed for any reason. |
| 83 blink::mojom::PermissionStatus GetBackgroundSyncPermissionOnUIThread( | 83 permission::mojom::PermissionStatus GetBackgroundSyncPermissionOnUIThread( |
| 84 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, | 84 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context, |
| 85 const GURL& origin) { | 85 const GURL& origin) { |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 86 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 87 | 87 |
| 88 BrowserContext* browser_context = | 88 BrowserContext* browser_context = |
| 89 GetBrowserContextOnUIThread(service_worker_context); | 89 GetBrowserContextOnUIThread(service_worker_context); |
| 90 if (!browser_context) | 90 if (!browser_context) |
| 91 return blink::mojom::PermissionStatus::DENIED; | 91 return permission::mojom::PermissionStatus::DENIED; |
| 92 | 92 |
| 93 PermissionManager* permission_manager = | 93 PermissionManager* permission_manager = |
| 94 browser_context->GetPermissionManager(); | 94 browser_context->GetPermissionManager(); |
| 95 if (!permission_manager) | 95 if (!permission_manager) |
| 96 return blink::mojom::PermissionStatus::DENIED; | 96 return permission::mojom::PermissionStatus::DENIED; |
| 97 | 97 |
| 98 // The requesting origin always matches the embedding origin. | 98 // The requesting origin always matches the embedding origin. |
| 99 return permission_manager->GetPermissionStatus( | 99 return permission_manager->GetPermissionStatus( |
| 100 PermissionType::BACKGROUND_SYNC, origin, origin); | 100 PermissionType::BACKGROUND_SYNC, origin, origin); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void NotifyBackgroundSyncRegisteredOnUIThread( | 103 void NotifyBackgroundSyncRegisteredOnUIThread( |
| 104 const scoped_refptr<ServiceWorkerContextWrapper>& sw_context_wrapper, | 104 const scoped_refptr<ServiceWorkerContextWrapper>& sw_context_wrapper, |
| 105 const GURL& origin) { | 105 const GURL& origin) { |
| 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 sw_registration->pattern().GetOrigin()), | 459 sw_registration->pattern().GetOrigin()), |
| 460 base::Bind(&BackgroundSyncManager::RegisterDidAskForPermission, | 460 base::Bind(&BackgroundSyncManager::RegisterDidAskForPermission, |
| 461 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, | 461 weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, |
| 462 callback)); | 462 callback)); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void BackgroundSyncManager::RegisterDidAskForPermission( | 465 void BackgroundSyncManager::RegisterDidAskForPermission( |
| 466 int64_t sw_registration_id, | 466 int64_t sw_registration_id, |
| 467 const BackgroundSyncRegistrationOptions& options, | 467 const BackgroundSyncRegistrationOptions& options, |
| 468 const StatusAndRegistrationCallback& callback, | 468 const StatusAndRegistrationCallback& callback, |
| 469 blink::mojom::PermissionStatus permission_status) { | 469 permission::mojom::PermissionStatus permission_status) { |
| 470 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 470 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 471 | 471 |
| 472 if (permission_status == blink::mojom::PermissionStatus::DENIED) { | 472 if (permission_status == permission::mojom::PermissionStatus::DENIED) { |
| 473 RecordFailureAndPostError(BACKGROUND_SYNC_STATUS_PERMISSION_DENIED, | 473 RecordFailureAndPostError(BACKGROUND_SYNC_STATUS_PERMISSION_DENIED, |
| 474 callback); | 474 callback); |
| 475 return; | 475 return; |
| 476 } | 476 } |
| 477 DCHECK(permission_status == blink::mojom::PermissionStatus::GRANTED); | 477 DCHECK(permission_status == permission::mojom::PermissionStatus::GRANTED); |
| 478 | 478 |
| 479 ServiceWorkerRegistration* sw_registration = | 479 ServiceWorkerRegistration* sw_registration = |
| 480 service_worker_context_->GetLiveRegistration(sw_registration_id); | 480 service_worker_context_->GetLiveRegistration(sw_registration_id); |
| 481 if (!sw_registration || !sw_registration->active_version()) { | 481 if (!sw_registration || !sw_registration->active_version()) { |
| 482 // The service worker was shut down in the interim. | 482 // The service worker was shut down in the interim. |
| 483 RecordFailureAndPostError(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, | 483 RecordFailureAndPostError(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, |
| 484 callback); | 484 callback); |
| 485 return; | 485 return; |
| 486 } | 486 } |
| 487 | 487 |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1242 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
| 1243 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1243 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1244 | 1244 |
| 1245 return base::Bind( | 1245 return base::Bind( |
| 1246 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1246 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
| 1247 BackgroundSyncStatus>, | 1247 BackgroundSyncStatus>, |
| 1248 weak_ptr_factory_.GetWeakPtr(), callback); | 1248 weak_ptr_factory_.GetWeakPtr(), callback); |
| 1249 } | 1249 } |
| 1250 | 1250 |
| 1251 } // namespace content | 1251 } // namespace content |
| OLD | NEW |