Chromium Code Reviews| 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 |