| 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_impl.h" | 5 #include "components/arc/arc_bridge_service_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chromeos/chromeos_switches.h" | 17 #include "chromeos/chromeos_switches.h" |
| 18 #include "chromeos/dbus/dbus_method_call_status.h" | 18 #include "chromeos/dbus/dbus_method_call_status.h" |
| 19 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "components/arc/arc_session.h" |
| 20 #include "components/prefs/pref_registry_simple.h" | 21 #include "components/prefs/pref_registry_simple.h" |
| 21 #include "components/prefs/pref_service.h" | 22 #include "components/prefs/pref_service.h" |
| 22 | 23 |
| 23 namespace arc { | 24 namespace arc { |
| 24 namespace { | 25 namespace { |
| 25 constexpr int64_t kReconnectDelayInSeconds = 5; | 26 constexpr int64_t kReconnectDelayInSeconds = 5; |
| 26 } // namespace | 27 } // namespace |
| 27 | 28 |
| 28 ArcBridgeServiceImpl::ArcBridgeServiceImpl( | 29 ArcBridgeServiceImpl::ArcBridgeServiceImpl( |
| 29 const scoped_refptr<base::TaskRunner>& blocking_task_runner) | 30 const scoped_refptr<base::TaskRunner>& blocking_task_runner) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 reconnect_ = false; | 113 reconnect_ = false; |
| 113 | 114 |
| 114 VLOG(1) << "Stopping ARC"; | 115 VLOG(1) << "Stopping ARC"; |
| 115 DCHECK(arc_session_.get()); | 116 DCHECK(arc_session_.get()); |
| 116 SetState(State::STOPPING); | 117 SetState(State::STOPPING); |
| 117 | 118 |
| 118 // Note: this can call OnStopped() internally as a callback. | 119 // Note: this can call OnStopped() internally as a callback. |
| 119 arc_session_->Stop(); | 120 arc_session_->Stop(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void ArcBridgeServiceImpl::OnReady() { | 123 void ArcBridgeServiceImpl::OnSessionReady() { |
| 123 DCHECK(CalledOnValidThread()); | 124 DCHECK(CalledOnValidThread()); |
| 124 if (state() != State::CONNECTING) { | 125 if (state() != State::CONNECTING) { |
| 125 VLOG(1) << "StopInstance() called while connecting"; | 126 VLOG(1) << "StopInstance() called while connecting"; |
| 126 return; | 127 return; |
| 127 } | 128 } |
| 128 | 129 |
| 129 // The container can be considered to have been successfully launched, so | 130 // The container can be considered to have been successfully launched, so |
| 130 // restart if the connection goes down without being requested. | 131 // restart if the connection goes down without being requested. |
| 131 reconnect_ = true; | 132 reconnect_ = true; |
| 132 VLOG(0) << "ARC ready"; | 133 VLOG(0) << "ARC ready"; |
| 133 SetState(State::READY); | 134 SetState(State::READY); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void ArcBridgeServiceImpl::OnStopped(StopReason stop_reason) { | 137 void ArcBridgeServiceImpl::OnSessionStopped(StopReason stop_reason) { |
| 137 DCHECK(CalledOnValidThread()); | 138 DCHECK(CalledOnValidThread()); |
| 138 VLOG(0) << "ARC stopped: " << stop_reason; | 139 VLOG(0) << "ARC stopped: " << stop_reason; |
| 139 arc_session_->RemoveObserver(this); | 140 arc_session_->RemoveObserver(this); |
| 140 arc_session_.reset(); | 141 arc_session_.reset(); |
| 141 SetStopReason(stop_reason); | 142 SetStopReason(stop_reason); |
| 142 SetState(State::STOPPED); | 143 SetState(State::STOPPED); |
| 143 | 144 |
| 144 if (reconnect_) { | 145 if (reconnect_) { |
| 145 // There was a previous invocation and it crashed for some reason. Try | 146 // There was a previous invocation and it crashed for some reason. Try |
| 146 // starting the container again. | 147 // starting the container again. |
| 147 reconnect_ = false; | 148 reconnect_ = false; |
| 148 VLOG(0) << "ARC reconnecting"; | 149 VLOG(0) << "ARC reconnecting"; |
| 149 if (use_delay_before_reconnecting_) { | 150 if (use_delay_before_reconnecting_) { |
| 150 // Instead of immediately trying to restart the container, give it some | 151 // Instead of immediately trying to restart the container, give it some |
| 151 // time to finish tearing down in case it is still in the process of | 152 // time to finish tearing down in case it is still in the process of |
| 152 // stopping. | 153 // stopping. |
| 153 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 154 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 154 FROM_HERE, base::Bind(&ArcBridgeServiceImpl::PrerequisitesChanged, | 155 FROM_HERE, base::Bind(&ArcBridgeServiceImpl::PrerequisitesChanged, |
| 155 weak_factory_.GetWeakPtr()), | 156 weak_factory_.GetWeakPtr()), |
| 156 base::TimeDelta::FromSeconds(kReconnectDelayInSeconds)); | 157 base::TimeDelta::FromSeconds(kReconnectDelayInSeconds)); |
| 157 } else { | 158 } else { |
| 158 // Restart immediately. | 159 // Restart immediately. |
| 159 PrerequisitesChanged(); | 160 PrerequisitesChanged(); |
| 160 } | 161 } |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 164 } // namespace arc | 165 } // namespace arc |
| OLD | NEW |