chromium/extensions/browser/updater/safe_manifest_parser.h

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_
#define EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback_forward.h"
#include "extensions/common/extension_id.h"
#include "url/gurl.h"

namespace extensions {

// Note: enum used for UMA. Do NOT reorder or remove entries.
// 1) Don't forget to update enums.xml (name: ManifestInvalidError) when adding
// new entries.
// 2) Don't forget to update device_management_backend.proto (name:
// ExtensionInstallReportLogEvent::ManifestInvalidError) when adding new
// entries.
// 3) Don't forget to update ConvertManifestInvalidErrorToProto method in
// ExtensionInstallEventLogCollector.
// Some errors are common for the entire fetched update manifest which
// contains manifests of different extensions, while some errors are per
// extension basis.
enum class ManifestInvalidError {};

struct ManifestParseFailure {};

struct UpdateManifestResult {};

inline constexpr int kNoDaystart =;
struct UpdateManifestResults {};

// 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="http://www.google.com/update2/response" protocol="2.0">
//  <daystart elapsed_seconds="300" />
//  <app appid="12345" status="ok">
//   <updatecheck codebase="http://example.com/extension_1.2.3.4.crx"
//                hash="12345" size="9854" status="ok" version="1.2.3.4"
//                prodversionmin="2.0.143.0"
//                codebasediff="http://example.com/diff_1.2.3.4.crx"
//                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.
ParseUpdateManifestCallback;
void ParseUpdateManifest(const std::string& xml,
                         ParseUpdateManifestCallback callback);

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_UPDATER_SAFE_MANIFEST_PARSER_H_