blob: b3b72219e1f5b6a2e66e8ef4ed72e68b9b6b57a3 [file] [log] [blame]
Yavor Goulishev9c08e842020-04-29 14:03:33 -07001// 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 COMPONENTS_UPDATE_CLIENT_UPDATE_CHECKER_H_
6#define COMPONENTS_UPDATE_CLIENT_UPDATE_CHECKER_H_
7
8#include <memory>
9#include <string>
10#include <vector>
11
12#include "base/callback.h"
13#include "base/containers/flat_map.h"
14#include "base/macros.h"
15#include "base/memory/ref_counted.h"
16#include "base/optional.h"
17#include "components/update_client/component.h"
18#include "components/update_client/protocol_parser.h"
19#include "url/gurl.h"
20
Kaido Kert08336fa2022-02-08 14:10:50 -080021#if defined(STARBOARD)
Kaido Kert52711092023-02-14 18:06:26 -080022#include "starboard/extension/installation_manager.h"
Kaido Kert08336fa2022-02-08 14:10:50 -080023#endif
24
Yavor Goulishev9c08e842020-04-29 14:03:33 -070025namespace update_client {
26
27class Configurator;
28class PersistedData;
29
30class UpdateChecker {
31 public:
32 using UpdateCheckCallback = base::OnceCallback<void(
33 const base::Optional<ProtocolParser::Results>& results,
34 ErrorCategory error_category,
35 int error,
36 int retry_after_sec)>;
37
38 using Factory =
39 std::unique_ptr<UpdateChecker> (*)(scoped_refptr<Configurator> config,
40 PersistedData* persistent);
41
42 virtual ~UpdateChecker() = default;
43
44 // Initiates an update check for the components specified by their ids.
45 // |additional_attributes| provides a way to customize the <request> element.
46 // |is_foreground| controls the value of "X-Goog-Update-Interactivity"
47 // header which is sent with the update check.
48 // On completion, the state of |components| is mutated as required by the
49 // server response received.
50 virtual void CheckForUpdates(
51 const std::string& session_id,
52 const std::vector<std::string>& ids_to_check,
53 const IdToComponentPtrMap& components,
54 const base::flat_map<std::string, std::string>& additional_attributes,
55 bool enabled_component_updates,
56 UpdateCheckCallback update_check_callback) = 0;
57
Kaido Kert97b64f22021-12-13 10:55:31 -080058#if defined(STARBOARD)
59 virtual void Cancel() = 0;
Kaido Kert08336fa2022-02-08 14:10:50 -080060 virtual bool SkipUpdate(const CobaltExtensionInstallationManagerApi* installation_api) = 0;
Kaido Kert97b64f22021-12-13 10:55:31 -080061#endif
62
Yavor Goulishev9c08e842020-04-29 14:03:33 -070063 static std::unique_ptr<UpdateChecker> Create(
64 scoped_refptr<Configurator> config,
65 PersistedData* persistent);
66
Kaido Kert72bde072021-03-12 15:55:15 -080067#if defined(STARBOARD)
Yavor Goulishev9c08e842020-04-29 14:03:33 -070068 virtual PersistedData* GetPersistedData() = 0;
69#endif
70
71 protected:
72 UpdateChecker() = default;
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(UpdateChecker);
76};
77
78} // namespace update_client
79
80#endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CHECKER_H_