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

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: 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 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..30bbf9e2afaf43ff13f394d8cbaf50991d79dcd5 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,36 @@ bool BackgroundSyncRegistration::IsValid() const {
return id_ != kInvalidRegistrationId;
}
+void BackgroundSyncRegistration::AddDoneCallback(
+ const StateCallback& callback) {
+ DCHECK(!HasCompleted());
+ notify_done_callbacks_.push_back(callback);
+}
+
+void BackgroundSyncRegistration::RunDoneCallbacks() {
+ DCHECK(HasCompleted());
+
+ for (auto& callback : notify_done_callbacks_) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, sync_state_));
+ }
+
+ notify_done_callbacks_.clear();
+}
+
+bool BackgroundSyncRegistration::HasCompleted() const {
+ switch (sync_state_) {
+ case BACKGROUND_SYNC_STATE_PENDING:
+ case BACKGROUND_SYNC_STATE_FIRING:
+ case BACKGROUND_SYNC_STATE_UNREGISTERED_WHILE_FIRING:
+ return false;
+ case BACKGROUND_SYNC_STATE_FAILED:
+ case BACKGROUND_SYNC_STATE_SUCCESS:
+ case BACKGROUND_SYNC_STATE_UNREGISTERED:
+ return true;
+ }
+ NOTREACHED();
+ return false;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698