diff options
Diffstat (limited to 'sync')
-rw-r--r-- | sync/internal_api/http_bridge.cc | 6 | ||||
-rw-r--r-- | sync/internal_api/http_bridge_unittest.cc | 29 |
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 |