Index: content/browser/background_sync/background_sync_manager.cc |
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc |
index 071b97a742dc5e84af989e0f0a4bfcd25602a0e6..374fd8fb4953daf6c15d63142a7239413e7c8d5f 100644 |
--- a/content/browser/background_sync/background_sync_manager.cc |
+++ b/content/browser/background_sync/background_sync_manager.cc |
@@ -181,10 +181,18 @@ void BackgroundSyncManager::Register( |
return; |
} |
- op_scheduler_.ScheduleOperation(base::Bind( |
- &BackgroundSyncManager::RegisterImpl, weak_ptr_factory_.GetWeakPtr(), |
- sw_registration_id, options, requested_from_service_worker, |
- MakeStatusAndRegistrationCompletion(callback))); |
+ if (requested_from_service_worker) { |
+ op_scheduler_.ScheduleOperation( |
+ base::Bind(&BackgroundSyncManager::RegisterCheckIfMainFrame, |
+ weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, |
+ MakeStatusAndRegistrationCompletion(callback))); |
+ return; |
+ } |
+ |
+ op_scheduler_.ScheduleOperation( |
+ base::Bind(&BackgroundSyncManager::RegisterImpl, |
+ weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, |
+ MakeStatusAndRegistrationCompletion(callback))); |
} |
void BackgroundSyncManager::GetRegistration( |
@@ -392,10 +400,47 @@ void BackgroundSyncManager::InitDidGetDataFromBackend( |
base::Bind(callback)); |
} |
+void BackgroundSyncManager::RegisterCheckIfMainFrame( |
iclelland
2015/11/25 14:58:16
I know it makes it a bit longer, but I'd prefer so
jkarlin
2015/11/25 16:47:25
Done.
|
+ int64 sw_registration_id, |
+ const BackgroundSyncRegistrationOptions& options, |
+ const StatusAndRegistrationCallback& callback) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ |
+ ServiceWorkerRegistration* sw_registration = |
+ service_worker_context_->GetLiveRegistration(sw_registration_id); |
+ if (!sw_registration || !sw_registration->active_version()) { |
+ BackgroundSyncMetrics::CountRegisterFailure( |
+ options.periodicity, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER); |
+ PostErrorResponse(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback); |
+ return; |
+ } |
+ |
+ HasMainFrameProviderHost( |
+ sw_registration->pattern().GetOrigin(), |
+ base::Bind(&BackgroundSyncManager::RegisterDidCheckIfMainFrame, |
+ weak_ptr_factory_.GetWeakPtr(), sw_registration_id, options, |
+ callback)); |
+} |
+ |
+void BackgroundSyncManager::RegisterDidCheckIfMainFrame( |
+ int64 sw_registration_id, |
+ const BackgroundSyncRegistrationOptions& options, |
+ const StatusAndRegistrationCallback& callback, |
+ bool has_main_frame_client) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ |
+ if (!has_main_frame_client) { |
+ BackgroundSyncMetrics::CountRegisterFailure( |
+ options.periodicity, BACKGROUND_SYNC_STATUS_NOT_ALLOWED); |
+ PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback); |
+ return; |
+ } |
+ RegisterImpl(sw_registration_id, options, callback); |
+} |
+ |
void BackgroundSyncManager::RegisterImpl( |
int64 sw_registration_id, |
const BackgroundSyncRegistrationOptions& options, |
- bool requested_from_service_worker, |
const StatusAndRegistrationCallback& callback) { |
DCHECK_CURRENTLY_ON(BrowserThread::IO); |
@@ -429,13 +474,6 @@ void BackgroundSyncManager::RegisterImpl( |
return; |
} |
- if (requested_from_service_worker && |
- !service_worker_context_->HasWindowProviderHost( |
- sw_registration->pattern().GetOrigin())) { |
- PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback); |
- return; |
- } |
- |
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
base::Bind(&NotifyBackgroundSyncRegisteredOnUIThread, |
service_worker_context_, |
@@ -738,6 +776,12 @@ void BackgroundSyncManager::ScheduleDelayedTask(const base::Closure& callback, |
delay); |
} |
+void BackgroundSyncManager::HasMainFrameProviderHost( |
+ const GURL& origin, |
+ const BoolCallback& callback) { |
+ service_worker_context_->HasMainFrameProviderHost(origin, callback); |
+} |
+ |
scoped_ptr<BackgroundSyncRegistrationHandle> |
BackgroundSyncManager::CreateRegistrationHandle( |
const scoped_refptr<RefCountedRegistration>& registration) { |
@@ -1231,11 +1275,11 @@ void BackgroundSyncManager::EventCompleteImpl( |
ServiceWorkerRegistration* sw_registration = |
service_worker_context_->GetLiveRegistration(service_worker_id); |
if (sw_registration) { |
- bool foreground = service_worker_context_->HasWindowProviderHost( |
- sw_registration->pattern().GetOrigin()); |
- BackgroundSyncMetrics::RecordEventResult( |
- registration->options()->periodicity, status_code == SERVICE_WORKER_OK, |
- foreground); |
+ HasMainFrameProviderHost( |
+ sw_registration->pattern().GetOrigin(), |
+ base::Bind(&BackgroundSyncMetrics::RecordEventResult, |
+ registration->options()->periodicity, |
+ status_code == SERVICE_WORKER_OK)); |
} |
if (registration->options()->periodicity == SYNC_ONE_SHOT) { |