Yusuke Sato | 6bc6a9fa | 2018-12-05 17:55:00 | [diff] [blame] | 1 | // Copyright 2018 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_ARC_ARC_CLIENT_ADAPTER_H_ |
| 6 | #define COMPONENTS_ARC_ARC_CLIENT_ADAPTER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/callback_forward.h" |
| 12 | #include "base/macros.h" |
| 13 | #include "base/observer_list.h" |
| 14 | #include "base/optional.h" |
| 15 | #include "chromeos/dbus/login_manager/arc.pb.h" |
| 16 | #include "chromeos/dbus/session_manager_client.h" |
| 17 | |
| 18 | namespace arc { |
| 19 | |
| 20 | // TODO(yusukes): Move the enum and proto in system_api/ from login_manager's |
| 21 | // namespace to arc and remove all the type aliases. |
| 22 | using ArcContainerStopReason = login_manager::ArcContainerStopReason; |
| 23 | using StartArcMiniContainerRequest = |
| 24 | login_manager::StartArcMiniContainerRequest; |
| 25 | using UpgradeArcContainerRequest = login_manager::UpgradeArcContainerRequest; |
| 26 | |
| 27 | // An adapter to talk to a Chrome OS daemon to manage lifetime of ARC instance. |
| 28 | class ArcClientAdapter { |
| 29 | public: |
| 30 | class Observer { |
| 31 | public: |
| 32 | virtual ~Observer() = default; |
| 33 | virtual void ArcInstanceStopped(ArcContainerStopReason stop_reason, |
| 34 | const std::string& instance_id) = 0; |
| 35 | }; |
| 36 | |
| 37 | // Creates a default instance of ArcClientAdapter. |
| 38 | static std::unique_ptr<ArcClientAdapter> Create(); |
| 39 | virtual ~ArcClientAdapter(); |
| 40 | |
| 41 | // StartMiniArc starts ARC with only a handful of ARC processes for Chrome OS |
| 42 | // login screen. In case of success, callback will be called with |
| 43 | // |instance_id| set to a string. The ID is passed to ArcInstanceStopped() |
| 44 | // to identify which instance is stopped. In case of error, |instance_id| will |
| 45 | // be nullopt. |
| 46 | using StartMiniArcCallback = |
| 47 | base::OnceCallback<void(base::Optional<std::string> instance_id)>; |
| 48 | virtual void StartMiniArc(const StartArcMiniContainerRequest& request, |
| 49 | StartMiniArcCallback callback) = 0; |
| 50 | |
| 51 | // UpgradeArc upgrades a mini ARC instance to a full ARC instance. In case of |
| 52 | // success, success_callback is called. In case of error, |error_callback| |
| 53 | // will be called with a |low_free_disk_space| signaling whether the failure |
| 54 | // was due to low free disk space. |
| 55 | using UpgradeErrorCallback = |
| 56 | base::OnceCallback<void(bool low_free_disk_space)>; |
| 57 | virtual void UpgradeArc(const UpgradeArcContainerRequest& request, |
| 58 | base::OnceClosure success_callback, |
| 59 | UpgradeErrorCallback error_callback) = 0; |
| 60 | |
| 61 | // Asynchronously stops the ARC instance. |
| 62 | virtual void StopArcInstance() = 0; |
| 63 | |
| 64 | void AddObserver(Observer* observer); |
| 65 | void RemoveObserver(Observer* observer); |
| 66 | |
| 67 | protected: |
| 68 | ArcClientAdapter(); |
| 69 | |
| 70 | base::ObserverList<Observer>::Unchecked observer_list_; |
| 71 | |
| 72 | private: |
| 73 | DISALLOW_COPY_AND_ASSIGN(ArcClientAdapter); |
| 74 | }; |
| 75 | |
| 76 | } // namespace arc |
| 77 | |
| 78 | #endif // COMPONENTS_ARC_ARC_CLIENT_ADAPTER_H_ |