[email protected] | de0fdca2 | 2014-08-19 05:26:09 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 5 | #ifndef COMPONENTS_UPDATE_CLIENT_UTILS_H_ |
| 6 | #define COMPONENTS_UPDATE_CLIENT_UTILS_H_ |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 7 | |
dcheng | d0fc6aa9 | 2016-04-22 18:03:12 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 9 | #include <string> |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 10 | #include <utility> |
sorin | fccbf2d | 2016-04-04 20:34:34 | [diff] [blame] | 11 | #include <vector> |
tfarina | be264fa | 2016-01-11 19:55:01 | [diff] [blame] | 12 | |
sorin | 2892f721 | 2016-11-07 18:59:43 | [diff] [blame] | 13 | #include "base/callback_forward.h" |
| 14 | #include "components/update_client/update_client.h" |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 15 | |
| 16 | class GURL; |
| 17 | |
[email protected] | 2e2c529 | 2013-12-17 03:48:40 | [diff] [blame] | 18 | namespace base { |
| 19 | class FilePath; |
| 20 | } |
| 21 | |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 22 | namespace net { |
| 23 | class URLFetcher; |
| 24 | class URLFetcherDelegate; |
| 25 | class URLRequestContextGetter; |
| 26 | } |
| 27 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 28 | namespace update_client { |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 29 | |
sorin | 30474f0 | 2017-04-27 00:45:48 | [diff] [blame] | 30 | class Component; |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 31 | struct CrxComponent; |
[email protected] | da37c1d | 2013-12-19 01:04:38 | [diff] [blame] | 32 | |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 33 | // Defines a name-value pair that represents an installer attribute. |
| 34 | // Installer attributes are component-specific metadata, which may be serialized |
| 35 | // in an update check request. |
| 36 | using InstallerAttribute = std::pair<std::string, std::string>; |
| 37 | |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 38 | // Sends a protocol request to the the service endpoint specified by |url|. |
| 39 | // The body of the request is provided by |protocol_request| and it is |
| 40 | // expected to contain XML data. The caller owns the returned object. |
dcheng | d0fc6aa9 | 2016-04-22 18:03:12 | [diff] [blame] | 41 | std::unique_ptr<net::URLFetcher> SendProtocolRequest( |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 42 | const GURL& url, |
| 43 | const std::string& protocol_request, |
| 44 | net::URLFetcherDelegate* url_fetcher_delegate, |
| 45 | net::URLRequestContextGetter* url_request_context_getter); |
| 46 | |
[email protected] | afa378f2 | 2013-12-02 03:37:54 | [diff] [blame] | 47 | // Returns true if the url request of |fetcher| was succesful. |
| 48 | bool FetchSuccess(const net::URLFetcher& fetcher); |
| 49 | |
| 50 | // Returns the error code which occured during the fetch. The function returns 0 |
| 51 | // if the fetch was successful. If errors happen, the function could return a |
| 52 | // network error, an http response code, or the status of the fetch, if the |
| 53 | // fetch is pending or canceled. |
| 54 | int GetFetchError(const net::URLFetcher& fetcher); |
| 55 | |
sorin | 30474f0 | 2017-04-27 00:45:48 | [diff] [blame] | 56 | // Returns true if the |component| contains a valid differential update url. |
| 57 | bool HasDiffUpdate(const Component& component); |
[email protected] | da37c1d | 2013-12-19 01:04:38 | [diff] [blame] | 58 | |
[email protected] | 3cb2a4f | 2013-12-07 21:54:34 | [diff] [blame] | 59 | // Returns true if the |status_code| represents a server error 5xx. |
| 60 | bool IsHttpServerError(int status_code); |
| 61 | |
[email protected] | 2e2c529 | 2013-12-17 03:48:40 | [diff] [blame] | 62 | // Deletes the file and its directory, if the directory is empty. If the |
| 63 | // parent directory is not empty, the function ignores deleting the directory. |
| 64 | // Returns true if the file and the empty directory are deleted. |
| 65 | bool DeleteFileAndEmptyParentDirectory(const base::FilePath& filepath); |
| 66 | |
[email protected] | 93e8e2c | 2014-01-04 12:29:23 | [diff] [blame] | 67 | // Returns the component id of the |component|. The component id is in a |
| 68 | // format similar with the format of an extension id. |
| 69 | std::string GetCrxComponentID(const CrxComponent& component); |
| 70 | |
sorin | 74e7067 | 2016-02-03 03:13:10 | [diff] [blame] | 71 | // Returns true if the actual SHA-256 hash of the |filepath| matches the |
| 72 | // |expected_hash|. |
| 73 | bool VerifyFileHash256(const base::FilePath& filepath, |
| 74 | const std::string& expected_hash); |
| 75 | |
sorin | af402ee | 2016-04-09 01:02:06 | [diff] [blame] | 76 | // Returns true if the |brand| parameter matches ^[a-zA-Z]{4}?$ . |
sorin | a1fafb7d | 2016-03-23 17:54:42 | [diff] [blame] | 77 | bool IsValidBrand(const std::string& brand); |
| 78 | |
sorin | 2adb2ca | 2016-06-29 01:44:35 | [diff] [blame] | 79 | // Returns true if the name part of the |attr| parameter matches |
| 80 | // ^[-_a-zA-Z0-9]{1,256}$ and the value part of the |attr| parameter |
| 81 | // matches ^[-.,;+_=a-zA-Z0-9]{0,256}$ . |
| 82 | bool IsValidInstallerAttribute(const InstallerAttribute& attr); |
sorin | 2b864bc7 | 2016-04-08 22:14:47 | [diff] [blame] | 83 | |
sorin | fccbf2d | 2016-04-04 20:34:34 | [diff] [blame] | 84 | // Removes the unsecure urls in the |urls| parameter. |
| 85 | void RemoveUnsecureUrls(std::vector<GURL>* urls); |
| 86 | |
sorin | 2892f721 | 2016-11-07 18:59:43 | [diff] [blame] | 87 | // Adapter function for the old definitions of CrxInstaller::Install until the |
| 88 | // component installer code is migrated to use a REsult instead of bool. |
| 89 | CrxInstaller::Result InstallFunctionWrapper(base::Callback<bool()> callback); |
| 90 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 91 | } // namespace update_client |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 92 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 93 | #endif // COMPONENTS_UPDATE_CLIENT_UTILS_H_ |