diff options
author | haitaol@chromium.org <haitaol@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-11 21:19:26 +0000 |
---|---|---|
committer | haitaol@chromium.org <haitaol@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-11 21:19:26 +0000 |
commit | 21c028f2174b2003d8a1cbccba54420438dd4496 (patch) | |
tree | 165ec3f72db625e49ad3b729da622f0d43e7950c /sync/internal_api/http_bridge_unittest.cc | |
parent | 6c2769a73de69e1d82e59f11a0bcf4103097bb01 (diff) | |
download | chromium_src-21c028f2174b2003d8a1cbccba54420438dd4496.zip chromium_src-21c028f2174b2003d8a1cbccba54420438dd4496.tar.gz chromium_src-21c028f2174b2003d8a1cbccba54420438dd4496.tar.bz2 |
Release sync's RequestContextGetter as soon as possible
This lets its RequestContext object be destroyed in the right order during shutdown.
BUG=236451
Review URL: https://chromiumcodereview.appspot.com/22901013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222633 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api/http_bridge_unittest.cc')
-rw-r--r-- | sync/internal_api/http_bridge_unittest.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/sync/internal_api/http_bridge_unittest.cc b/sync/internal_api/http_bridge_unittest.cc index c72f479..9cb37df 100644 --- a/sync/internal_api/http_bridge_unittest.cc +++ b/sync/internal_api/http_bridge_unittest.cc @@ -405,4 +405,81 @@ TEST_F(SyncHttpBridgeTest, AbortAndReleaseBeforeFetchComplete) { io_thread()->Stop(); } +void HttpBridgeRunOnSyncThread( + net::URLRequestContextGetter* baseline_context_getter, + syncer::HttpPostProviderFactory** bridge_factory_out, + syncer::HttpPostProviderInterface** bridge_out, + base::WaitableEvent* signal_when_created, + base::WaitableEvent* wait_for_shutdown) { + scoped_ptr<syncer::HttpPostProviderFactory> bridge_factory( + new syncer::HttpBridgeFactory(baseline_context_getter, + "test", + NetworkTimeUpdateCallback())); + *bridge_factory_out = bridge_factory.get(); + + HttpPostProviderInterface* bridge = bridge_factory->Create(); + *bridge_out = bridge; + + signal_when_created->Signal(); + wait_for_shutdown->Wait(); + + bridge_factory->Destroy(bridge); +} + +void WaitOnIOThread(base::WaitableEvent* signal_wait_start, + base::WaitableEvent* wait_done) { + signal_wait_start->Signal(); + wait_done->Wait(); +} + +// Tests RequestContextGetter is properly released on IO thread even when +// IO thread stops before sync thread. +TEST_F(SyncHttpBridgeTest, RequestContextGetterReleaseOrder) { + base::Thread sync_thread("SyncThread"); + sync_thread.Start(); + + syncer::HttpPostProviderFactory* factory = NULL; + syncer::HttpPostProviderInterface* bridge = NULL; + + scoped_refptr<net::URLRequestContextGetter> baseline_context_getter( + new net::TestURLRequestContextGetter(io_thread()->message_loop_proxy())); + + base::WaitableEvent signal_when_created(false, false); + base::WaitableEvent wait_for_shutdown(false, false); + + // Create bridge factory and factory on sync thread and wait for the creation + // to finish. + sync_thread.message_loop()->PostTask(FROM_HERE, + base::Bind(&HttpBridgeRunOnSyncThread, + base::Unretained(baseline_context_getter.get()), + &factory, &bridge, &signal_when_created, &wait_for_shutdown)); + signal_when_created.Wait(); + + // Simulate sync shutdown by aborting bridge and shutting down factory on + // frontend. + bridge->Abort(); + factory->Shutdown(); + + // Wait for sync's RequestContextGetter to be cleared on IO thread and + // check for reference count. + base::WaitableEvent signal_wait_start(false, false); + base::WaitableEvent wait_done(false, false); + io_thread()->message_loop()->PostTask( + FROM_HERE, + base::Bind(&WaitOnIOThread, &signal_wait_start, &wait_done)); + signal_wait_start.Wait(); + // |baseline_context_getter| should have only one reference from local + // variable. + EXPECT_TRUE(baseline_context_getter->HasOneRef()); + baseline_context_getter = NULL; + + // Unblock and stop IO thread before sync thread. + wait_done.Signal(); + io_thread()->Stop(); + + // Unblock and stop sync thread. + wait_for_shutdown.Signal(); + sync_thread.Stop(); +} + } // namespace syncer |