Commit dafdf50d authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

[sync] Move and refactor CancelationSignal

The class is only used under sync/engine_impl and in fact shouldn't be
used outside, so let's move it away from base/.

While moving it, a few minor things are refactored, such as a few
functions being renamed for clarity.

Change-Id: Ibaf6e662551eeb78e2b7c7cbc88778b54cf31ee2
Bug: 1129782
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2484697Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818459}
parent 8f702c9b
...@@ -91,6 +91,8 @@ static_library("rest_of_sync") { ...@@ -91,6 +91,8 @@ static_library("rest_of_sync") {
"engine_impl/backoff_delay_provider.h", "engine_impl/backoff_delay_provider.h",
"engine_impl/bookmark_update_preprocessing.cc", "engine_impl/bookmark_update_preprocessing.cc",
"engine_impl/bookmark_update_preprocessing.h", "engine_impl/bookmark_update_preprocessing.h",
"engine_impl/cancelation_signal.cc",
"engine_impl/cancelation_signal.h",
"engine_impl/commit.cc", "engine_impl/commit.cc",
"engine_impl/commit.h", "engine_impl/commit.h",
"engine_impl/commit_contribution.h", "engine_impl/commit_contribution.h",
...@@ -397,7 +399,6 @@ source_set("unit_tests") { ...@@ -397,7 +399,6 @@ source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"base/bind_to_task_runner_unittest.cc", "base/bind_to_task_runner_unittest.cc",
"base/cancelation_signal_unittest.cc",
"base/client_tag_hash_unittest.cc", "base/client_tag_hash_unittest.cc",
"base/enum_set_unittest.cc", "base/enum_set_unittest.cc",
"base/immutable_unittest.cc", "base/immutable_unittest.cc",
...@@ -432,6 +433,7 @@ source_set("unit_tests") { ...@@ -432,6 +433,7 @@ source_set("unit_tests") {
"engine/sync_backend_registrar_unittest.cc", "engine/sync_backend_registrar_unittest.cc",
"engine_impl/backoff_delay_provider_unittest.cc", "engine_impl/backoff_delay_provider_unittest.cc",
"engine_impl/bookmark_update_preprocessing_unittest.cc", "engine_impl/bookmark_update_preprocessing_unittest.cc",
"engine_impl/cancelation_signal_unittest.cc",
"engine_impl/commit_contribution_impl_unittest.cc", "engine_impl/commit_contribution_impl_unittest.cc",
"engine_impl/commit_processor_unittest.cc", "engine_impl/commit_processor_unittest.cc",
"engine_impl/cycle/nudge_tracker_unittest.cc", "engine_impl/cycle/nudge_tracker_unittest.cc",
......
...@@ -12,9 +12,6 @@ declare_args() { ...@@ -12,9 +12,6 @@ declare_args() {
static_library("base") { static_library("base") {
sources = [ sources = [
"bind_to_task_runner.h", "bind_to_task_runner.h",
"cancelation_observer.h",
"cancelation_signal.cc",
"cancelation_signal.h",
"client_tag_hash.cc", "client_tag_hash.cc",
"client_tag_hash.h", "client_tag_hash.h",
"data_type_histogram.cc", "data_type_histogram.cc",
......
// Copyright 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.
#ifndef COMPONENTS_SYNC_BASE_CANCELATION_OBSERVER_H_
#define COMPONENTS_SYNC_BASE_CANCELATION_OBSERVER_H_
namespace syncer {
// Interface for classes that handle signals from the CancelationSignal.
class CancelationObserver {
public:
CancelationObserver() = default;
virtual ~CancelationObserver() = default;
// This may be called from a foreign thread while the CancelationSignal's lock
// is held. The callee should avoid performing slow or blocking operations.
virtual void OnSignalReceived() = 0;
};
} // namespace syncer
#endif // COMPONENTS_SYNC_BASE_CANCELATION_OBSERVER_H_
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "components/invalidation/impl/invalidation_switches.h" #include "components/invalidation/impl/invalidation_switches.h"
#include "components/invalidation/public/invalidation.h" #include "components/invalidation/public/invalidation.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/base/system_encryptor.h" #include "components/sync/base/system_encryptor.h"
#include "components/sync/driver/glue/sync_engine_impl.h" #include "components/sync/driver/glue/sync_engine_impl.h"
#include "components/sync/engine/model_type_configurer.h" #include "components/sync/engine/model_type_configurer.h"
#include "components/sync/engine/shutdown_reason.h" #include "components/sync/engine/shutdown_reason.h"
#include "components/sync/engine/sync_encryption_handler.h" #include "components/sync/engine/sync_encryption_handler.h"
#include "components/sync/engine/sync_status_observer.h" #include "components/sync/engine/sync_status_observer.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace syncer { namespace syncer {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/sync/base/cancelation_signal.h" #include "components/sync/engine_impl/cancelation_signal.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
......
...@@ -2,20 +2,19 @@ ...@@ -2,20 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/sync/base/cancelation_signal.h" #include "components/sync/engine_impl/cancelation_signal.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "components/sync/base/cancelation_observer.h"
namespace syncer { namespace syncer {
CancelationSignal::CancelationSignal() : signalled_(false), handler_(nullptr) {} CancelationSignal::CancelationSignal() = default;
CancelationSignal::~CancelationSignal() { CancelationSignal::~CancelationSignal() {
DCHECK(!handler_); DCHECK(!handler_);
} }
bool CancelationSignal::TryRegisterHandler(CancelationObserver* handler) { bool CancelationSignal::TryRegisterHandler(Observer* handler) {
base::AutoLock lock(signal_lock_); base::AutoLock lock(signal_lock_);
DCHECK(!handler_); DCHECK(!handler_);
...@@ -26,7 +25,7 @@ bool CancelationSignal::TryRegisterHandler(CancelationObserver* handler) { ...@@ -26,7 +25,7 @@ bool CancelationSignal::TryRegisterHandler(CancelationObserver* handler) {
return true; return true;
} }
void CancelationSignal::UnregisterHandler(CancelationObserver* handler) { void CancelationSignal::UnregisterHandler(Observer* handler) {
base::AutoLock lock(signal_lock_); base::AutoLock lock(signal_lock_);
DCHECK_EQ(handler_, handler); DCHECK_EQ(handler_, handler);
handler_ = nullptr; handler_ = nullptr;
...@@ -43,7 +42,7 @@ void CancelationSignal::Signal() { ...@@ -43,7 +42,7 @@ void CancelationSignal::Signal() {
signalled_ = true; signalled_ = true;
if (handler_) { if (handler_) {
handler_->OnSignalReceived(); handler_->OnCancelationSignalReceived();
} }
} }
......
...@@ -2,15 +2,13 @@ ...@@ -2,15 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ #ifndef COMPONENTS_SYNC_ENGINE_IMPL_CANCELATION_SIGNAL_H_
#define COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ #define COMPONENTS_SYNC_ENGINE_IMPL_CANCELATION_SIGNAL_H_
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
namespace syncer { namespace syncer {
class CancelationObserver;
// This class is used to allow one thread to request that another abort and // This class is used to allow one thread to request that another abort and
// return early. // return early.
// //
...@@ -20,18 +18,29 @@ class CancelationObserver; ...@@ -20,18 +18,29 @@ class CancelationObserver;
// periodically check the value of IsSignalled() to see if it should return // periodically check the value of IsSignalled() to see if it should return
// early. // early.
// //
// The receiving task may also choose to register an CancelationObserver whose // The receiving task may also choose to register an observer whose
// OnSignalReceived() method will be executed on the signaller's thread when // OnCancelationSignalReceived() method will be executed on the signaller's
// Signal() is called. This may be used for sending an early Signal() to a // thread when Signal() is called. This may be used for sending an early
// WaitableEvent. The registration of the handler is necessarily racy. If // Signal() to a WaitableEvent. The registration of the handler is necessarily
// Signal() is executes before TryRegisterHandler(), TryRegisterHandler() will // racy. If Signal() is executes before TryRegisterHandler(),
// not perform any registration and return false. That function's caller must // TryRegisterHandler() will not perform any registration and return false. That
// handle this case. // function's caller must handle this case.
// //
// This class supports only one handler, though it could easily support multiple // This class supports only one handler, though it could easily support multiple
// observers if we found a use case for such a feature. // observers if we found a use case for such a feature.
class CancelationSignal { class CancelationSignal {
public: public:
class Observer {
public:
Observer() = default;
virtual ~Observer() = default;
// This may be called from a foreign thread while the CancelationSignal's
// lock is held. The callee should avoid performing slow or blocking
// operations.
virtual void OnCancelationSignalReceived() = 0;
};
CancelationSignal(); CancelationSignal();
~CancelationSignal(); ~CancelationSignal();
...@@ -42,16 +51,16 @@ class CancelationSignal { ...@@ -42,16 +51,16 @@ class CancelationSignal {
// //
// If the registration was successful, the handler must be unregistered with // If the registration was successful, the handler must be unregistered with
// UnregisterHandler before this CancelationSignal is destroyed. // UnregisterHandler before this CancelationSignal is destroyed.
bool TryRegisterHandler(CancelationObserver* handler); bool TryRegisterHandler(Observer* handler);
// Unregisters the abort handler. // Unregisters the abort handler.
void UnregisterHandler(CancelationObserver* handler); void UnregisterHandler(Observer* handler);
// Returns true if Signal() has been called. // Returns true if Signal() has been called.
bool IsSignalled(); bool IsSignalled();
// Sets the stop_requested_ flag and calls the OnSignalReceived() method of // Sets the stop_requested_ flag and calls the OnCancelationSignalReceived()
// the registered handler, if there is one registered at the time. // method of the registered handler, if there is one registered at the time.
// SignalReceived() will be called with the |signal_lock_| held. // SignalReceived() will be called with the |signal_lock_| held.
void Signal(); void Signal();
...@@ -60,12 +69,12 @@ class CancelationSignal { ...@@ -60,12 +69,12 @@ class CancelationSignal {
base::Lock signal_lock_; base::Lock signal_lock_;
// True if Signal() has been invoked. // True if Signal() has been invoked.
bool signalled_; bool signalled_ = false;
// The registered abort handler. May be null. // The registered abort handler. May be null.
CancelationObserver* handler_; Observer* handler_ = nullptr;
}; };
} // namespace syncer } // namespace syncer
#endif // COMPONENTS_SYNC_BASE_CANCELATION_SIGNAL_H_ #endif // COMPONENTS_SYNC_ENGINE_IMPL_CANCELATION_SIGNAL_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/sync/base/cancelation_signal.h" #include "components/sync/engine_impl/cancelation_signal.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
...@@ -11,12 +11,11 @@ ...@@ -11,12 +11,11 @@
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/sync/base/cancelation_observer.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace syncer { namespace syncer {
class BlockingTask : public CancelationObserver { class BlockingTask : public CancelationSignal::Observer {
public: public:
explicit BlockingTask(CancelationSignal* cancel_signal); explicit BlockingTask(CancelationSignal* cancel_signal);
~BlockingTask() override; ~BlockingTask() override;
...@@ -32,9 +31,9 @@ class BlockingTask : public CancelationObserver { ...@@ -32,9 +31,9 @@ class BlockingTask : public CancelationObserver {
void Run(base::WaitableEvent* task_start_signal, void Run(base::WaitableEvent* task_start_signal,
base::WaitableEvent* task_done_signal); base::WaitableEvent* task_done_signal);
// Implementation of CancelationObserver. // Implementation of CancelationSignal::Observer.
// Wakes up the thread blocked in Run(). // Wakes up the thread blocked in Run().
void OnSignalReceived() override; void OnCancelationSignalReceived() override;
// Checks if we ever did successfully start waiting for |event_|. Be careful // Checks if we ever did successfully start waiting for |event_|. Be careful
// with this. The flag itself is thread-unsafe, and the event that flips it // with this. The flag itself is thread-unsafe, and the event that flips it
...@@ -81,7 +80,7 @@ void BlockingTask::Run(base::WaitableEvent* task_start_signal, ...@@ -81,7 +80,7 @@ void BlockingTask::Run(base::WaitableEvent* task_start_signal,
task_done_signal->Signal(); task_done_signal->Signal();
} }
void BlockingTask::OnSignalReceived() { void BlockingTask::OnCancelationSignalReceived() {
event_.Signal(); event_.Signal();
} }
...@@ -150,12 +149,13 @@ bool CancelationSignalTest::VerifyTaskNotStarted() { ...@@ -150,12 +149,13 @@ bool CancelationSignalTest::VerifyTaskNotStarted() {
return !blocking_task_.WasStarted(); return !blocking_task_.WasStarted();
} }
class FakeCancelationObserver : public CancelationObserver { class FakeObserver : public CancelationSignal::Observer {
void OnSignalReceived() override {} public:
void OnCancelationSignalReceived() override {}
}; };
TEST(CancelationSignalTest_SingleThread, CheckFlags) { TEST(CancelationSignalTest_SingleThread, CheckFlags) {
FakeCancelationObserver observer; FakeObserver observer;
CancelationSignal signal; CancelationSignal signal;
EXPECT_FALSE(signal.IsSignalled()); EXPECT_FALSE(signal.IsSignalled());
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#include "base/deferred_sequenced_task_runner.h" #include "base/deferred_sequenced_task_runner.h"
#include "base/test/gtest_util.h" #include "base/test/gtest_util.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/engine/data_type_activation_response.h" #include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/engine/fake_model_type_processor.h" #include "components/sync/engine/fake_model_type_processor.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/protocol/model_type_state.pb.h" #include "components/sync/protocol/model_type_state.pb.h"
#include "components/sync/test/engine/mock_nudge_handler.h" #include "components/sync/test/engine/mock_nudge_handler.h"
#include "components/sync/test/fake_sync_encryption_handler.h" #include "components/sync/test/fake_sync_encryption_handler.h"
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/memory_usage_estimator.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/base/client_tag_hash.h" #include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/data_type_histogram.h" #include "components/sync/base/data_type_histogram.h"
#include "components/sync/base/hash_util.h" #include "components/sync/base/hash_util.h"
...@@ -28,6 +27,7 @@ ...@@ -28,6 +27,7 @@
#include "components/sync/base/unique_position.h" #include "components/sync/base/unique_position.h"
#include "components/sync/engine/model_type_processor.h" #include "components/sync/engine/model_type_processor.h"
#include "components/sync/engine_impl/bookmark_update_preprocessing.h" #include "components/sync/engine_impl/bookmark_update_preprocessing.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/commit_contribution.h" #include "components/sync/engine_impl/commit_contribution.h"
#include "components/sync/engine_impl/commit_contribution_impl.h" #include "components/sync/engine_impl/commit_contribution_impl.h"
#include "components/sync/engine_impl/cycle/entity_change_metric_recording.h" #include "components/sync/engine_impl/cycle/entity_change_metric_recording.h"
...@@ -392,7 +392,7 @@ std::unique_ptr<CommitContribution> ModelTypeWorker::GetContribution( ...@@ -392,7 +392,7 @@ std::unique_ptr<CommitContribution> ModelTypeWorker::GetContribution(
model_type_processor_->GetLocalChanges( model_type_processor_->GetLocalChanges(
max_entries, max_entries,
base::BindOnce(&GetLocalChangesRequest::SetResponse, request)); base::BindOnce(&GetLocalChangesRequest::SetResponse, request));
request->WaitForResponse(); request->WaitForResponseOrCancelation();
CommitRequestDataList response; CommitRequestDataList response;
if (!request->WasCancelled()) if (!request->WasCancelled())
response = request->ExtractResponse(); response = request->ExtractResponse();
...@@ -632,11 +632,11 @@ GetLocalChangesRequest::GetLocalChangesRequest( ...@@ -632,11 +632,11 @@ GetLocalChangesRequest::GetLocalChangesRequest(
GetLocalChangesRequest::~GetLocalChangesRequest() {} GetLocalChangesRequest::~GetLocalChangesRequest() {}
void GetLocalChangesRequest::OnSignalReceived() { void GetLocalChangesRequest::OnCancelationSignalReceived() {
response_accepted_.Signal(); response_accepted_.Signal();
} }
void GetLocalChangesRequest::WaitForResponse() { void GetLocalChangesRequest::WaitForResponseOrCancelation() {
if (!cancelation_signal_->TryRegisterHandler(this)) { if (!cancelation_signal_->TryRegisterHandler(this)) {
return; return;
} }
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "components/sync/base/cancelation_observer.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
#include "components/sync/base/passphrase_enums.h" #include "components/sync/base/passphrase_enums.h"
#include "components/sync/engine/commit_and_get_updates_types.h" #include "components/sync/engine/commit_and_get_updates_types.h"
#include "components/sync/engine/commit_queue.h" #include "components/sync/engine/commit_queue.h"
#include "components/sync/engine/sync_encryption_handler.h" #include "components/sync/engine/sync_encryption_handler.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/commit_contributor.h" #include "components/sync/engine_impl/commit_contributor.h"
#include "components/sync/engine_impl/nudge_handler.h" #include "components/sync/engine_impl/nudge_handler.h"
#include "components/sync/engine_impl/update_handler.h" #include "components/sync/engine_impl/update_handler.h"
...@@ -252,30 +252,30 @@ class ModelTypeWorker : public UpdateHandler, ...@@ -252,30 +252,30 @@ class ModelTypeWorker : public UpdateHandler,
// model_type_processor_->GetLocalChanges( // model_type_processor_->GetLocalChanges(
// max_entries, // max_entries,
// base::Bind(&GetLocalChangesRequest::SetResponse, request)); // base::Bind(&GetLocalChangesRequest::SetResponse, request));
// request->WaitForResponse(); // request->WaitForResponseOrCancelation();
// CommitRequestDataList response; // CommitRequestDataList response;
// if (!request->WasCancelled()) // if (!request->WasCancelled())
// response = request->ExtractResponse(); // response = request->ExtractResponse();
class GetLocalChangesRequest class GetLocalChangesRequest
: public base::RefCountedThreadSafe<GetLocalChangesRequest>, : public base::RefCountedThreadSafe<GetLocalChangesRequest>,
public CancelationObserver { public CancelationSignal::Observer {
public: public:
explicit GetLocalChangesRequest(CancelationSignal* cancelation_signal); explicit GetLocalChangesRequest(CancelationSignal* cancelation_signal);
// CancelationObserver implementation. // CancelationSignal::Observer implementation.
void OnSignalReceived() override; void OnCancelationSignalReceived() override;
// Blocks current thread until either SetResponse is called or // Blocks current thread until either SetResponse is called or
// cancelation_signal_ is signaled. // cancelation_signal_ is signaled.
void WaitForResponse(); void WaitForResponseOrCancelation();
// SetResponse takes ownership of |local_changes| and unblocks WaitForResponse // SetResponse takes ownership of |local_changes| and unblocks
// call. It is called by model type through callback passed to // WaitForResponseOrCancelation call. It is called by model type through
// GetLocalChanges. // callback passed to GetLocalChanges.
void SetResponse(CommitRequestDataList&& local_changes); void SetResponse(CommitRequestDataList&& local_changes);
// Checks if WaitForResponse was canceled through CancelationSignal. When // Checks if WaitForResponseOrCancelation was canceled through
// returns true calling ExtractResponse is unsafe. // CancelationSignal. When returns true calling ExtractResponse is unsafe.
bool WasCancelled(); bool WasCancelled();
// Returns response set by SetResponse(). // Returns response set by SetResponse().
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/base/client_tag_hash.h" #include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/unique_position.h" #include "components/sync/base/unique_position.h"
#include "components/sync/engine/model_type_processor.h" #include "components/sync/engine/model_type_processor.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/commit_contribution.h" #include "components/sync/engine_impl/commit_contribution.h"
#include "components/sync/engine_impl/cycle/entity_change_metric_recording.h" #include "components/sync/engine_impl/cycle/entity_change_metric_recording.h"
#include "components/sync/engine_impl/cycle/status_controller.h" #include "components/sync/engine_impl/cycle/status_controller.h"
...@@ -1672,7 +1672,8 @@ class GetLocalChangesRequestTest : public testing::Test { ...@@ -1672,7 +1672,8 @@ class GetLocalChangesRequestTest : public testing::Test {
scoped_refptr<GetLocalChangesRequest> MakeRequest(); scoped_refptr<GetLocalChangesRequest> MakeRequest();
void BlockingWaitForResponse(scoped_refptr<GetLocalChangesRequest> request); void BlockingWaitForResponseOrCancelation(
scoped_refptr<GetLocalChangesRequest> request);
void ScheduleBlockingWait(scoped_refptr<GetLocalChangesRequest> request); void ScheduleBlockingWait(scoped_refptr<GetLocalChangesRequest> request);
protected: protected:
...@@ -1704,10 +1705,10 @@ GetLocalChangesRequestTest::MakeRequest() { ...@@ -1704,10 +1705,10 @@ GetLocalChangesRequestTest::MakeRequest() {
return base::MakeRefCounted<GetLocalChangesRequest>(&cancelation_signal_); return base::MakeRefCounted<GetLocalChangesRequest>(&cancelation_signal_);
} }
void GetLocalChangesRequestTest::BlockingWaitForResponse( void GetLocalChangesRequestTest::BlockingWaitForResponseOrCancelation(
scoped_refptr<GetLocalChangesRequest> request) { scoped_refptr<GetLocalChangesRequest> request) {
start_event_.Signal(); start_event_.Signal();
request->WaitForResponse(); request->WaitForResponseOrCancelation();
done_event_.Signal(); done_event_.Signal();
} }
...@@ -1715,15 +1716,16 @@ void GetLocalChangesRequestTest::ScheduleBlockingWait( ...@@ -1715,15 +1716,16 @@ void GetLocalChangesRequestTest::ScheduleBlockingWait(
scoped_refptr<GetLocalChangesRequest> request) { scoped_refptr<GetLocalChangesRequest> request) {
blocking_thread_.task_runner()->PostTask( blocking_thread_.task_runner()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&GetLocalChangesRequestTest::BlockingWaitForResponse, base::BindOnce(
base::Unretained(this), request)); &GetLocalChangesRequestTest::BlockingWaitForResponseOrCancelation,
base::Unretained(this), request));
} }
// Tests that request doesn't block when cancelation signal is already signaled. // Tests that request doesn't block when cancelation signal is already signaled.
TEST_F(GetLocalChangesRequestTest, CancelationSignaledBeforeRequest) { TEST_F(GetLocalChangesRequestTest, CancelationSignaledBeforeRequest) {
cancelation_signal_.Signal(); cancelation_signal_.Signal();
auto request = MakeRequest(); auto request = MakeRequest();
request->WaitForResponse(); request->WaitForResponseOrCancelation();
EXPECT_TRUE(request->WasCancelled()); EXPECT_TRUE(request->WasCancelled());
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/sync/base/cancelation_signal.h" #include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/net/url_translator.h" #include "components/sync/engine_impl/net/url_translator.h"
#include "components/sync/engine_impl/syncer.h" #include "components/sync/engine_impl/syncer.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
......
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "components/sync/base/cancelation_observer.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/engine/net/http_post_provider_factory.h" #include "components/sync/engine/net/http_post_provider_factory.h"
#include "components/sync/engine/net/http_post_provider_interface.h" #include "components/sync/engine/net/http_post_provider_interface.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
...@@ -22,7 +21,7 @@ namespace { ...@@ -22,7 +21,7 @@ namespace {
// This provides HTTP Post functionality through the interface provided // This provides HTTP Post functionality through the interface provided
// by the application hosting the syncer backend. // by the application hosting the syncer backend.
class Connection : public CancelationObserver { class Connection : public CancelationSignal::Observer {
public: public:
// All pointers must not be null and must outlive this object. // All pointers must not be null and must outlive this object.
Connection(HttpPostProviderFactory* factory, Connection(HttpPostProviderFactory* factory,
...@@ -35,8 +34,8 @@ class Connection : public CancelationObserver { ...@@ -35,8 +34,8 @@ class Connection : public CancelationObserver {
bool ReadBufferResponse(std::string* buffer_out, HttpResponse* response); bool ReadBufferResponse(std::string* buffer_out, HttpResponse* response);
bool ReadDownloadResponse(HttpResponse* response, std::string* buffer_out); bool ReadDownloadResponse(HttpResponse* response, std::string* buffer_out);
// CancelationObserver overrides. // CancelationSignal::Observer overrides.
void OnSignalReceived() override; void OnCancelationSignalReceived() override;
private: private:
int ReadResponse(std::string* out_buffer, int length) const; int ReadResponse(std::string* out_buffer, int length) const;
...@@ -154,7 +153,7 @@ int Connection::ReadResponse(std::string* out_buffer, int length) const { ...@@ -154,7 +153,7 @@ int Connection::ReadResponse(std::string* out_buffer, int length) const {
return bytes_read; return bytes_read;
} }
void Connection::OnSignalReceived() { void Connection::OnCancelationSignalReceived() {
DCHECK(post_provider_); DCHECK(post_provider_);
post_provider_->Abort(); post_provider_->Abort();
} }
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/engine/net/http_post_provider_factory.h" #include "components/sync/engine/net/http_post_provider_factory.h"
#include "components/sync/engine/net/http_post_provider_interface.h" #include "components/sync/engine/net/http_post_provider_interface.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/values.h" #include "base/values.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/base/invalidation_interface.h" #include "components/sync/base/invalidation_interface.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
#include "components/sync/engine/configure_reason.h" #include "components/sync/engine/configure_reason.h"
...@@ -23,6 +22,7 @@ ...@@ -23,6 +22,7 @@
#include "components/sync/engine/engine_util.h" #include "components/sync/engine/engine_util.h"
#include "components/sync/engine/net/http_post_provider_factory.h" #include "components/sync/engine/net/http_post_provider_factory.h"
#include "components/sync/engine/polling_constants.h" #include "components/sync/engine/polling_constants.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/loopback_server/loopback_connection_manager.h" #include "components/sync/engine_impl/loopback_server/loopback_connection_manager.h"
#include "components/sync/engine_impl/model_type_connector_proxy.h" #include "components/sync/engine_impl/model_type_connector_proxy.h"
#include "components/sync/engine_impl/net/sync_server_connection_manager.h" #include "components/sync/engine_impl/net/sync_server_connection_manager.h"
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/test/values_test_util.h" #include "base/test/values_test_util.h"
#include "base/values.h" #include "base/values.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/base/client_tag_hash.h" #include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/extensions_activity.h" #include "components/sync/base/extensions_activity.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
...@@ -32,6 +31,7 @@ ...@@ -32,6 +31,7 @@
#include "components/sync/engine/net/http_post_provider_interface.h" #include "components/sync/engine/net/http_post_provider_interface.h"
#include "components/sync/engine/polling_constants.h" #include "components/sync/engine/polling_constants.h"
#include "components/sync/engine/test_engine_components_factory.h" #include "components/sync/engine/test_engine_components_factory.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/cycle/sync_cycle.h" #include "components/sync/engine_impl/cycle/sync_cycle.h"
#include "components/sync/engine_impl/sync_scheduler.h" #include "components/sync/engine_impl/sync_scheduler.h"
#include "components/sync/js/js_event_handler.h" #include "components/sync/js/js_event_handler.h"
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/base/extensions_activity.h" #include "components/sync/base/extensions_activity.h"
#include "components/sync/base/model_type_test_util.h" #include "components/sync/base/model_type_test_util.h"
#include "components/sync/engine/data_type_activation_response.h" #include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/engine/fake_model_type_processor.h" #include "components/sync/engine/fake_model_type_processor.h"
#include "components/sync/engine/sync_engine_switches.h" #include "components/sync/engine/sync_engine_switches.h"
#include "components/sync/engine_impl/backoff_delay_provider.h" #include "components/sync/engine_impl/backoff_delay_provider.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/cycle/test_util.h" #include "components/sync/engine_impl/cycle/test_util.h"
#include "components/sync/test/callback_counter.h" #include "components/sync/test/callback_counter.h"
#include "components/sync/test/engine/mock_connection_manager.h" #include "components/sync/test/engine/mock_connection_manager.h"
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/engine/sync_engine_switches.h" #include "components/sync/engine/sync_engine_switches.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/commit.h" #include "components/sync/engine_impl/commit.h"
#include "components/sync/engine_impl/commit_processor.h" #include "components/sync/engine_impl/commit_processor.h"
#include "components/sync/engine_impl/cycle/nudge_tracker.h" #include "components/sync/engine_impl/cycle/nudge_tracker.h"
......
...@@ -25,13 +25,13 @@ ...@@ -25,13 +25,13 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/sync/base/cancelation_signal.h"
#include "components/sync/base/client_tag_hash.h" #include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/extensions_activity.h" #include "components/sync/base/extensions_activity.h"
#include "components/sync/base/time.h" #include "components/sync/base/time.h"
#include "components/sync/engine/data_type_activation_response.h" #include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/engine/forwarding_model_type_processor.h" #include "components/sync/engine/forwarding_model_type_processor.h"
#include "components/sync/engine_impl/backoff_delay_provider.h" #include "components/sync/engine_impl/backoff_delay_provider.h"
#include "components/sync/engine_impl/cancelation_signal.h"
#include "components/sync/engine_impl/cycle/mock_debug_info_getter.h" #include "components/sync/engine_impl/cycle/mock_debug_info_getter.h"
#include "components/sync/engine_impl/cycle/sync_cycle_context.h" #include "components/sync/engine_impl/cycle/sync_cycle_context.h"
#include "components/sync/engine_impl/net/server_connection_manager.h" #include "components/sync/engine_impl/net/server_connection_manager.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment