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 |