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

Unified Diff: components/update_client/request_sender.cc

Issue 808773005: Move most of the component updater artifacts to update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « components/update_client/request_sender.h ('k') | components/update_client/test/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/update_client/request_sender.cc
diff --git a/components/update_client/request_sender.cc b/components/update_client/request_sender.cc
new file mode 100644
index 0000000000000000000000000000000000000000..726c2faea6d23174d9ccb80048832106033a6e9d
--- /dev/null
+++ b/components/update_client/request_sender.cc
@@ -0,0 +1,70 @@
+// 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/update_client/request_sender.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
+#include "components/update_client/configurator.h"
+#include "components/update_client/utils.h"
+#include "net/url_request/url_fetcher.h"
+
+namespace update_client {
+
+RequestSender::RequestSender(const Configurator& config) : config_(config) {
+}
+
+RequestSender::~RequestSender() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+void RequestSender::Send(const std::string& request_string,
+ const std::vector<GURL>& urls,
+ const RequestSenderCallback& request_sender_callback) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (urls.empty()) {
+ request_sender_callback.Run(NULL);
+ return;
+ }
+
+ request_string_ = request_string;
+ urls_ = urls;
+ request_sender_callback_ = request_sender_callback;
+
+ cur_url_ = urls_.begin();
+
+ SendInternal();
+}
+
+void RequestSender::SendInternal() {
+ DCHECK(cur_url_ != urls_.end());
+ DCHECK(cur_url_->is_valid());
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ url_fetcher_.reset(SendProtocolRequest(*cur_url_, request_string_, this,
+ config_.RequestContext()));
+}
+
+void RequestSender::OnURLFetchComplete(const net::URLFetcher* source) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (GetFetchError(*source) == 0) {
+ request_sender_callback_.Run(source);
+ return;
+ }
+
+ if (++cur_url_ != urls_.end() &&
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestSender::SendInternal, base::Unretained(this)))) {
+ return;
+ }
+
+ request_sender_callback_.Run(source);
+}
+
+} // namespace update_client
« no previous file with comments | « components/update_client/request_sender.h ('k') | components/update_client/test/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698