Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / update_client / utils.h
blobb109764a11a9b6d4ccbd1c4059cf95dfca5166d3
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_UPDATE_CLIENT_UTILS_H_
6 #define COMPONENTS_UPDATE_CLIENT_UTILS_H_
8 #include <string>
9 #include <base/memory/scoped_ptr.h>
11 class GURL;
13 namespace base {
14 class FilePath;
17 namespace net {
18 class URLFetcher;
19 class URLFetcherDelegate;
20 class URLRequestContextGetter;
23 namespace update_client {
25 class Configurator;
26 struct CrxComponent;
27 struct CrxUpdateItem;
29 // An update protocol request starts with a common preamble which includes
30 // version and platform information for Chrome and the operating system,
31 // followed by a request body, which is the actual payload of the request.
32 // For example:
34 // <?xml version="1.0" encoding="UTF-8"?>
35 // <request protocol="3.0" version="chrome-32.0.1.0" prodversion="32.0.1.0"
36 // requestid="{7383396D-B4DD-46E1-9104-AAC6B918E792}"
37 // updaterchannel="canary" arch="x86" nacl_arch="x86-64"
38 // ADDITIONAL ATTRIBUTES>
39 // <hw physmemory="16"/>
40 // <os platform="win" version="6.1" arch="x86"/>
41 // ... REQUEST BODY ...
42 // </request>
44 // Builds a protocol request string by creating the outer envelope for
45 // the request and including the request body specified as a parameter.
46 // If specified, |additional_attributes| are appended as attributes of the
47 // request element. The additional attributes have to be well-formed for
48 // insertion in the request element.
49 std::string BuildProtocolRequest(const std::string& browser_version,
50 const std::string& channel,
51 const std::string& lang,
52 const std::string& os_long_name,
53 const std::string& request_body,
54 const std::string& additional_attributes);
56 // Sends a protocol request to the the service endpoint specified by |url|.
57 // The body of the request is provided by |protocol_request| and it is
58 // expected to contain XML data. The caller owns the returned object.
59 scoped_ptr<net::URLFetcher> SendProtocolRequest(
60 const GURL& url,
61 const std::string& protocol_request,
62 net::URLFetcherDelegate* url_fetcher_delegate,
63 net::URLRequestContextGetter* url_request_context_getter);
65 // Returns true if the url request of |fetcher| was succesful.
66 bool FetchSuccess(const net::URLFetcher& fetcher);
68 // Returns the error code which occured during the fetch. The function returns 0
69 // if the fetch was successful. If errors happen, the function could return a
70 // network error, an http response code, or the status of the fetch, if the
71 // fetch is pending or canceled.
72 int GetFetchError(const net::URLFetcher& fetcher);
74 // Returns true if the |update_item| contains a valid differential update url.
75 bool HasDiffUpdate(const CrxUpdateItem* update_item);
77 // Returns true if the |status_code| represents a server error 5xx.
78 bool IsHttpServerError(int status_code);
80 // Deletes the file and its directory, if the directory is empty. If the
81 // parent directory is not empty, the function ignores deleting the directory.
82 // Returns true if the file and the empty directory are deleted.
83 bool DeleteFileAndEmptyParentDirectory(const base::FilePath& filepath);
85 // Returns the component id of the |component|. The component id is in a
86 // format similar with the format of an extension id.
87 std::string GetCrxComponentID(const CrxComponent& component);
89 } // namespace update_client
91 #endif // COMPONENTS_UPDATE_CLIENT_UTILS_H_