summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-03 18:08:40 +0000
committerrlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-03 18:08:40 +0000
commit4c275624c6486dcc812247236cab693502702bf1 (patch)
tree31c8a598d4d3d9b01ff6e0767715d8f8ee30dcdd /sync
parent0e9e028999178e71020e5c9223cebad9f93c83b9 (diff)
downloadchromium_src-4c275624c6486dcc812247236cab693502702bf1.zip
chromium_src-4c275624c6486dcc812247236cab693502702bf1.tar.gz
chromium_src-4c275624c6486dcc812247236cab693502702bf1.tar.bz2
sync: Fix bug in early sync shutdown
In r224014, we tried to fix many issues with early shutdown. That CL contained a fairly serious bug that would cause shutdown requests that arrive very early to trigger a crash. This patch fixes that bug and adds a test to help prevent regressions. BUG=236451,303177 Review URL: https://codereview.chromium.org/25794002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/internal_api/http_bridge.cc6
-rw-r--r--sync/internal_api/http_bridge_unittest.cc29
2 files changed, 32 insertions, 3 deletions
diff --git a/sync/internal_api/http_bridge.cc b/sync/internal_api/http_bridge.cc
index 48305eb..5827c9d 100644
--- a/sync/internal_api/http_bridge.cc
+++ b/sync/internal_api/http_bridge.cc
@@ -79,9 +79,9 @@ void HttpBridgeFactory::Init(const std::string& user_agent) {
base::AutoLock lock(context_getter_lock_);
if (!baseline_request_context_getter_.get()) {
- // Uh oh. We've been aborted before we finsihed initializing.
- // There's no point in initializating further; let's just return
- // right away.
+ // Uh oh. We've been aborted before we finished initializing. There's no
+ // point in initializating further; let's just return right away.
+ return;
}
request_context_getter_ =
diff --git a/sync/internal_api/http_bridge_unittest.cc b/sync/internal_api/http_bridge_unittest.cc
index e1dc6de..5dd39bb 100644
--- a/sync/internal_api/http_bridge_unittest.cc
+++ b/sync/internal_api/http_bridge_unittest.cc
@@ -488,4 +488,33 @@ TEST_F(SyncHttpBridgeTest, RequestContextGetterReleaseOrder) {
sync_thread.Stop();
}
+// Attempt to release the URLRequestContextGetter before the HttpBridgeFactory
+// is initialized.
+TEST_F(SyncHttpBridgeTest, EarlyAbortFactory) {
+ // In a real scenario, the following would happen on many threads. For
+ // simplicity, this test uses only one thread.
+
+ scoped_refptr<net::URLRequestContextGetter> baseline_context_getter(
+ new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy()));
+ CancelationSignal release_request_context_signal;
+
+ // UI Thread: Initialize the HttpBridgeFactory. The next step would be to
+ // post a task to SBH::Core to have it initialized.
+ scoped_ptr<syncer::HttpBridgeFactory> factory(new HttpBridgeFactory(
+ baseline_context_getter,
+ NetworkTimeUpdateCallback(),
+ &release_request_context_signal));
+
+ // UI Thread: A very early shutdown request arrives and executes on the UI
+ // thread before the posted sync thread task is run.
+ release_request_context_signal.Signal();
+
+ // Sync thread: Finally run the posted task, only to find that our
+ // HttpBridgeFactory has been neutered. Should not crash.
+ factory->Init("TestUserAgent");
+
+ // At this point, attempting to use the factory would trigger a crash. Both
+ // this test and the real world code should make sure this never happens.
+};
+
} // namespace syncer