Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame] | 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 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 Kert | 08336fa | 2022-02-08 14:10:50 -0800 | [diff] [blame] | 21 | #if defined(STARBOARD) |
Kaido Kert | 5271109 | 2023-02-14 18:06:26 -0800 | [diff] [blame] | 22 | #include "starboard/extension/installation_manager.h" |
Kaido Kert | 08336fa | 2022-02-08 14:10:50 -0800 | [diff] [blame] | 23 | #endif |
| 24 | |
Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame] | 25 | namespace update_client { |
| 26 | |
| 27 | class Configurator; |
| 28 | class PersistedData; |
| 29 | |
| 30 | class 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 Kert | 97b64f2 | 2021-12-13 10:55:31 -0800 | [diff] [blame] | 58 | #if defined(STARBOARD) |
| 59 | virtual void Cancel() = 0; |
Kaido Kert | 08336fa | 2022-02-08 14:10:50 -0800 | [diff] [blame] | 60 | virtual bool SkipUpdate(const CobaltExtensionInstallationManagerApi* installation_api) = 0; |
Kaido Kert | 97b64f2 | 2021-12-13 10:55:31 -0800 | [diff] [blame] | 61 | #endif |
| 62 | |
Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame] | 63 | static std::unique_ptr<UpdateChecker> Create( |
| 64 | scoped_refptr<Configurator> config, |
| 65 | PersistedData* persistent); |
| 66 | |
Kaido Kert | 72bde07 | 2021-03-12 15:55:15 -0800 | [diff] [blame] | 67 | #if defined(STARBOARD) |
Yavor Goulishev | 9c08e84 | 2020-04-29 14:03:33 -0700 | [diff] [blame] | 68 | 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_ |