• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_COMMON_UPDATE_MANIFEST_H_
6 #define EXTENSIONS_COMMON_UPDATE_MANIFEST_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "url/gurl.h"
12 
13 class UpdateManifest {
14  public:
15   // An update manifest looks like this:
16   //
17   // <?xml version="1.0" encoding="UTF-8"?>
18   // <gupdate xmlns="http://www.google.com/update2/response" protocol="2.0">
19   //  <daystart elapsed_seconds="300" />
20   //  <app appid="12345" status="ok">
21   //   <updatecheck codebase="http://example.com/extension_1.2.3.4.crx"
22   //                hash="12345" size="9854" status="ok" version="1.2.3.4"
23   //                prodversionmin="2.0.143.0"
24   //                codebasediff="http://example.com/diff_1.2.3.4.crx"
25   //                hashdiff="123" sizediff="101"
26   //                fp="1.123" />
27   //  </app>
28   // </gupdate>
29   //
30   // The <daystart> tag contains a "elapsed_seconds" attribute which refers to
31   // the server's notion of how many seconds it has been since midnight.
32   //
33   // The "appid" attribute of the <app> tag refers to the unique id of the
34   // extension. The "codebase" attribute of the <updatecheck> tag is the url to
35   // fetch the updated crx file, and the "prodversionmin" attribute refers to
36   // the minimum version of the chrome browser that the update applies to.
37 
38   // The diff data members correspond to the differential update package, if
39   // a differential update is specified in the response.
40 
41   // The result of parsing one <app> tag in an xml update check manifest.
42   struct Result {
43     Result();
44     ~Result();
45 
46     std::string extension_id;
47     std::string version;
48     std::string browser_min_version;
49 
50     // Attributes for the full update.
51     GURL crx_url;
52     std::string package_hash;
53     int size;
54     std::string package_fingerprint;
55 
56     // Attributes for the differential update.
57     GURL diff_crx_url;
58     std::string diff_package_hash;
59     int diff_size;
60   };
61 
62   static const int kNoDaystart = -1;
63   struct Results {
64     Results();
65     ~Results();
66 
67     std::vector<Result> list;
68     // This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
69     int daystart_elapsed_seconds;
70   };
71 
72   UpdateManifest();
73   ~UpdateManifest();
74 
75   // Parses an update manifest xml string into Result data. Returns a bool
76   // indicating success or failure. On success, the results are available by
77   // calling results(). The details for any failures are available by calling
78   // errors().
79   bool Parse(const std::string& manifest_xml);
80 
results()81   const Results& results() { return results_; }
errors()82   const std::string& errors() { return errors_; }
83 
84  private:
85   Results results_;
86   std::string errors_;
87 
88   // Helper function that adds parse error details to our errors_ string.
89   void ParseError(const char* details, ...);
90 
91   DISALLOW_COPY_AND_ASSIGN(UpdateManifest);
92 };
93 
94 #endif  // EXTENSIONS_COMMON_UPDATE_MANIFEST_H_
95