Index: components/arc/arc_bridge_service.cc |
diff --git a/components/arc/arc_bridge_service.cc b/components/arc/arc_bridge_service.cc |
index 3c5f391482c31b691da219c83ac3ec743abceacf..c469bae849cad85178849ba9502b65c7bb5b4fb1 100644 |
--- a/components/arc/arc_bridge_service.cc |
+++ b/components/arc/arc_bridge_service.cc |
@@ -22,7 +22,7 @@ ArcBridgeService* g_arc_bridge_service = nullptr; |
} // namespace |
ArcBridgeService::ArcBridgeService() |
- : available_(false), state_(State::STOPPED) { |
+ : available_(false), state_(State::STOPPED), weak_factory_(this) { |
DCHECK(!g_arc_bridge_service); |
g_arc_bridge_service = this; |
} |
@@ -60,12 +60,34 @@ void ArcBridgeService::OnAppInstanceReady(AppInstancePtr app_ptr) { |
DCHECK(CalledOnValidThread()); |
app_ptr_ = std::move(app_ptr); |
FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceReady()); |
+ app_ptr_.set_connection_error_handler(base::Bind( |
+ &ArcBridgeService::OnAppChannelClosed, weak_factory_.GetWeakPtr())); |
+} |
+ |
+void ArcBridgeService::OnAppChannelClosed() { |
+ DCHECK(CalledOnValidThread()); |
+ if (!app_ptr_) |
+ return; |
+ |
+ app_ptr_.reset(); |
+ FOR_EACH_OBSERVER(Observer, observer_list(), OnAppInstanceClosed()); |
} |
void ArcBridgeService::OnInputInstanceReady(InputInstancePtr input_ptr) { |
DCHECK(CalledOnValidThread()); |
input_ptr_ = std::move(input_ptr); |
FOR_EACH_OBSERVER(Observer, observer_list(), OnInputInstanceReady()); |
+ input_ptr_.set_connection_error_handler(base::Bind( |
+ &ArcBridgeService::OnInputChannelClosed, weak_factory_.GetWeakPtr())); |
+} |
+ |
+void ArcBridgeService::OnInputChannelClosed() { |
+ DCHECK(CalledOnValidThread()); |
+ if (!input_ptr_) |
+ return; |
+ |
+ input_ptr_.reset(); |
+ FOR_EACH_OBSERVER(Observer, observer_list(), OnInputInstanceClosed()); |
} |
void ArcBridgeService::OnNotificationsInstanceReady( |
@@ -73,18 +95,52 @@ void ArcBridgeService::OnNotificationsInstanceReady( |
DCHECK(CalledOnValidThread()); |
notifications_ptr_ = std::move(notifications_ptr); |
FOR_EACH_OBSERVER(Observer, observer_list(), OnNotificationsInstanceReady()); |
+ notifications_ptr_.set_connection_error_handler( |
+ base::Bind(&ArcBridgeService::OnNotificationsChannelClosed, |
+ weak_factory_.GetWeakPtr())); |
+} |
+ |
+void ArcBridgeService::OnNotificationsChannelClosed() { |
+ DCHECK(CalledOnValidThread()); |
+ if (!notifications_ptr_) |
+ return; |
+ |
+ notifications_ptr_.reset(); |
+ FOR_EACH_OBSERVER(Observer, observer_list(), OnNotificationsInstanceClosed()); |
} |
void ArcBridgeService::OnPowerInstanceReady(PowerInstancePtr power_ptr) { |
DCHECK(CalledOnValidThread()); |
power_ptr_ = std::move(power_ptr); |
FOR_EACH_OBSERVER(Observer, observer_list(), OnPowerInstanceReady()); |
+ power_ptr_.set_connection_error_handler(base::Bind( |
+ &ArcBridgeService::OnPowerChannelClosed, weak_factory_.GetWeakPtr())); |
+} |
+ |
+void ArcBridgeService::OnPowerChannelClosed() { |
+ DCHECK(CalledOnValidThread()); |
+ if (!power_ptr_) |
+ return; |
+ |
+ power_ptr_.reset(); |
+ FOR_EACH_OBSERVER(Observer, observer_list(), OnPowerInstanceClosed()); |
} |
void ArcBridgeService::OnProcessInstanceReady(ProcessInstancePtr process_ptr) { |
DCHECK(CalledOnValidThread()); |
process_ptr_ = std::move(process_ptr); |
FOR_EACH_OBSERVER(Observer, observer_list(), OnProcessInstanceReady()); |
+ process_ptr_.set_connection_error_handler(base::Bind( |
+ &ArcBridgeService::OnProcessChannelClosed, weak_factory_.GetWeakPtr())); |
+} |
+ |
+void ArcBridgeService::OnProcessChannelClosed() { |
+ DCHECK(CalledOnValidThread()); |
+ if (!process_ptr_) |
+ return; |
+ |
+ process_ptr_.reset(); |
+ FOR_EACH_OBSERVER(Observer, observer_list(), OnProcessInstanceClosed()); |
} |
void ArcBridgeService::OnSettingsInstanceReady( |
@@ -92,6 +148,17 @@ void ArcBridgeService::OnSettingsInstanceReady( |
DCHECK(CalledOnValidThread()); |
settings_ptr_ = std::move(settings_ptr); |
FOR_EACH_OBSERVER(Observer, observer_list(), OnSettingsInstanceReady()); |
+ settings_ptr_.set_connection_error_handler(base::Bind( |
+ &ArcBridgeService::OnSettingsChannelClosed, weak_factory_.GetWeakPtr())); |
+} |
+ |
+void ArcBridgeService::OnSettingsChannelClosed() { |
+ DCHECK(CalledOnValidThread()); |
+ if (!settings_ptr_) |
+ return; |
+ |
+ settings_ptr_.reset(); |
+ FOR_EACH_OBSERVER(Observer, observer_list(), OnSettingsInstanceClosed()); |
} |
void ArcBridgeService::SetState(State state) { |
@@ -113,4 +180,13 @@ bool ArcBridgeService::CalledOnValidThread() { |
return thread_checker_.CalledOnValidThread(); |
} |
+void ArcBridgeService::CloseAllChannels() { |
hidehiko
2015/12/29 13:27:12
This method looks not actually close the channels?
Luis Héctor Chávez
2015/12/29 17:17:36
It does, but let me add a comment to make it more
hidehiko
2016/01/05 08:17:13
Oh, I was confused by the name.
So, let's rename t
Luis Héctor Chávez
2016/01/05 18:59:21
When there is an error, Mojo closes the channel fi
|
+ OnAppChannelClosed(); |
+ OnInputChannelClosed(); |
+ OnNotificationsChannelClosed(); |
+ OnPowerChannelClosed(); |
+ OnProcessChannelClosed(); |
+ OnSettingsChannelClosed(); |
+} |
+ |
} // namespace arc |