Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: sync/internal_api/http_bridge.cc

Issue 23717047: Retry: sync: Gracefully handle early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/engine/syncer_unittest.cc ('k') | sync/internal_api/http_bridge_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/http_bridge.cc
diff --git a/sync/internal_api/http_bridge.cc b/sync/internal_api/http_bridge.cc
index 0b3697fb4b24e02ef6c8bb460069ed4977140496..48305eb0c9c6147216db09ffafeebd08effa76d6 100644
--- a/sync/internal_api/http_bridge.cc
+++ b/sync/internal_api/http_bridge.cc
@@ -19,6 +19,7 @@
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_status.h"
+#include "sync/internal_api/public/base/cancelation_signal.h"
namespace syncer {
@@ -58,20 +59,45 @@ HttpBridge::RequestContextGetter::GetNetworkTaskRunner() const {
HttpBridgeFactory::HttpBridgeFactory(
net::URLRequestContextGetter* baseline_context_getter,
- const std::string& user_agent,
- const NetworkTimeUpdateCallback& network_time_update_callback)
- : request_context_getter_(
- new HttpBridge::RequestContextGetter(
- baseline_context_getter, user_agent)),
- network_time_update_callback_(network_time_update_callback) {
+ const NetworkTimeUpdateCallback& network_time_update_callback,
+ CancelationSignal* cancelation_signal)
+ : baseline_request_context_getter_(baseline_context_getter),
+ network_time_update_callback_(network_time_update_callback),
+ cancelation_signal_(cancelation_signal) {
+ // Registration should never fail. This should happen on the UI thread during
+ // init. It would be impossible for a shutdown to have been requested at this
+ // point.
+ bool result = cancelation_signal_->TryRegisterHandler(this);
+ DCHECK(result);
}
HttpBridgeFactory::~HttpBridgeFactory() {
+ cancelation_signal_->UnregisterHandler(this);
+}
+
+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.
+ }
+
+ request_context_getter_ =
+ new HttpBridge::RequestContextGetter(
+ baseline_request_context_getter_, user_agent);
}
HttpPostProviderInterface* HttpBridgeFactory::Create() {
base::AutoLock lock(context_getter_lock_);
+
+ // If we've been asked to shut down (something which may happen asynchronously
+ // and at pretty much any time), then we won't have a request_context_getter_.
+ // Some external mechanism must ensure that this function is not called after
+ // we've been asked to shut down.
CHECK(request_context_getter_.get());
+
HttpBridge* http = new HttpBridge(request_context_getter_.get(),
network_time_update_callback_);
http->AddRef();
@@ -82,10 +108,13 @@ void HttpBridgeFactory::Destroy(HttpPostProviderInterface* http) {
static_cast<HttpBridge*>(http)->Release();
}
-void HttpBridgeFactory::Shutdown() {
+void HttpBridgeFactory::OnSignalReceived() {
base::AutoLock lock(context_getter_lock_);
- // Release |request_context_getter_| as soon as possible so that it is
- // destroyed in the right order on its network task runner.
+ // Release |baseline_request_context_getter_| as soon as possible so that it
+ // is destroyed in the right order on its network task runner. The
+ // |request_context_getter_| has a reference to the baseline, so we must
+ // drop our reference to it, too.
+ baseline_request_context_getter_ = NULL;
request_context_getter_ = NULL;
}
« no previous file with comments | « sync/engine/syncer_unittest.cc ('k') | sync/internal_api/http_bridge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698