OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/arc/arc_bridge_service.h" | 5 #include "components/arc/arc_bridge_service.h" |
6 | 6 |
7 #include "base/command_line.h" | |
7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
9 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
11 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #include "chromeos/chromeos_switches.h" | |
13 #include "chromeos/dbus/dbus_method_call_status.h" | 15 #include "chromeos/dbus/dbus_method_call_status.h" |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "chromeos/dbus/session_manager_client.h" | 17 #include "chromeos/dbus/session_manager_client.h" |
16 #include "components/arc/common/arc_host_messages.h" | 18 #include "components/arc/common/arc_host_messages.h" |
17 #include "components/arc/common/arc_instance_messages.h" | 19 #include "components/arc/common/arc_instance_messages.h" |
18 #include "ipc/ipc_channel.h" | 20 #include "ipc/ipc_channel.h" |
19 | 21 |
20 namespace arc { | 22 namespace arc { |
21 | 23 |
22 namespace { | 24 namespace { |
(...skipping 27 matching lines...) Expand all Loading... | |
50 g_arc_bridge_service = nullptr; | 52 g_arc_bridge_service = nullptr; |
51 } | 53 } |
52 | 54 |
53 // static | 55 // static |
54 ArcBridgeService* ArcBridgeService::Get() { | 56 ArcBridgeService* ArcBridgeService::Get() { |
55 DCHECK(g_arc_bridge_service); | 57 DCHECK(g_arc_bridge_service); |
56 DCHECK(g_arc_bridge_service->origin_task_runner_->RunsTasksOnCurrentThread()); | 58 DCHECK(g_arc_bridge_service->origin_task_runner_->RunsTasksOnCurrentThread()); |
57 return g_arc_bridge_service; | 59 return g_arc_bridge_service; |
58 } | 60 } |
59 | 61 |
62 // static | |
63 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { | |
64 return command_line->HasSwitch(chromeos::switches::kEnableArc); | |
65 } | |
66 | |
60 void ArcBridgeService::DetectAvailability() { | 67 void ArcBridgeService::DetectAvailability() { |
61 chromeos::SessionManagerClient* session_manager_client = | 68 chromeos::SessionManagerClient* session_manager_client = |
62 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 69 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
63 session_manager_client->CheckArcAvailability(base::Bind( | 70 session_manager_client->CheckArcAvailability(base::Bind( |
64 &ArcBridgeService::OnArcAvailable, weak_factory_.GetWeakPtr())); | 71 &ArcBridgeService::OnArcAvailable, weak_factory_.GetWeakPtr())); |
65 } | 72 } |
66 | 73 |
67 void ArcBridgeService::HandleStartup() { | 74 void ArcBridgeService::HandleStartup() { |
68 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 75 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
69 session_started_ = true; | 76 session_started_ = true; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 } | 233 } |
227 if (!success) { | 234 if (!success) { |
228 LOG(ERROR) << "ARC instance unable to start. Shutting down the bridge"; | 235 LOG(ERROR) << "ARC instance unable to start. Shutting down the bridge"; |
229 StopInstance(); | 236 StopInstance(); |
230 return; | 237 return; |
231 } | 238 } |
232 } | 239 } |
233 | 240 |
234 void ArcBridgeService::OnInstanceBootPhase(InstanceBootPhase phase) { | 241 void ArcBridgeService::OnInstanceBootPhase(InstanceBootPhase phase) { |
235 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 242 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
236 if (state_ != State::STARTING) { | 243 // The state can be STARTING the first time this is called, and will then |
244 // transition to READY after BRIDGE_READY has been passed. | |
245 if (state_ != State::STARTING && state_ != State::READY) { | |
elijahtaylor (use chromium)
2015/11/23 18:01:04
this doesn't seem related to the flag, what is thi
Luis Héctor Chávez
2015/11/23 18:02:45
This is a fix for a test breakage that we did not
| |
237 VLOG(1) << "StopInstance() called while connecting"; | 246 VLOG(1) << "StopInstance() called while connecting"; |
238 return; | 247 return; |
239 } | 248 } |
240 if (phase == InstanceBootPhase::BRIDGE_READY) { | 249 if (phase == InstanceBootPhase::BRIDGE_READY) { |
241 SetState(State::READY); | 250 SetState(State::READY); |
242 } | 251 } |
243 FOR_EACH_OBSERVER(Observer, observer_list_, OnInstanceBootPhase(phase)); | 252 FOR_EACH_OBSERVER(Observer, observer_list_, OnInstanceBootPhase(phase)); |
244 } | 253 } |
245 | 254 |
246 void ArcBridgeService::SetState(State state) { | 255 void ArcBridgeService::SetState(State state) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 void ArcBridgeService::OnInstanceStopped(bool success) { | 287 void ArcBridgeService::OnInstanceStopped(bool success) { |
279 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); | 288 DCHECK(origin_task_runner_->RunsTasksOnCurrentThread()); |
280 // STOPPING is the only valid state for this function. | 289 // STOPPING is the only valid state for this function. |
281 // DCHECK on enum classes not supported. | 290 // DCHECK on enum classes not supported. |
282 DCHECK(state_ == State::STOPPING); | 291 DCHECK(state_ == State::STOPPING); |
283 ipc_channel_.reset(); | 292 ipc_channel_.reset(); |
284 SetState(State::STOPPED); | 293 SetState(State::STOPPED); |
285 } | 294 } |
286 | 295 |
287 } // namespace arc | 296 } // namespace arc |
OLD | NEW |