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 #include "chromeos/arc/bridge/arc_bridge_service.h" | |
6 | |
7 #include "base/files/file_util.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
oshima
2015/10/23 20:29:45
ditto
Luis Héctor Chávez
2015/10/27 00:37:47
Done.
| |
9 #include "chromeos/dbus/arc_instance_client.h" | |
10 #include "chromeos/dbus/dbus_method_call_status.h" | |
11 #include "chromeos/dbus/dbus_thread_manager.h" | |
12 | |
13 namespace { | |
14 | |
15 const char kArcBridgeSocketPath[] = "/home/chronos/ArcBridge/bridge.sock"; | |
satorux1
2015/10/23 06:10:58
should this be shared between here and the chromeo
Luis Héctor Chávez
2015/10/27 00:37:47
There will be no sharing of this constant. It will
| |
16 | |
17 } // namespace | |
18 | |
19 namespace arc { | |
20 | |
21 ArcBridgeService::ArcBridgeService(Profile* profile) | |
22 : BridgeHostEndpoint(), | |
23 enabled_(true), | |
24 running_(false), | |
25 profile_(profile) {} | |
26 | |
27 ArcBridgeService::~ArcBridgeService() {} | |
28 | |
29 void ArcBridgeService::HandleStartup() { | |
30 if (!IsEnabled()) | |
31 return; | |
32 if (!SocketConnect(kArcBridgeSocketPath)) { | |
33 LOG(ERROR) << "ARC++ unable to connect to the socket"; | |
34 return; | |
35 } | |
36 connected_ = true; | |
37 // This will fail if the ArcInstanceService is not running on Chrome OS. | |
38 chromeos::DBusThreadManager::Get()->GetArcInstanceClient()->StartInstance( | |
satorux1
2015/10/23 06:10:58
Is the D-Bus client code checked-in? I'm reviewing
Luis Héctor Chávez
2015/10/27 00:37:47
Not yet, but here's its review: https://codereview
| |
39 kArcBridgeSocketPath, | |
40 base::Bind(&ArcBridgeService::OnInstanceStarted, base::Unretained(this))); | |
satorux1
2015/10/23 06:10:58
Is it safe to base::Unretained() here? Please docu
Luis Héctor Chávez
2015/10/27 00:37:47
Done.
| |
41 } | |
42 | |
43 void ArcBridgeService::Shutdown() { | |
44 if (!connected_) | |
45 return; | |
46 channel_->Close(); | |
satorux1
2015/10/23 06:10:58
channel_ is defined in the parent class right? May
Luis Héctor Chávez
2015/10/27 00:37:47
Done.
| |
47 base::DeleteFile(base::FilePath(kArcBridgeSocketPath), false); | |
48 if (!running_) | |
49 return; | |
50 chromeos::DBusThreadManager::Get()->GetArcInstanceClient()->StopInstance( | |
51 base::Bind(&ArcBridgeService::OnInstanceStopped, base::Unretained(this))); | |
satorux1
2015/10/23 06:10:58
ditto. add a comment about base::Unretained()?
Luis Héctor Chávez
2015/10/27 00:37:47
Done.
| |
52 } | |
53 | |
54 void ArcBridgeService::AddObserver(Observer* observer) { | |
55 observer_list_.AddObserver(observer); | |
56 } | |
57 | |
58 void ArcBridgeService::RemoveObserver(Observer* observer) { | |
59 observer_list_.RemoveObserver(observer); | |
60 } | |
61 | |
62 void ArcBridgeService::OnInstanceStarted(chromeos::DBusMethodCallStatus status, | |
63 bool success) { | |
64 running_ = success; | |
65 if (!running_) { | |
66 LOG(ERROR) << "ARC++ instance unable to start. Shutting down the bridge"; | |
67 Shutdown(); | |
68 } | |
69 FOR_EACH_OBSERVER(Observer, observer_list_, OnInstanceStarted(success)); | |
70 } | |
71 | |
72 void ArcBridgeService::OnInstanceStopped( | |
73 chromeos::DBusMethodCallStatus status) { | |
74 if (running_) | |
75 FOR_EACH_OBSERVER(Observer, observer_list_, OnInstanceStopped()); | |
76 running_ = false; | |
77 } | |
78 | |
79 void ArcBridgeService::OnInstanceReady() { | |
80 FOR_EACH_OBSERVER(Observer, observer_list_, OnInstanceReady()); | |
81 } | |
82 | |
83 void ArcBridgeService::OnPong() {} | |
84 | |
85 } // namespace arc | |
OLD | NEW |