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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 767 } |
765 | 768 |
766 void BackgroundSyncManager::FireOneShotSync( | 769 void BackgroundSyncManager::FireOneShotSync( |
767 BackgroundSyncRegistrationHandle::HandleId handle_id, | 770 BackgroundSyncRegistrationHandle::HandleId handle_id, |
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 |
| 777 base::TimeTicks expiration = |
| 778 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(kSyncEventSec); |
| 779 |
774 // The ServiceWorkerVersion doesn't know when the client (javascript) is done | 780 // The ServiceWorkerVersion doesn't know when the client (javascript) is done |
775 // with the registration so don't give it a BackgroundSyncRegistrationHandle. | 781 // 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 | 782 // Once the render process gets the handle_id it can create its own handle |
777 // (with a new unique handle id). | 783 // (with a new unique handle id). |
778 active_version->DispatchSyncEvent(handle_id, last_chance, callback); | 784 active_version->DispatchSyncEvent(handle_id, last_chance, expiration, |
| 785 callback); |
779 } | 786 } |
780 | 787 |
781 void BackgroundSyncManager::ScheduleDelayedTask(const base::Closure& callback, | 788 void BackgroundSyncManager::ScheduleDelayedTask(const base::Closure& callback, |
782 base::TimeDelta delay) { | 789 base::TimeDelta delay) { |
783 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, callback, | 790 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, callback, |
784 delay); | 791 delay); |
785 } | 792 } |
786 | 793 |
787 void BackgroundSyncManager::HasMainFrameProviderHost( | 794 void BackgroundSyncManager::HasMainFrameProviderHost( |
788 const GURL& origin, | 795 const GURL& origin, |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { | 1497 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { |
1491 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1498 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1492 | 1499 |
1493 return base::Bind( | 1500 return base::Bind( |
1494 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, | 1501 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, |
1495 BackgroundSyncStatus>, | 1502 BackgroundSyncStatus>, |
1496 weak_ptr_factory_.GetWeakPtr(), callback); | 1503 weak_ptr_factory_.GetWeakPtr(), callback); |
1497 } | 1504 } |
1498 | 1505 |
1499 } // namespace content | 1506 } // namespace content |
OLD | NEW |