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-19 01:17:02 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-19 01:17:02 +0000
commitea29851b736ba58190146f5ce0bef59683ad8904 (patch)
treed5dea3dc7483b2d65601d87304b3282189f3dbb5 /sync/engine/syncer.h
parent4f432a56da54cdbe213ae943944599072a690c75 (diff)
downloadchromium_src-ea29851b736ba58190146f5ce0bef59683ad8904.zip
chromium_src-ea29851b736ba58190146f5ce0bef59683ad8904.tar.gz
chromium_src-ea29851b736ba58190146f5ce0bef59683ad8904.tar.bz2
sync: Gracefully handle 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. We use two instances of this class to ensure we meet all the requirements for a safe and fast sync backend shutdown. The first instance is used with the HttpBridgeFactory to allow the UI thread to force it to drop all refereces to its RequestContextGetter immediately. This is an important part of our plan to ensure that all references to that object are released before ProfileSyncService::Shutdown() returns, which is necessary to avoid racy crashes at shutdown. (See crbug.com/236451) The second instance is used with the ServerConnectionManager and the Syncer. Once signalled, it ensures that any active connections are released (possibly decrementing another ref to the RequestContextGetter), that any blocking I/O is aborted, and that no more connections will be instantiated. It's important to prevent the creation of more connections because the HttpBridgeFactory might trigger a crash if we asked it to create another connection after it had been shut down. The syncer's interaction with the second cancelation signal is more passive. It does not execute any callbacks when the signal is sent. Instead, it queries the signal as it performs sync cycles, and will cut short any existing sync cycle if it notices the signal has been sent. Finally, this CL includes one important change to the initialization of the HttpBridgeFactory. In order to properly register with the cancellation signal while still allowing the creation of the user agent to occur on the sync thread, its initialization had to be split into two parts. This class now has an Init() method in addition to its constructor. BUG=236451 Review URL: https://chromiumcodereview.appspot.com/23717047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224014 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);