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

Side by Side Diff: components/update_client/request_sender.h

Issue 1740333002: Allow fallback from https to http for component update checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_ 5 #ifndef COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_
6 #define COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_ 6 #define COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_
7 7
8 #include <stdint.h>
9
8 #include <string> 10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/callback.h" 13 #include "base/callback.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
16 #include "net/url_request/url_fetcher_delegate.h" 18 #include "net/url_request/url_fetcher_delegate.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
(...skipping 10 matching lines...) Expand all
28 30
29 class Configurator; 31 class Configurator;
30 32
31 // Sends a request to one of the urls provided. The class implements a chain 33 // Sends a request to one of the urls provided. The class implements a chain
32 // of responsibility design pattern, where the urls are tried in the order they 34 // of responsibility design pattern, where the urls are tried in the order they
33 // are specified, until the request to one of them succeeds or all have failed. 35 // are specified, until the request to one of them succeeds or all have failed.
34 // CUP signing is optional. 36 // CUP signing is optional.
35 class RequestSender : public net::URLFetcherDelegate { 37 class RequestSender : public net::URLFetcherDelegate {
36 public: 38 public:
37 // If |error| is 0, then the response is provided in the |response| parameter. 39 // If |error| is 0, then the response is provided in the |response| parameter.
38 using RequestSenderCallback = 40 // |retry_after_sec| contains the value of the X-Retry-After response header,
39 base::Callback<void(int error, const std::string& response)>; 41 // when the response was received from a cryptographically secure URL. The
42 // range for this value is [-1, 86400]. If |retry_after_sec| is -1 it means
43 // that the header could not be found, or trusted, or had an invalid value.
44 // The upper bound represents a delay of one day.
45 using RequestSenderCallback = base::Callback<
46 void(int error, const std::string& response, int retry_after_sec)>;
40 47
41 static int kErrorResponseNotTrusted; 48 static int kErrorResponseNotTrusted;
42 49
43 explicit RequestSender(const scoped_refptr<Configurator>& config); 50 explicit RequestSender(const scoped_refptr<Configurator>& config);
44 ~RequestSender() override; 51 ~RequestSender() override;
45 52
46 // |use_signing| enables CUP signing of protocol messages exchanged using 53 // |use_signing| enables CUP signing of protocol messages exchanged using
47 // this class. 54 // this class.
48 void Send(bool use_signing, 55 void Send(bool use_signing,
49 const std::string& request_body, 56 const std::string& request_body,
50 const std::vector<GURL>& urls, 57 const std::vector<GURL>& urls,
51 const RequestSenderCallback& request_sender_callback); 58 const RequestSenderCallback& request_sender_callback);
52 59
53 private: 60 private:
54 // Combines the |url| and |query_params| parameters. 61 // Combines the |url| and |query_params| parameters.
55 static GURL BuildUpdateUrl(const GURL& url, const std::string& query_params); 62 static GURL BuildUpdateUrl(const GURL& url, const std::string& query_params);
56 63
57 // Decodes and returns the public key used by CUP. 64 // Decodes and returns the public key used by CUP.
58 static std::string GetKey(const char* key_bytes_base64); 65 static std::string GetKey(const char* key_bytes_base64);
59 66
60 // Returns the Etag of the server response or an empty string if the 67 // Returns the string value of a header of the server response or an empty
61 // Etag is not available. 68 // string if the header is not available.
62 static std::string GetServerETag(const net::URLFetcher* source); 69 static std::string GetStringHeaderValue(const net::URLFetcher* source,
70 const char* header_name);
71
72 // Returns the integral value of a header of the server response or -1 if
73 // if the header is not available or a conversion error has occured.
74 static int64_t GetInt64HeaderValue(const net::URLFetcher* source,
75 const char* header_name);
63 76
64 // Overrides for URLFetcherDelegate. 77 // Overrides for URLFetcherDelegate.
65 void OnURLFetchComplete(const net::URLFetcher* source) override; 78 void OnURLFetchComplete(const net::URLFetcher* source) override;
66 79
67 // Implements the error handling and url fallback mechanism. 80 // Implements the error handling and url fallback mechanism.
68 void SendInternal(); 81 void SendInternal();
69 82
70 // Called when SendInternal complets. |response_body|and |response_etag| 83 // Called when SendInternal completes. |response_body| and |response_etag|
71 // contain the body and the etag associated with the HTTP response. 84 // contain the body and the etag associated with the HTTP response.
72 void SendInternalComplete(int error, 85 void SendInternalComplete(int error,
73 const std::string& response_body, 86 const std::string& response_body,
74 const std::string& response_etag); 87 const std::string& response_etag,
88 int retry_after_sec);
75 89
76 // Helper function to handle a non-continuable error in Send. 90 // Helper function to handle a non-continuable error in Send.
77 void HandleSendError(int error); 91 void HandleSendError(int error, int retry_after_sec);
78 92
79 base::ThreadChecker thread_checker_; 93 base::ThreadChecker thread_checker_;
80 94
81 const scoped_refptr<Configurator> config_; 95 const scoped_refptr<Configurator> config_;
82 bool use_signing_; 96 bool use_signing_; // True if CUP signing is used.
83 std::vector<GURL> urls_; 97 std::vector<GURL> urls_;
84 std::string request_body_; 98 std::string request_body_;
85 RequestSenderCallback request_sender_callback_; 99 RequestSenderCallback request_sender_callback_;
86 100
87 std::string public_key_; 101 std::string public_key_;
88 std::vector<GURL>::const_iterator cur_url_; 102 std::vector<GURL>::const_iterator cur_url_;
89 scoped_ptr<net::URLFetcher> url_fetcher_; 103 scoped_ptr<net::URLFetcher> url_fetcher_;
90 scoped_ptr<client_update_protocol::Ecdsa> signer_; 104 scoped_ptr<client_update_protocol::Ecdsa> signer_;
91 105
92 DISALLOW_COPY_AND_ASSIGN(RequestSender); 106 DISALLOW_COPY_AND_ASSIGN(RequestSender);
93 }; 107 };
94 108
95 } // namespace update_client 109 } // namespace update_client
96 110
97 #endif // COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_ 111 #endif // COMPONENTS_UPDATE_CLIENT_REQUEST_SENDER_H_
OLDNEW
« no previous file with comments | « components/update_client/ping_manager_unittest.cc ('k') | components/update_client/request_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698