blob: dc6b45181af11697295fc5dd1d7a4afb6342723e [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "url/gurl.h"
namespace service_manager {
class Connector;
namespace extensions {
struct UpdateManifestResult {
UpdateManifestResult(const UpdateManifestResult& other);
std::string extension_id;
std::string version;
std::string browser_min_version;
// Attributes for the full update.
GURL crx_url;
std::string package_hash;
int size = 0;
std::string package_fingerprint;
// Attributes for the differential update.
GURL diff_crx_url;
std::string diff_package_hash;
int diff_size = 0;
constexpr int kNoDaystart = -1;
struct UpdateManifestResults {
UpdateManifestResults(const UpdateManifestResults& other);
UpdateManifestResults& operator=(const UpdateManifestResults& other);
// Group |list| by |extension_id|.
std::map<std::string, std::vector<const UpdateManifestResult*>> GroupByID()
std::vector<UpdateManifestResult> list;
// This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
int daystart_elapsed_seconds = kNoDaystart;
// Parses an update manifest |xml| safely in a utility process and calls
// |callback| with the results, which will be null on failure. Runs on
// the UI thread.
// An update manifest looks like this:
// <?xml version="1.0" encoding="UTF-8"?>
// <gupdate xmlns="" protocol="2.0">
// <daystart elapsed_seconds="300" />
// <app appid="12345" status="ok">
// <updatecheck codebase=""
// hash="12345" size="9854" status="ok" version=""
// prodversionmin=""
// codebasediff=""
// hashdiff="123" sizediff="101"
// fp="1.123" />
// </app>
// </gupdate>
// The <daystart> tag contains a "elapsed_seconds" attribute which refers to
// the server's notion of how many seconds it has been since midnight.
// The "appid" attribute of the <app> tag refers to the unique id of the
// extension. The "codebase" attribute of the <updatecheck> tag is the url to
// fetch the updated crx file, and the "prodversionmin" attribute refers to
// the minimum version of the chrome browser that the update applies to.
// The diff data members correspond to the differential update package, if
// a differential update is specified in the response.
// The result of parsing one <app> tag in an xml update check manifest.
using ParseUpdateManifestCallback =
base::OnceCallback<void(std::unique_ptr<UpdateManifestResults> results,
const base::Optional<std::string>& error)>;
void ParseUpdateManifest(service_manager::Connector* connector,
const std::string& xml,
ParseUpdateManifestCallback callback);
} // namespace extensions