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