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