OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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_BRIDGE_SERVICE_IMPL_H_ |
| 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
| 7 |
| 8 #include "base/files/scoped_file.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/sequenced_task_runner.h" |
| 11 #include "components/arc/arc_bridge_service.h" |
| 12 #include "ipc/ipc_channel_proxy.h" |
| 13 #include "ipc/ipc_listener.h" |
| 14 #include "ipc/ipc_message.h" |
| 15 |
| 16 namespace arc { |
| 17 |
| 18 // Real IPC based ArcBridgeService that is used in production. |
| 19 class ArcBridgeServiceImpl : public ArcBridgeService, |
| 20 public IPC::Listener { |
| 21 public: |
| 22 |
| 23 ArcBridgeServiceImpl( |
| 24 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 25 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
| 26 ~ArcBridgeServiceImpl() override; |
| 27 |
| 28 // DetectAvailability() should be called once D-Bus is available. It will |
| 29 // call CheckArcAvailability() on the session_manager. This can only be |
| 30 // called on the thread that this class was created on. |
| 31 void DetectAvailability(); |
| 32 |
| 33 void HandleStartup() override; |
| 34 |
| 35 void Shutdown() override; |
| 36 |
| 37 bool RegisterInputDevice(const std::string& name, |
| 38 const std::string& device_type, |
| 39 base::ScopedFD fd) override; |
| 40 |
| 41 // Requests to refresh an app list. |
| 42 bool RefreshApps() override; |
| 43 |
| 44 // Requests to launch an app. |
| 45 bool LaunchApp(const std::string& package, |
| 46 const std::string& activity) override; |
| 47 |
| 48 // Request to load icon of specific scale_factor. |
| 49 bool RequestIcon(const std::string& package, |
| 50 const std::string& activity, |
| 51 int scale_factor) override; |
| 52 |
| 53 private: |
| 54 friend class ArcBridgeTest; |
| 55 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
| 56 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
| 57 |
| 58 // If all pre-requisites are true (ARC is available, it has been enabled, and |
| 59 // the session has started), and ARC is stopped, start ARC. If ARC is running |
| 60 // and the pre-requisites stop being true, stop ARC. |
| 61 void PrerequisitesChanged(); |
| 62 |
| 63 // Binds to the socket specified by |socket_path|. |
| 64 void SocketConnect(const base::FilePath& socket_path); |
| 65 |
| 66 // Binds to the socket specified by |socket_path| after creating its parent |
| 67 // directory is present. |
| 68 void SocketConnectAfterEnsureParentDirectory( |
| 69 const base::FilePath& socket_path, |
| 70 bool directory_present); |
| 71 |
| 72 // Internal connection method. Separated to make testing easier. |
| 73 bool Connect(const IPC::ChannelHandle& handle, IPC::Channel::Mode mode); |
| 74 |
| 75 // Finishes connecting after setting socket permissions. |
| 76 void SocketConnectAfterSetSocketPermissions(const base::FilePath& socket_path, |
| 77 bool socket_permissions_success); |
| 78 |
| 79 // Stops the running instance. |
| 80 void StopInstance(); |
| 81 |
| 82 // Called when the ARC instance has finished setting up and is ready for user |
| 83 // interaction. |
| 84 void OnInstanceReady(); |
| 85 |
| 86 // Called whenever ARC sends information about available apps. |
| 87 void OnAppsRefreshed(const std::vector<std::string>& name, |
| 88 const std::vector<std::string>& packages, |
| 89 const std::vector<std::string>& activities); |
| 90 |
| 91 // Called whenever ARC sends app icon data for specific scale factor. |
| 92 void OnAppIcon(const std::string& package, |
| 93 const std::string& activity, |
| 94 int scale_factor, |
| 95 const std::vector<uint8_t>& icon_png_data); |
| 96 |
| 97 // IPC::Listener: |
| 98 bool OnMessageReceived(const IPC::Message& message) override; |
| 99 |
| 100 // DBus callbacks. |
| 101 void OnArcAvailable(bool available); |
| 102 void OnInstanceStarted(bool success); |
| 103 void OnInstanceStopped(bool success); |
| 104 |
| 105 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
| 106 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
| 107 |
| 108 scoped_ptr<IPC::ChannelProxy> ipc_channel_; |
| 109 |
| 110 // If the user's session has started. |
| 111 bool session_started_; |
| 112 |
| 113 // WeakPtrFactory to use callbacks. |
| 114 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); |
| 117 }; |
| 118 |
| 119 } // namespace arc |
| 120 |
| 121 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_ |
OLD | NEW |