Chromium Code Reviews| Index: components/component_updater/request_sender.h |
| diff --git a/components/component_updater/request_sender.h b/components/component_updater/request_sender.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..592aca4f930cac632804f4e60daa71cc5d0fa486 |
| --- /dev/null |
| +++ b/components/component_updater/request_sender.h |
| @@ -0,0 +1,56 @@ |
| +// 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. |
| + |
| +#ifndef COMPONENTS_COMPONENT_UPDATER_REQUEST_SENDER_H_ |
| +#define COMPONENTS_COMPONENT_UPDATER_REQUEST_SENDER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| +#include "url/gurl.h" |
| + |
| +namespace component_updater { |
| + |
| +class Configurator; |
| + |
| +// Sends a request to one of the urls provided. The class implements a chain |
| +// of responsibility design pattern, where the urls are tried in the order they |
| +// are specified, until the request to one of them succeeds or all have failed. |
| +class RequestSender : public net::URLFetcherDelegate { |
| + public: |
| + // The |source| refers to the fetcher object used to make the request. This |
| + // parameter can be NULL in some error cases. |
| + typedef base::Callback<void(const net::URLFetcher* source)> |
| + RequestSenderCallback; |
| + |
| + RequestSender(const Configurator& config, const std::vector<GURL>& urls); |
|
waffles
2014/09/12 22:38:26
Yeah, as you mentioned this seems strange. Maybe w
Sorin Jianu
2014/09/12 23:24:00
I will move the urls param to the Send function. W
|
| + |
| + void Send(const std::string& request_string, |
| + const RequestSenderCallback& request_sender_callback); |
| + |
| + private: |
| + void SendInternal(); |
| + |
| + // Overrides for URLFetcherDelegate. |
| + virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| + |
| + const Configurator& config_; |
| + const std::vector<GURL> urls_; |
| + std::vector<GURL>::const_iterator cur_url_; |
| + scoped_ptr<net::URLFetcher> url_fetcher_; |
| + std::string request_string_; |
| + RequestSenderCallback request_sender_callback_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RequestSender); |
| +}; |
| + |
| +} // namespace component_updater |
| + |
| +#endif // COMPONENTS_COMPONENT_UPDATER_REQUEST_SENDER_H_ |