1 // Copyright (c) 2012 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 EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ 6 #define EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ 7 8 #include <map> 9 #include <memory> 10 #include <string> 11 #include <vector> 12 13 #include "base/callback_forward.h" 14 #include "base/optional.h" 15 #include "url/gurl.h" 16 17 namespace extensions { 18 19 struct UpdateManifestResult { 20 UpdateManifestResult(); 21 UpdateManifestResult(const UpdateManifestResult& other); 22 ~UpdateManifestResult(); 23 24 std::string extension_id; 25 std::string version; 26 std::string browser_min_version; 27 28 // Attribute for no update: server may provide additional info about why there 29 // is no updates, eg. “bandwidth limit” if client is downloading extensions 30 // too aggressive. 31 base::Optional<std::string> info; 32 33 // Attributes for the full update. 34 GURL crx_url; 35 std::string package_hash; 36 int size = 0; 37 std::string package_fingerprint; 38 39 // Attributes for the differential update. 40 GURL diff_crx_url; 41 std::string diff_package_hash; 42 int diff_size = 0; 43 }; 44 45 constexpr int kNoDaystart = -1; 46 struct UpdateManifestResults { 47 UpdateManifestResults(); 48 UpdateManifestResults(const UpdateManifestResults& other); 49 UpdateManifestResults& operator=(const UpdateManifestResults& other); 50 ~UpdateManifestResults(); 51 52 // Group |list| by |extension_id|. 53 std::map<std::string, std::vector<const UpdateManifestResult*>> GroupByID() 54 const; 55 56 std::vector<UpdateManifestResult> list; 57 // This will be >= 0, or kNoDaystart if the <daystart> tag was not present. 58 int daystart_elapsed_seconds = kNoDaystart; 59 }; 60 61 // Parses an update manifest |xml| safely in a utility process and calls 62 // |callback| with the results, which will be null on failure. Runs on 63 // the UI thread. 64 // 65 // An update manifest looks like this: 66 // 67 // <?xml version="1.0" encoding="UTF-8"?> 68 // <gupdate xmlns="http://www.google.com/update2/response" protocol="2.0"> 69 // <daystart elapsed_seconds="300" /> 70 // <app appid="12345" status="ok"> 71 // <updatecheck codebase="http://example.com/extension_1.2.3.4.crx" 72 // hash="12345" size="9854" status="ok" version="1.2.3.4" 73 // prodversionmin="2.0.143.0" 74 // codebasediff="http://example.com/diff_1.2.3.4.crx" 75 // hashdiff="123" sizediff="101" 76 // fp="1.123" /> 77 // </app> 78 // </gupdate> 79 // 80 // The <daystart> tag contains a "elapsed_seconds" attribute which refers to 81 // the server's notion of how many seconds it has been since midnight. 82 // 83 // The "appid" attribute of the <app> tag refers to the unique id of the 84 // extension. The "codebase" attribute of the <updatecheck> tag is the url to 85 // fetch the updated crx file, and the "prodversionmin" attribute refers to 86 // the minimum version of the chrome browser that the update applies to. 87 88 // The diff data members correspond to the differential update package, if 89 // a differential update is specified in the response. 90 91 // The result of parsing one <app> tag in an xml update check manifest. 92 using ParseUpdateManifestCallback = 93 base::OnceCallback<void(std::unique_ptr<UpdateManifestResults> results, 94 const base::Optional<std::string>& error)>; 95 void ParseUpdateManifest(const std::string& xml, 96 ParseUpdateManifestCallback callback); 97 98 } // namespace extensions 99 100 #endif // EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_ 101