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

Unified 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: Extract some of the changes to new CLs 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/background_sync/background_sync_registration.cc
diff --git a/content/browser/background_sync/background_sync_registration.cc b/content/browser/background_sync/background_sync_registration.cc
index d6a122c735b66fad937db47878485093e170b7bc..206e3b4a76898aca2fc73497a18c30698d1075e2 100644
--- a/content/browser/background_sync/background_sync_registration.cc
+++ b/content/browser/background_sync/background_sync_registration.cc
@@ -4,6 +4,12 @@
#include "content/browser/background_sync/background_sync_registration.h"
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
+
namespace content {
const BackgroundSyncRegistration::RegistrationId
@@ -12,6 +18,9 @@ const BackgroundSyncRegistration::RegistrationId
const BackgroundSyncRegistration::RegistrationId
BackgroundSyncRegistration::kInitialId = 0;
+BackgroundSyncRegistration::BackgroundSyncRegistration() = default;
+BackgroundSyncRegistration::~BackgroundSyncRegistration() = default;
+
bool BackgroundSyncRegistration::Equals(
const BackgroundSyncRegistration& other) const {
return options_.Equals(other.options_);
@@ -21,4 +30,24 @@ bool BackgroundSyncRegistration::IsValid() const {
return id_ != kInvalidRegistrationId;
}
+void BackgroundSyncRegistration::AddDoneCallback(
+ const StateCallback& callback) {
+ DCHECK_NE(BACKGROUND_SYNC_STATE_SUCCESS, sync_state_);
+ DCHECK_NE(BACKGROUND_SYNC_STATE_FAILED, sync_state_);
+ DCHECK_NE(BACKGROUND_SYNC_STATE_UNREGISTERED, sync_state_);
iclelland 2015/09/17 13:48:09 This set of negative tests complements the positiv
jkarlin 2015/09/17 17:40:25 Nice catch. I've added HasCompleted() which uses a
+ notify_done_callbacks_.push_back(callback);
+}
+
+void BackgroundSyncRegistration::RunDoneCallbacks() {
+ DCHECK_NE(BACKGROUND_SYNC_STATE_PENDING, sync_state_);
+ DCHECK_NE(BACKGROUND_SYNC_STATE_FIRING, sync_state_);
+
+ for (auto& callback : notify_done_callbacks_) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, sync_state_));
+ }
+
+ notify_done_callbacks_.clear();
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698