Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: components/arc/arc_bridge_service_impl.cc

Issue 1548833002: arc-bridge: Restart ARC instance on crash (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Addressed more feedback Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/arc/arc_bridge_service_impl.h ('k') | components/arc/arc_bridge_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
101 instance_ptr_.set_connection_error_handler(base::Bind(
102 &ArcBridgeServiceImpl::OnChannelClosed, weak_factory_.GetWeakPtr()));
98 103
99 ArcBridgeHostPtr host; 104 ArcBridgeHostPtr host;
100 binding_.Bind(GetProxy(&host)); 105 binding_.Bind(GetProxy(&host));
101 instance_ptr_->Init(std::move(host)); 106 instance_ptr_->Init(std::move(host));
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() {
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
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_service_impl.h ('k') | components/arc/arc_bridge_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698