| 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 "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 ~RefCountedRegistration() = default; | 40 ~RefCountedRegistration() = default; |
| 41 | 41 |
| 42 BackgroundSyncRegistration registration_; | 42 BackgroundSyncRegistration registration_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 // The key used to index the background sync data in ServiceWorkerStorage. | 47 // The key used to index the background sync data in ServiceWorkerStorage. |
| 48 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; | 48 const char kBackgroundSyncUserDataKey[] = "BackgroundSyncUserData"; |
| 49 | 49 |
| 50 // The amount of time that a sync event can fire for, in seconds. |
| 51 const int kSyncEventSec = 5 * 60; // 5 minutes |
| 52 |
| 50 void PostErrorResponse( | 53 void PostErrorResponse( |
| 51 BackgroundSyncStatus status, | 54 BackgroundSyncStatus status, |
| 52 const BackgroundSyncManager::StatusAndRegistrationCallback& callback) { | 55 const BackgroundSyncManager::StatusAndRegistrationCallback& callback) { |
| 53 base::ThreadTaskRunnerHandle::Get()->PostTask( | 56 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 54 FROM_HERE, | 57 FROM_HERE, |
| 55 base::Bind( | 58 base::Bind( |
| 56 callback, status, | 59 callback, status, |
| 57 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>().Pass()))); | 60 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>().Pass()))); |
| 58 } | 61 } |
| 59 | 62 |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 const scoped_refptr<ServiceWorkerVersion>& active_version, | 771 const scoped_refptr<ServiceWorkerVersion>& active_version, |
| 769 BackgroundSyncEventLastChance last_chance, | 772 BackgroundSyncEventLastChance last_chance, |
| 770 const ServiceWorkerVersion::StatusCallback& callback) { | 773 const ServiceWorkerVersion::StatusCallback& callback) { |
| 771 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 774 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 772 DCHECK(active_version); | 775 DCHECK(active_version); |
| 773 | 776 |
| 774 // The ServiceWorkerVersion doesn't know when the client (javascript) is done | 777 // The ServiceWorkerVersion doesn't know when the client (javascript) is done |
| 775 // with the registration so don't give it a BackgroundSyncRegistrationHandle. | 778 // with the registration so don't give it a BackgroundSyncRegistrationHandle. |
| 776 // Once the render process gets the handle_id it can create its own handle | 779 // Once the render process gets the handle_id it can create its own handle |
| 777 // (with a new unique handle id). | 780 // (with a new unique handle id). |
| 778 active_version->DispatchSyncEvent(handle_id, last_chance, callback); | 781 active_version->DispatchSyncEvent(handle_id, last_chance, |
| 782 base::TimeDelta::FromSeconds(kSyncEventSec), |
| 783 callback); |
| 779 } | 784 } |
| 780 | 785 |
| 781 void BackgroundSyncManager::ScheduleDelayedTask(const base::Closure& callback, | 786 void BackgroundSyncManager::ScheduleDelayedTask(const base::Closure& callback, |
| 782 base::TimeDelta delay) { | 787 base::TimeDelta delay) { |
| 783 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, callback, | 788 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, callback, |
| 784 delay); | 789 delay); |
| 785 } | 790 } |
| 786 | 791 |
| 787 void BackgroundSyncManager::HasMainFrameProviderHost( | 792 void BackgroundSyncManager::HasMainFrameProviderHost( |
| 788 const GURL& origin, | 793 const GURL& origin, |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1495 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
| 1491 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1496 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1492 | 1497 |
| 1493 return base::Bind( | 1498 return base::Bind( |
| 1494 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1499 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
| 1495 BackgroundSyncStatus>, | 1500 BackgroundSyncStatus>, |
| 1496 weak_ptr_factory_.GetWeakPtr(), callback); | 1501 weak_ptr_factory_.GetWeakPtr(), callback); |
| 1497 } | 1502 } |
| 1498 | 1503 |
| 1499 } // namespace content | 1504 } // namespace content |
| OLD | NEW |