1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_COMPONENT_UPDATER_REQUEST_SENDER_H_
6 #define COMPONENTS_COMPONENT_UPDATER_REQUEST_SENDER_H_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "net/url_request/url_fetcher_delegate.h"
22 namespace component_updater {
26 // Sends a request to one of the urls provided. The class implements a chain
27 // of responsibility design pattern, where the urls are tried in the order they
28 // are specified, until the request to one of them succeeds or all have failed.
29 class RequestSender : public net::URLFetcherDelegate {
31 // The |source| refers to the fetcher object used to make the request. This
32 // parameter can be NULL in some error cases.
33 typedef base::Callback<void(const net::URLFetcher* source)>
34 RequestSenderCallback;
36 explicit RequestSender(const Configurator& config);
37 ~RequestSender() override;
39 void Send(const std::string& request_string,
40 const std::vector<GURL>& urls,
41 const RequestSenderCallback& request_sender_callback);
46 // Overrides for URLFetcherDelegate.
47 void OnURLFetchComplete(const net::URLFetcher* source) override;
49 const Configurator& config_;
50 std::vector<GURL> urls_;
51 std::vector<GURL>::const_iterator cur_url_;
52 scoped_ptr<net::URLFetcher> url_fetcher_;
53 std::string request_string_;
54 RequestSenderCallback request_sender_callback_;
56 DISALLOW_COPY_AND_ASSIGN(RequestSender);
59 } // namespace component_updater
61 #endif // COMPONENTS_COMPONENT_UPDATER_REQUEST_SENDER_H_