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

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

Issue 2133653002: arc: Notify ARC instance failures via callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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
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.h" 5 #include "components/arc/arc_bridge_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/sequenced_task_runner.h" 10 #include "base/sequenced_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "chromeos/chromeos_switches.h" 12 #include "chromeos/chromeos_switches.h"
13 13
14 namespace arc { 14 namespace arc {
15 15
16 // Weak pointer. This class is owned by ArcServiceManager. 16 // Weak pointer. This class is owned by ArcServiceManager.
17 ArcBridgeService* g_arc_bridge_service = nullptr; 17 ArcBridgeService* g_arc_bridge_service = nullptr;
18 18
19 ArcBridgeService::ArcBridgeService() 19 ArcBridgeService::ArcBridgeService()
20 : available_(false), state_(State::STOPPED), weak_factory_(this) { 20 : available_(false),
21 } 21 state_(State::STOPPED),
22 stop_reason_(StopReason::NO_ERROR),
23 weak_factory_(this) {}
22 24
23 ArcBridgeService::~ArcBridgeService() { 25 ArcBridgeService::~ArcBridgeService() {
24 DCHECK(CalledOnValidThread()); 26 DCHECK(CalledOnValidThread());
25 DCHECK(state() == State::STOPPING || state() == State::STOPPED); 27 DCHECK(state() == State::STOPPING || state() == State::STOPPED);
26 } 28 }
27 29
28 // static 30 // static
29 ArcBridgeService* ArcBridgeService::Get() { 31 ArcBridgeService* ArcBridgeService::Get() {
30 if (!g_arc_bridge_service) { 32 if (!g_arc_bridge_service) {
31 // ArcBridgeService may be indirectly referenced in unit tests where 33 // ArcBridgeService may be indirectly referenced in unit tests where
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 void ArcBridgeService::SetState(State state) { 579 void ArcBridgeService::SetState(State state) {
578 DCHECK(CalledOnValidThread()); 580 DCHECK(CalledOnValidThread());
579 // DCHECK on enum classes not supported. 581 // DCHECK on enum classes not supported.
580 DCHECK(state_ != state); 582 DCHECK(state_ != state);
581 state_ = state; 583 state_ = state;
582 VLOG(2) << "State: " << static_cast<uint32_t>(state_); 584 VLOG(2) << "State: " << static_cast<uint32_t>(state_);
583 FOR_EACH_OBSERVER(Observer, observer_list(), OnStateChanged(state_)); 585 FOR_EACH_OBSERVER(Observer, observer_list(), OnStateChanged(state_));
584 if (state_ == State::READY) 586 if (state_ == State::READY)
585 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady()); 587 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeReady());
586 else if (state == State::STOPPED) 588 else if (state == State::STOPPED)
587 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped()); 589 FOR_EACH_OBSERVER(Observer, observer_list(), OnBridgeStopped(stop_reason_));
588 } 590 }
589 591
590 void ArcBridgeService::SetAvailable(bool available) { 592 void ArcBridgeService::SetAvailable(bool available) {
591 DCHECK(CalledOnValidThread()); 593 DCHECK(CalledOnValidThread());
592 DCHECK(available_ != available); 594 DCHECK(available_ != available);
593 available_ = available; 595 available_ = available;
594 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_)); 596 FOR_EACH_OBSERVER(Observer, observer_list(), OnAvailableChanged(available_));
595 } 597 }
596 598
599 void ArcBridgeService::SetStopReason(StopReason stop_reason) {
600 DCHECK(CalledOnValidThread());
601 stop_reason_ = stop_reason;
602 }
603
597 bool ArcBridgeService::CalledOnValidThread() { 604 bool ArcBridgeService::CalledOnValidThread() {
598 return thread_checker_.CalledOnValidThread(); 605 return thread_checker_.CalledOnValidThread();
599 } 606 }
600 607
601 void ArcBridgeService::CloseAllChannels() { 608 void ArcBridgeService::CloseAllChannels() {
602 // Call all the error handlers of all the channels to both close the channel 609 // Call all the error handlers of all the channels to both close the channel
603 // and notify any observers that the channel is closed. 610 // and notify any observers that the channel is closed.
604 CloseAppChannel(); 611 CloseAppChannel();
605 CloseAudioChannel(); 612 CloseAudioChannel();
606 CloseAuthChannel(); 613 CloseAuthChannel();
607 CloseBluetoothChannel(); 614 CloseBluetoothChannel();
608 CloseClipboardChannel(); 615 CloseClipboardChannel();
609 CloseCrashCollectorChannel(); 616 CloseCrashCollectorChannel();
610 CloseFileSystemChannel(); 617 CloseFileSystemChannel();
611 CloseImeChannel(); 618 CloseImeChannel();
612 CloseIntentHelperChannel(); 619 CloseIntentHelperChannel();
613 CloseMetricsChannel(); 620 CloseMetricsChannel();
614 CloseNetChannel(); 621 CloseNetChannel();
615 CloseNotificationsChannel(); 622 CloseNotificationsChannel();
616 CloseObbMounterChannel(); 623 CloseObbMounterChannel();
617 ClosePolicyChannel(); 624 ClosePolicyChannel();
618 ClosePowerChannel(); 625 ClosePowerChannel();
619 CloseProcessChannel(); 626 CloseProcessChannel();
620 CloseStorageManagerChannel(); 627 CloseStorageManagerChannel();
621 CloseVideoChannel(); 628 CloseVideoChannel();
622 CloseWindowManagerChannel(); 629 CloseWindowManagerChannel();
623 } 630 }
624 631
625 } // namespace arc 632 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698