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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 68 } |
69 | 69 |
70 void ArcBridgeServiceImpl::StopInstance() { | 70 void ArcBridgeServiceImpl::StopInstance() { |
71 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
72 if (state() == State::STOPPED || state() == State::STOPPING) { | 72 if (state() == State::STOPPED || state() == State::STOPPING) { |
73 VLOG(1) << "StopInstance() called when ARC is not running"; | 73 VLOG(1) << "StopInstance() called when ARC is not running"; |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 SetState(State::STOPPING); | 77 SetState(State::STOPPING); |
78 instance_ptr_.reset(); | |
79 if (binding_.is_bound()) | |
80 binding_.Close(); | |
78 bootstrap_->Stop(); | 81 bootstrap_->Stop(); |
79 } | 82 } |
80 | 83 |
81 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { | 84 void ArcBridgeServiceImpl::OnArcAvailable(bool arc_available) { |
82 DCHECK(CalledOnValidThread()); | 85 DCHECK(CalledOnValidThread()); |
83 if (available() == arc_available) | 86 if (available() == arc_available) |
84 return; | 87 return; |
85 SetAvailable(arc_available); | 88 SetAvailable(arc_available); |
86 PrerequisitesChanged(); | 89 PrerequisitesChanged(); |
87 } | 90 } |
88 | 91 |
89 void ArcBridgeServiceImpl::OnConnectionEstablished( | 92 void ArcBridgeServiceImpl::OnConnectionEstablished( |
90 ArcBridgeInstancePtr instance) { | 93 ArcBridgeInstancePtr instance) { |
91 DCHECK(CalledOnValidThread()); | 94 DCHECK(CalledOnValidThread()); |
92 if (state() != State::CONNECTING) { | 95 if (state() != State::CONNECTING) { |
93 VLOG(1) << "StopInstance() called while connecting"; | 96 VLOG(1) << "StopInstance() called while connecting"; |
94 return; | 97 return; |
95 } | 98 } |
96 | 99 |
97 instance_ptr_ = std::move(instance); | 100 instance_ptr_ = std::move(instance); |
98 | 101 |
99 ArcBridgeHostPtr host; | 102 ArcBridgeHostPtr host; |
100 binding_.Bind(GetProxy(&host)); | 103 binding_.Bind(GetProxy(&host)); |
101 instance_ptr_->Init(std::move(host)); | 104 instance_ptr_->Init(std::move(host)); |
105 instance_ptr_.set_connection_error_handler(base::Bind( | |
hidehiko
2015/12/29 13:27:12
This should be called before Init() invocation? (I
Luis Héctor Chávez
2015/12/29 17:17:36
Done.
| |
106 &ArcBridgeServiceImpl::OnChannelClosed, weak_factory_.GetWeakPtr())); | |
102 | 107 |
103 SetState(State::READY); | 108 SetState(State::READY); |
104 } | 109 } |
105 | 110 |
106 void ArcBridgeServiceImpl::OnStopped() { | 111 void ArcBridgeServiceImpl::OnStopped() { |
107 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
108 SetState(State::STOPPED); | 113 SetState(State::STOPPED); |
114 if (reconnect_) { | |
115 // There was a previous invocation and it crashed for some reason. Try | |
116 // starting the container again. | |
117 reconnect_ = false; | |
118 PrerequisitesChanged(); | |
119 } | |
120 } | |
121 | |
122 void ArcBridgeServiceImpl::OnChannelClosed() { | |
hidehiko
2015/12/29 13:27:12
In the following scenario:
- the channel is accid
Luis Héctor Chávez
2015/12/29 17:17:36
In those cases StopInstance() is not called direct
| |
123 DCHECK(CalledOnValidThread()); | |
124 if (state() == State::STOPPED || state() == State::STOPPING) { | |
125 // This will happen when the instance is shut down. Ignore that case. | |
126 return; | |
127 } | |
128 VLOG(1) << "Mojo connection lost"; | |
129 CloseAllChannels(); | |
130 reconnect_ = true; | |
131 StopInstance(); | |
109 } | 132 } |
110 | 133 |
111 } // namespace arc | 134 } // namespace arc |
OLD | NEW |