Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: content/browser/background_sync/background_sync_registration.cc

Issue 1344843003: [BackgroundSync] Add browser side support for SyncRegistration.done (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ncn_max
Patch Set: Address comments from PS7 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_registration.h" 5 #include "content/browser/background_sync/background_sync_registration.h"
6 6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12
7 namespace content { 13 namespace content {
8 14
9 const BackgroundSyncRegistration::RegistrationId 15 const BackgroundSyncRegistration::RegistrationId
10 BackgroundSyncRegistration::kInvalidRegistrationId = -1; 16 BackgroundSyncRegistration::kInvalidRegistrationId = -1;
11 17
12 const BackgroundSyncRegistration::RegistrationId 18 const BackgroundSyncRegistration::RegistrationId
13 BackgroundSyncRegistration::kInitialId = 0; 19 BackgroundSyncRegistration::kInitialId = 0;
14 20
21 BackgroundSyncRegistration::BackgroundSyncRegistration() = default;
22 BackgroundSyncRegistration::~BackgroundSyncRegistration() = default;
23
15 bool BackgroundSyncRegistration::Equals( 24 bool BackgroundSyncRegistration::Equals(
16 const BackgroundSyncRegistration& other) const { 25 const BackgroundSyncRegistration& other) const {
17 return options_.Equals(other.options_); 26 return options_.Equals(other.options_);
18 } 27 }
19 28
20 bool BackgroundSyncRegistration::IsValid() const { 29 bool BackgroundSyncRegistration::IsValid() const {
21 return id_ != kInvalidRegistrationId; 30 return id_ != kInvalidRegistrationId;
22 } 31 }
23 32
33 void BackgroundSyncRegistration::AddDoneCallback(
34 const StateCallback& callback) {
35 DCHECK(!HasCompleted());
36 notify_done_callbacks_.push_back(callback);
37 }
38
39 void BackgroundSyncRegistration::RunDoneCallbacks() {
40 DCHECK(HasCompleted());
41
42 for (auto& callback : notify_done_callbacks_) {
43 base::ThreadTaskRunnerHandle::Get()->PostTask(
44 FROM_HERE, base::Bind(callback, sync_state_));
45 }
46
47 notify_done_callbacks_.clear();
48 }
49
50 bool BackgroundSyncRegistration::HasCompleted() const {
51 switch (sync_state_) {
52 case BACKGROUND_SYNC_STATE_PENDING:
53 case BACKGROUND_SYNC_STATE_FIRING:
54 case BACKGROUND_SYNC_STATE_UNREGISTERED_WHILE_FIRING:
55 return false;
56 case BACKGROUND_SYNC_STATE_FAILED:
57 case BACKGROUND_SYNC_STATE_SUCCESS:
58 case BACKGROUND_SYNC_STATE_UNREGISTERED:
59 return true;
60 }
61 NOTREACHED();
62 return false;
63 }
64
24 } // namespace content 65 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698