blob: 02c992594452708a69b153709c62626f683c4d77 [file] [log] [blame]
[email protected]de0fdca22014-08-19 05:26:091// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]2cddef42013-11-22 08:23:222// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sorin52ac0882015-01-24 01:15:005#ifndef COMPONENTS_UPDATE_CLIENT_UTILS_H_
6#define COMPONENTS_UPDATE_CLIENT_UTILS_H_
[email protected]2cddef42013-11-22 08:23:227
dchengd0fc6aa92016-04-22 18:03:128#include <memory>
[email protected]2cddef42013-11-22 08:23:229#include <string>
sorin2adb2ca2016-06-29 01:44:3510#include <utility>
sorinfccbf2d2016-04-04 20:34:3411#include <vector>
tfarinabe264fa2016-01-11 19:55:0112
sorin2892f7212016-11-07 18:59:4313#include "base/callback_forward.h"
14#include "components/update_client/update_client.h"
[email protected]2cddef42013-11-22 08:23:2215
16class GURL;
17
[email protected]2e2c5292013-12-17 03:48:4018namespace base {
19class FilePath;
20}
21
[email protected]2cddef42013-11-22 08:23:2222namespace net {
23class URLFetcher;
24class URLFetcherDelegate;
25class URLRequestContextGetter;
26}
27
sorin52ac0882015-01-24 01:15:0028namespace update_client {
[email protected]2cddef42013-11-22 08:23:2229
sorin30474f02017-04-27 00:45:4830class Component;
sorin52ac0882015-01-24 01:15:0031struct CrxComponent;
[email protected]da37c1d2013-12-19 01:04:3832
sorin2adb2ca2016-06-29 01:44:3533// 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.
36using InstallerAttribute = std::pair<std::string, std::string>;
37
[email protected]2cddef42013-11-22 08:23:2238// 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.
dchengd0fc6aa92016-04-22 18:03:1241std::unique_ptr<net::URLFetcher> SendProtocolRequest(
[email protected]2cddef42013-11-22 08:23:2242 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]afa378f22013-12-02 03:37:5447// Returns true if the url request of |fetcher| was succesful.
48bool 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.
54int GetFetchError(const net::URLFetcher& fetcher);
55
sorin30474f02017-04-27 00:45:4856// Returns true if the |component| contains a valid differential update url.
57bool HasDiffUpdate(const Component& component);
[email protected]da37c1d2013-12-19 01:04:3858
[email protected]3cb2a4f2013-12-07 21:54:3459// Returns true if the |status_code| represents a server error 5xx.
60bool IsHttpServerError(int status_code);
61
[email protected]2e2c5292013-12-17 03:48:4062// 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.
65bool DeleteFileAndEmptyParentDirectory(const base::FilePath& filepath);
66
[email protected]93e8e2c2014-01-04 12:29:2367// Returns the component id of the |component|. The component id is in a
68// format similar with the format of an extension id.
69std::string GetCrxComponentID(const CrxComponent& component);
70
sorin74e70672016-02-03 03:13:1071// Returns true if the actual SHA-256 hash of the |filepath| matches the
72// |expected_hash|.
73bool VerifyFileHash256(const base::FilePath& filepath,
74 const std::string& expected_hash);
75
sorinaf402ee2016-04-09 01:02:0676// Returns true if the |brand| parameter matches ^[a-zA-Z]{4}?$ .
sorina1fafb7d2016-03-23 17:54:4277bool IsValidBrand(const std::string& brand);
78
sorin2adb2ca2016-06-29 01:44:3579// 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}$ .
82bool IsValidInstallerAttribute(const InstallerAttribute& attr);
sorin2b864bc72016-04-08 22:14:4783
sorinfccbf2d2016-04-04 20:34:3484// Removes the unsecure urls in the |urls| parameter.
85void RemoveUnsecureUrls(std::vector<GURL>* urls);
86
sorin2892f7212016-11-07 18:59:4387// Adapter function for the old definitions of CrxInstaller::Install until the
88// component installer code is migrated to use a REsult instead of bool.
89CrxInstaller::Result InstallFunctionWrapper(base::Callback<bool()> callback);
90
sorin52ac0882015-01-24 01:15:0091} // namespace update_client
[email protected]2cddef42013-11-22 08:23:2292
sorin52ac0882015-01-24 01:15:0093#endif // COMPONENTS_UPDATE_CLIENT_UTILS_H_