[email protected] | de0fdca2 | 2014-08-19 05:26:09 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame] | 5 | #ifndef COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ |
6 | #define COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 7 | |
Sorin Jianu | 7663dd0 | 2018-11-15 18:25:29 | [diff] [blame] | 8 | #include <cstdint> |
waffles | f43eb2fd3 | 2016-08-23 19:15:29 | [diff] [blame] | 9 | #include <map> |
10 | #include <memory> | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 11 | #include <string> |
12 | #include <vector> | ||||
sorin | 5cb1f549 | 2014-09-23 04:07:44 | [diff] [blame] | 13 | |
14 | #include "base/macros.h" | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 15 | #include "url/gurl.h" |
16 | |||||
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 17 | namespace update_client { |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 18 | |
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame] | 19 | class ProtocolParser { |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 20 | public: |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 21 | // The result of parsing one |app| entity in an update check response. |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 22 | struct Result { |
23 | struct Manifest { | ||||
24 | struct Package { | ||||
25 | Package(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 26 | Package(const Package& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 27 | ~Package(); |
28 | |||||
Sorin Jianu | 55587d3 | 2018-11-14 21:43:27 | [diff] [blame] | 29 | // |fingerprint| is optional. It identifies the package, preferably |
30 | // with a modified sha256 hash of the package in hex format. | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 31 | std::string fingerprint; |
32 | |||||
33 | // Attributes for the full update. | ||||
34 | std::string name; | ||||
35 | std::string hash_sha256; | ||||
Sorin Jianu | 7663dd0 | 2018-11-15 18:25:29 | [diff] [blame] | 36 | int64_t size = 0; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 37 | |
38 | // Attributes for the differential update. | ||||
39 | std::string namediff; | ||||
40 | std::string hashdiff_sha256; | ||||
Sorin Jianu | 7663dd0 | 2018-11-15 18:25:29 | [diff] [blame] | 41 | int64_t sizediff = 0; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 42 | }; |
43 | |||||
44 | Manifest(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 45 | Manifest(const Manifest& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 46 | ~Manifest(); |
47 | |||||
48 | std::string version; | ||||
49 | std::string browser_min_version; | ||||
50 | std::vector<Package> packages; | ||||
Sorin Jianu | 9d64af67 | 2020-02-05 19:14:34 | [diff] [blame] | 51 | |
52 | // A path within the CRX archive to an executable to run as part of the | ||||
53 | // update. The executable is typically an application installer. | ||||
54 | std::string run; | ||||
55 | |||||
56 | // Command-line arguments for the binary specified by |run|. | ||||
57 | std::string arguments; | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 58 | }; |
59 | |||||
60 | Result(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 61 | Result(const Result& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 62 | ~Result(); |
63 | |||||
64 | std::string extension_id; | ||||
65 | |||||
sorin | 9ef301c | 2017-02-16 20:29:17 | [diff] [blame] | 66 | // The updatecheck response status. |
67 | std::string status; | ||||
68 | |||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 69 | // The list of fallback urls, for full and diff updates respectively. |
[email protected] | da37c1d | 2013-12-19 01:04:38 | [diff] [blame] | 70 | // These urls are base urls; they don't include the filename. |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 71 | std::vector<GURL> crx_urls; |
72 | std::vector<GURL> crx_diffurls; | ||||
73 | |||||
74 | Manifest manifest; | ||||
waffles | f43eb2fd3 | 2016-08-23 19:15:29 | [diff] [blame] | 75 | |
76 | // The server has instructed the client to set its [key] to [value] for each | ||||
77 | // key-value pair in this string. | ||||
78 | std::map<std::string, std::string> cohort_attrs; | ||||
79 | |||||
80 | // The following are the only allowed keys in |cohort_attrs|. | ||||
81 | static const char kCohort[]; | ||||
82 | static const char kCohortHint[]; | ||||
83 | static const char kCohortName[]; | ||||
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 84 | |
85 | // Contains the run action returned by the server as part of an update | ||||
Sorin Jianu | 9d64af67 | 2020-02-05 19:14:34 | [diff] [blame] | 86 | // check response. This indicates the need to trigger the execution of |
87 | // something bound to a component which is already installed. | ||||
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 88 | std::string action_run; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 89 | }; |
90 | |||||
91 | static const int kNoDaystart = -1; | ||||
92 | struct Results { | ||||
93 | Results(); | ||||
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 94 | Results(const Results& other); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 95 | ~Results(); |
96 | |||||
97 | // This will be >= 0, or kNoDaystart if the <daystart> tag was not present. | ||||
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 98 | int daystart_elapsed_seconds = kNoDaystart; |
99 | |||||
waffles | d2d9a33 | 2016-04-09 01:59:57 | [diff] [blame] | 100 | // This will be >= 0, or kNoDaystart if the <daystart> tag was not present. |
sorin | 519656c | 2017-04-28 22:39:34 | [diff] [blame] | 101 | int daystart_elapsed_days = kNoDaystart; |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 102 | std::vector<Result> list; |
103 | }; | ||||
104 | |||||
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 105 | static std::unique_ptr<ProtocolParser> Create(); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 106 | |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 107 | virtual ~ProtocolParser(); |
108 | |||||
109 | // Parses an update response string into Result data. Returns a bool | ||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 110 | // indicating success or failure. On success, the results are available by |
sorin | 9ef301c | 2017-02-16 20:29:17 | [diff] [blame] | 111 | // calling results(). In case of success, only results corresponding to |
112 | // the update check status |ok| or |noupdate| are included. | ||||
113 | // The details for any failures are available by calling errors(). | ||||
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 114 | bool Parse(const std::string& response); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 115 | |
116 | const Results& results() const { return results_; } | ||||
117 | const std::string& errors() const { return errors_; } | ||||
118 | |||||
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 119 | protected: |
120 | ProtocolParser(); | ||||
121 | |||||
122 | // Appends parse error details to |errors_| string. | ||||
123 | void ParseError(const char* details, ...); | ||||
124 | |||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 125 | private: |
Sorin Jianu | 039032b | 2018-10-12 21:48:13 | [diff] [blame] | 126 | virtual bool DoParse(const std::string& response, Results* results) = 0; |
127 | |||||
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 128 | Results results_; |
129 | std::string errors_; | ||||
130 | |||||
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame] | 131 | DISALLOW_COPY_AND_ASSIGN(ProtocolParser); |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 132 | }; |
133 | |||||
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 134 | } // namespace update_client |
[email protected] | 2cddef4 | 2013-11-22 08:23:22 | [diff] [blame] | 135 | |
sorin | 7cff6e5 | 2017-05-17 16:37:23 | [diff] [blame] | 136 | #endif // COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_ |