Chromium Code Reviews| Index: sync/internal_api/public/base/cancelation_signal.cc |
| diff --git a/sync/internal_api/public/base/cancelation_signal.cc b/sync/internal_api/public/base/cancelation_signal.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a95578f5fa9baf87c2bdbba91f51ca18b2b5974e |
| --- /dev/null |
| +++ b/sync/internal_api/public/base/cancelation_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/cancelation_signal.h" |
| + |
| +#include "base/logging.h" |
| +#include "sync/internal_api/public/base/cancelation_observer.h" |
| + |
| +namespace syncer { |
| + |
| +CancelationSignal::CancelationSignal() |
| + : stop_requested_(false), |
| + handler_(NULL) { } |
| + |
| +CancelationSignal::~CancelationSignal() { |
| + DCHECK(!handler_); |
| +} |
| + |
| +bool CancelationSignal::TryRegisterHandler(CancelationObserver* handler) { |
| + base::AutoLock lock(stop_requested_lock_); |
| + DCHECK(!handler_); |
| + |
| + if (stop_requested_) |
| + return false; |
| + |
| + handler_ = handler; |
| + return true; |
| +} |
| + |
| +void CancelationSignal::UnregisterHandler(CancelationObserver* handler) { |
| + base::AutoLock lock(stop_requested_lock_); |
| + DCHECK_EQ(handler_, handler); |
| + handler_ = NULL; |
| +} |
| + |
| +bool CancelationSignal::IsStopRequested() { |
| + base::AutoLock lock(stop_requested_lock_); |
| + return stop_requested_; |
| +} |
| + |
| +void CancelationSignal::RequestStop() { |
| + base::AutoLock lock(stop_requested_lock_); |
| + DCHECK(!stop_requested_); |
| + |
| + stop_requested_ = true; |
| + if (handler_) { |
| + handler_->OnStopRequested(); |
|
tim (not reviewing)
2013/09/06 21:47:34
A basic test that exercises each method in the int
rlarocque
2013/09/06 22:42:53
There are several shutdown scenarios tested in syn
tim (not reviewing)
2013/09/06 23:17:41
I don't think it's true that unit tests are unnece
rlarocque
2013/09/09 18:06:58
I may have miscommunicated my argument here.
The
|
| + } |
| +} |
| + |
| +} // namespace syncer |