blob: 8ab8192b71ee97d531800b9dbc2168c24b55c3e8 [file] [log] [blame]
[email protected]de0fdca22014-08-19 05:26:091// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]2cddef42013-11-22 08:23:222// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sorin7cff6e52017-05-17 16:37:235#ifndef COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_
6#define COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_
[email protected]2cddef42013-11-22 08:23:227
Sorin Jianu7663dd02018-11-15 18:25:298#include <cstdint>
wafflesf43eb2fd32016-08-23 19:15:299#include <map>
10#include <memory>
[email protected]2cddef42013-11-22 08:23:2211#include <string>
12#include <vector>
sorin5cb1f5492014-09-23 04:07:4413
14#include "base/macros.h"
[email protected]2cddef42013-11-22 08:23:2215#include "url/gurl.h"
16
sorin52ac0882015-01-24 01:15:0017namespace update_client {
[email protected]2cddef42013-11-22 08:23:2218
sorin7cff6e52017-05-17 16:37:2319class ProtocolParser {
[email protected]2cddef42013-11-22 08:23:2220 public:
Sorin Jianu039032b2018-10-12 21:48:1321 // The result of parsing one |app| entity in an update check response.
[email protected]2cddef42013-11-22 08:23:2222 struct Result {
23 struct Manifest {
24 struct Package {
25 Package();
vmpstrb6449d512016-02-25 23:55:4026 Package(const Package& other);
[email protected]2cddef42013-11-22 08:23:2227 ~Package();
28
Sorin Jianu55587d32018-11-14 21:43:2729 // |fingerprint| is optional. It identifies the package, preferably
30 // with a modified sha256 hash of the package in hex format.
[email protected]2cddef42013-11-22 08:23:2231 std::string fingerprint;
32
33 // Attributes for the full update.
34 std::string name;
35 std::string hash_sha256;
Sorin Jianu7663dd02018-11-15 18:25:2936 int64_t size = 0;
[email protected]2cddef42013-11-22 08:23:2237
38 // Attributes for the differential update.
39 std::string namediff;
40 std::string hashdiff_sha256;
Sorin Jianu7663dd02018-11-15 18:25:2941 int64_t sizediff = 0;
[email protected]2cddef42013-11-22 08:23:2242 };
43
44 Manifest();
vmpstrb6449d512016-02-25 23:55:4045 Manifest(const Manifest& other);
[email protected]2cddef42013-11-22 08:23:2246 ~Manifest();
47
48 std::string version;
49 std::string browser_min_version;
50 std::vector<Package> packages;
Sorin Jianu9d64af672020-02-05 19:14:3451
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]2cddef42013-11-22 08:23:2258 };
59
60 Result();
vmpstrb6449d512016-02-25 23:55:4061 Result(const Result& other);
[email protected]2cddef42013-11-22 08:23:2262 ~Result();
63
64 std::string extension_id;
65
sorin9ef301c2017-02-16 20:29:1766 // The updatecheck response status.
67 std::string status;
68
[email protected]2cddef42013-11-22 08:23:2269 // The list of fallback urls, for full and diff updates respectively.
[email protected]da37c1d2013-12-19 01:04:3870 // These urls are base urls; they don't include the filename.
[email protected]2cddef42013-11-22 08:23:2271 std::vector<GURL> crx_urls;
72 std::vector<GURL> crx_diffurls;
73
74 Manifest manifest;
wafflesf43eb2fd32016-08-23 19:15:2975
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[];
sorin519656c2017-04-28 22:39:3484
85 // Contains the run action returned by the server as part of an update
Sorin Jianu9d64af672020-02-05 19:14:3486 // check response. This indicates the need to trigger the execution of
87 // something bound to a component which is already installed.
sorin519656c2017-04-28 22:39:3488 std::string action_run;
[email protected]2cddef42013-11-22 08:23:2289 };
90
91 static const int kNoDaystart = -1;
92 struct Results {
93 Results();
vmpstrb6449d512016-02-25 23:55:4094 Results(const Results& other);
[email protected]2cddef42013-11-22 08:23:2295 ~Results();
96
97 // This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
sorin519656c2017-04-28 22:39:3498 int daystart_elapsed_seconds = kNoDaystart;
99
wafflesd2d9a332016-04-09 01:59:57100 // This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
sorin519656c2017-04-28 22:39:34101 int daystart_elapsed_days = kNoDaystart;
[email protected]2cddef42013-11-22 08:23:22102 std::vector<Result> list;
103 };
104
Sorin Jianu039032b2018-10-12 21:48:13105 static std::unique_ptr<ProtocolParser> Create();
[email protected]2cddef42013-11-22 08:23:22106
Sorin Jianu039032b2018-10-12 21:48:13107 virtual ~ProtocolParser();
108
109 // Parses an update response string into Result data. Returns a bool
[email protected]2cddef42013-11-22 08:23:22110 // indicating success or failure. On success, the results are available by
sorin9ef301c2017-02-16 20:29:17111 // 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 Jianu039032b2018-10-12 21:48:13114 bool Parse(const std::string& response);
[email protected]2cddef42013-11-22 08:23:22115
116 const Results& results() const { return results_; }
117 const std::string& errors() const { return errors_; }
118
Sorin Jianu039032b2018-10-12 21:48:13119 protected:
120 ProtocolParser();
121
122 // Appends parse error details to |errors_| string.
123 void ParseError(const char* details, ...);
124
[email protected]2cddef42013-11-22 08:23:22125 private:
Sorin Jianu039032b2018-10-12 21:48:13126 virtual bool DoParse(const std::string& response, Results* results) = 0;
127
[email protected]2cddef42013-11-22 08:23:22128 Results results_;
129 std::string errors_;
130
sorin7cff6e52017-05-17 16:37:23131 DISALLOW_COPY_AND_ASSIGN(ProtocolParser);
[email protected]2cddef42013-11-22 08:23:22132};
133
sorin52ac0882015-01-24 01:15:00134} // namespace update_client
[email protected]2cddef42013-11-22 08:23:22135
sorin7cff6e52017-05-17 16:37:23136#endif // COMPONENTS_UPDATE_CLIENT_PROTOCOL_PARSER_H_