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

Unified Diff: components/component_updater/request_sender.cc

Issue 565363002: Implement support for fallback update check urls in the component updater (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 6 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
Index: components/component_updater/request_sender.cc
diff --git a/components/component_updater/request_sender.cc b/components/component_updater/request_sender.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca6737155347c193ba99c251cdc73910d44f93c1
--- /dev/null
+++ b/components/component_updater/request_sender.cc
@@ -0,0 +1,59 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/component_updater/request_sender.h"
+
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/sequenced_task_runner.h"
+#include "components/component_updater/component_updater_configurator.h"
+#include "components/component_updater/component_updater_utils.h"
+
+namespace component_updater {
+
+RequestSender::RequestSender(const Configurator& config,
+ const std::vector<GURL>& urls)
+ : config_(config), urls_(urls) {
+}
+
+void RequestSender::Send(const std::string& request_string,
+ const RequestSenderCallback& request_sender_callback) {
+ if (urls_.empty()) {
+ request_sender_callback.Run(NULL);
+ return;
+ }
+
+ request_sender_callback_ = request_sender_callback;
+ request_string_ = request_string;
+
+ cur_url_ = urls_.begin();
+
+ SendInternal();
+}
+
+void RequestSender::SendInternal() {
+ DCHECK(cur_url_ != urls_.end());
+ DCHECK(cur_url_->is_valid());
+
+ url_fetcher_.reset(SendProtocolRequest(
+ *cur_url_, request_string_, this, config_.RequestContext()));
+}
+
+void RequestSender::OnURLFetchComplete(const net::URLFetcher* source) {
waffles 2014/09/12 22:38:26 What thread does this occur on? Is it OK to .Run t
Sorin Jianu 2014/09/12 23:24:00 The fetcher is thread safe, the call will occur on
+ if (GetFetchError(*source) == 0) {
+ request_sender_callback_.Run(source);
+ return;
+ }
+
+ if (++cur_url_ != urls_.end() &&
+ config_.GetSequencedTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestSender::SendInternal, base::Unretained(this)))) {
+ return;
+ }
+
+ request_sender_callback_.Run(source);
+}
+
+} // namespace component_updater

Powered by Google App Engine
This is Rietveld 408576698