| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_ |
| 6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 class GURL; | 10 class GURL; |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 class URLFetcher; | 13 class URLFetcher; |
| 14 class URLFetcherDelegate; | 14 class URLFetcherDelegate; |
| 15 class URLRequestContextGetter; | 15 class URLRequestContextGetter; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace component_updater { | 18 namespace component_updater { |
| 19 | 19 |
| 20 // An update protocol request starts with a common preamble which includes | 20 // An update protocol request starts with a common preamble which includes |
| 21 // version and platform information for Chrome and the operating system, | 21 // version and platform information for Chrome and the operating system, |
| 22 // followed by a request body, which is the actual payload of the request. | 22 // followed by a request body, which is the actual payload of the request. |
| 23 // For example: | 23 // For example: |
| 24 // | 24 // |
| 25 // <?xml version="1.0" encoding="UTF-8"?> | 25 // <?xml version="1.0" encoding="UTF-8"?> |
| 26 // <request protocol="3.0" version="chrome-32.0.1.0" prodversion="32.0.1.0" | 26 // <request protocol="3.0" version="chrome-32.0.1.0" prodversion="32.0.1.0" |
| 27 // requestid="{7383396D-B4DD-46E1-9104-AAC6B918E792}" | 27 // requestid="{7383396D-B4DD-46E1-9104-AAC6B918E792}" |
| 28 // updaterchannel="canary" arch="x86" nacl_arch="x86-64"> | 28 // updaterchannel="canary" arch="x86" nacl_arch="x86-64" |
| 29 // ADDITIONAL ATTRIBUTES> |
| 29 // <os platform="win" version="6.1" arch="x86"/> | 30 // <os platform="win" version="6.1" arch="x86"/> |
| 30 // ... REQUEST BODY ... | 31 // ... REQUEST BODY ... |
| 31 // </request> | 32 // </request> |
| 32 | 33 |
| 33 // Builds a protocol request string by creating the outer envelope for | 34 // Builds a protocol request string by creating the outer envelope for |
| 34 // the request and including the request body specified as a parameter. | 35 // the request and including the request body specified as a parameter. |
| 35 std::string BuildProtocolRequest(const std::string& request_body); | 36 // If specified, |additional_attributes| are appended as attributes of the |
| 37 // request element. |
| 38 std::string BuildProtocolRequest(const std::string& request_body, |
| 39 const std::string& additional_attributes); |
| 36 | 40 |
| 37 // Sends a protocol request to the the service endpoint specified by |url|. | 41 // Sends a protocol request to the the service endpoint specified by |url|. |
| 38 // The body of the request is provided by |protocol_request| and it is | 42 // The body of the request is provided by |protocol_request| and it is |
| 39 // expected to contain XML data. The caller owns the returned object. | 43 // expected to contain XML data. The caller owns the returned object. |
| 40 net::URLFetcher* SendProtocolRequest( | 44 net::URLFetcher* SendProtocolRequest( |
| 41 const GURL& url, | 45 const GURL& url, |
| 42 const std::string& protocol_request, | 46 const std::string& protocol_request, |
| 43 net::URLFetcherDelegate* url_fetcher_delegate, | 47 net::URLFetcherDelegate* url_fetcher_delegate, |
| 44 net::URLRequestContextGetter* url_request_context_getter); | 48 net::URLRequestContextGetter* url_request_context_getter); |
| 45 | 49 |
| 46 // Returns true if the url request of |fetcher| was succesful. | 50 // Returns true if the url request of |fetcher| was succesful. |
| 47 bool FetchSuccess(const net::URLFetcher& fetcher); | 51 bool FetchSuccess(const net::URLFetcher& fetcher); |
| 48 | 52 |
| 49 // Returns the error code which occured during the fetch. The function returns 0 | 53 // Returns the error code which occured during the fetch. The function returns 0 |
| 50 // if the fetch was successful. If errors happen, the function could return a | 54 // if the fetch was successful. If errors happen, the function could return a |
| 51 // network error, an http response code, or the status of the fetch, if the | 55 // network error, an http response code, or the status of the fetch, if the |
| 52 // fetch is pending or canceled. | 56 // fetch is pending or canceled. |
| 53 int GetFetchError(const net::URLFetcher& fetcher); | 57 int GetFetchError(const net::URLFetcher& fetcher); |
| 54 | 58 |
| 55 // Returns true if the |status_code| represents a server error 5xx. | 59 // Returns true if the |status_code| represents a server error 5xx. |
| 56 bool IsHttpServerError(int status_code); | 60 bool IsHttpServerError(int status_code); |
| 57 | 61 |
| 58 } // namespace component_updater | 62 } // namespace component_updater |
| 59 | 63 |
| 60 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_ | 64 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_UTILS_H_ |
| 61 | 65 |
| OLD | NEW |