summaryrefslogtreecommitdiffstats
path: root/sync/engine/syncer.h
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 00:39:48 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 00:39:48 +0000
commit33c1f53914a7a15b51cb226f572f5439e8ef9249 (patch)
tree553286bc9bc1966e753bbc6e1f703fbaab96f886 /sync/engine/syncer.h
parent98f936181964f99cd0c73707cfd9027d0c528702 (diff)
downloadchromium_src-33c1f53914a7a15b51cb226f572f5439e8ef9249.zip
chromium_src-33c1f53914a7a15b51cb226f572f5439e8ef9249.tar.gz
chromium_src-33c1f53914a7a15b51cb226f572f5439e8ef9249.tar.bz2
sync: Gracefully handle very early shutdown
Introduce a new object to communicate cross-thread cancellation signals. This new object, the CancellationSignal, is protected by a lock. It allows the receiving thread to query whether or not a stop has been requested. It also allows the receiving thread to safely register a cross-thread callback to be invoked immediately when a stop is requested. This class is used to reimplement the UI thread to sync thread early shutdown signal. Previously, the UI thread would try to call in to objects owned by the sync thread. This required a workaround if the signal arrived very early, since we couldn't guarantee the sync thread had actually created those objects until later. The CancellationSignal is owned by the UI thread, so it is safe to call its RequestStop() at any point during sync initialization. The sync thread will receive the signal when it's ready. The new scheme has a few advantages over the old: - Thread ownership is simpler. The SyncBackendHost::Core, SyncManager, ServerConnectionManager, SyncScheduler and Syncer can now claim that all their member functions run on the sync thread. - We no longer need to implement special case logic for when a shutdown is requested before the SyncManager has initialized. - In a future CL, we can take advantage of the fact that we no longer require the special case to reduce inter-thread communication during sync startup. This will make startup simpler and, in some cases, improve sync startup time by as much as a few hundred milliseconds. - This will make it easier to address crbug.com/236451. BUG=236451 Review URL: https://chromiumcodereview.appspot.com/23189021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine/syncer.h')
-rw-r--r--sync/engine/syncer.h10
1 files changed, 4 insertions, 6 deletions
diff --git a/sync/engine/syncer.h b/sync/engine/syncer.h
index e1e5eac..132f6ef 100644
--- a/sync/engine/syncer.h
+++ b/sync/engine/syncer.h
@@ -21,6 +21,8 @@
namespace syncer {
+class CancelationSignal;
+
// A Syncer provides a control interface for driving the individual steps
// of the sync cycle. Each cycle (hopefully) moves the client into closer
// synchronization with the server. The individual steps are modeled
@@ -35,13 +37,10 @@ class SYNC_EXPORT_PRIVATE Syncer {
public:
typedef std::vector<int64> UnsyncedMetaHandles;
- Syncer();
+ Syncer(CancelationSignal* cancelation_signal);
virtual ~Syncer();
- // Called by other threads to tell the syncer to stop what it's doing
- // and return early from SyncShare, if possible.
bool ExitRequested();
- void RequestEarlyExit();
// Fetches and applies updates, resolves conflicts and commits local changes
// for |request_types| as necessary until client and server states are in
@@ -79,8 +78,7 @@ class SYNC_EXPORT_PRIVATE Syncer {
sessions::SyncSession* session,
sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
- bool early_exit_requested_;
- base::Lock early_exit_requested_lock_;
+ syncer::CancelationSignal* const cancelation_signal_;
friend class SyncerTest;
FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);