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