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_SESSION_ARC_CLIENT_ADAPTER_H_
6 #define COMPONENTS_ARC_SESSION_ARC_CLIENT_ADAPTER_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "base/macros.h"
12 #include "base/observer_list.h"
13 #include "chromeos/dbus/dbus_method_call_status.h"
14 #include "components/arc/session/arc_start_params.h"
15 #include "components/arc/session/arc_upgrade_params.h"
16 
17 namespace cryptohome {
18 class Identification;
19 }  // namespace cryptohome
20 
21 namespace arc {
22 
23 // An adapter to talk to a Chrome OS daemon to manage lifetime of ARC instance.
24 class ArcClientAdapter {
25  public:
26   class Observer {
27    public:
28     virtual ~Observer() = default;
29     virtual void ArcInstanceStopped() = 0;
30   };
31 
32   // Creates a default instance of ArcClientAdapter.
33   static std::unique_ptr<ArcClientAdapter> Create();
34   virtual ~ArcClientAdapter();
35 
36   // StartMiniArc starts ARC with only a handful of ARC processes for Chrome OS
37   // login screen.
38   virtual void StartMiniArc(StartParams params,
39                             chromeos::VoidDBusMethodCallback callback) = 0;
40 
41   // UpgradeArc upgrades a mini ARC instance to a full ARC instance.
42   virtual void UpgradeArc(UpgradeParams params,
43                           chromeos::VoidDBusMethodCallback callback) = 0;
44 
45   // Asynchronously stops the ARC instance. |on_shutdown| is true if the method
46   // is called due to the browser being shut down. Also backs up the ARC
47   // bug report if |should_backup_log| is set to true.
48   virtual void StopArcInstance(bool on_shutdown, bool should_backup_log) = 0;
49 
50   // Sets a hash string of the profile user IDs and an ARC serial number for the
51   // user.
52   virtual void SetUserInfo(const cryptohome::Identification& cryptohome_id,
53                            const std::string& hash,
54                            const std::string& serial_number) = 0;
55 
56   void AddObserver(Observer* observer);
57   void RemoveObserver(Observer* observer);
58 
59  protected:
60   ArcClientAdapter();
61 
62   base::ObserverList<Observer>::Unchecked observer_list_;
63 
64  private:
65   DISALLOW_COPY_AND_ASSIGN(ArcClientAdapter);
66 };
67 
68 }  // namespace arc
69 
70 #endif  // COMPONENTS_ARC_SESSION_ARC_CLIENT_ADAPTER_H_
71