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

Unified Diff: sync/internal_api/public/base/cancellation_signal.cc

Issue 23189021: sync: Gracefully handle very early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sync_client compile Created 7 years, 4 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: sync/internal_api/public/base/cancellation_signal.cc
diff --git a/sync/internal_api/public/base/cancellation_signal.cc b/sync/internal_api/public/base/cancellation_signal.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7921d08f4adae440198b17c9f81f3e8511309c5a
--- /dev/null
+++ b/sync/internal_api/public/base/cancellation_signal.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/internal_api/public/base/cancellation_signal.h"
+
+#include "base/logging.h"
+#include "sync/internal_api/public/base/cancellation_observer.h"
+
+namespace syncer {
+
+CancellationSignal::CancellationSignal()
+ : stop_requested_(false),
+ handler_(NULL){ }
akalin 2013/09/05 16:06:35 space after )
rlarocque 2013/09/05 22:37:06 Done.
+
+CancellationSignal::~CancellationSignal() {
+ DCHECK(!handler_);
+}
+
+bool CancellationSignal::TryRegisterHandler(CancellationObserver* handler) {
+ base::AutoLock lock(stop_requested_lock_);
+ DCHECK(!handler_);
+
+ if (stop_requested_)
+ return false;
+
+ handler_ = handler;
+ return true;
+}
+
+void CancellationSignal::UnregisterHandler(CancellationObserver* handler) {
+ base::AutoLock lock(stop_requested_lock_);
+ DCHECK_EQ(handler_, handler);
+ handler_ = NULL;
+}
+
+bool CancellationSignal::IsStopRequested() {
+ base::AutoLock lock(stop_requested_lock_);
+ return stop_requested_;
+}
+
+void CancellationSignal::RequestStop() {
+ base::AutoLock lock(stop_requested_lock_);
+ DCHECK(!stop_requested_);
+
+ stop_requested_ = true;
+ if (handler_) {
+ handler_->OnStopRequested();
+ }
+}
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698