| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/chromeos/arc/arc_session_manager.h" | 5 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // TODO(hidehiko): When the dependency to ArcAuthNotification from this | 135 // TODO(hidehiko): When the dependency to ArcAuthNotification from this |
| 136 // class is removed, we should remove this as well. | 136 // class is removed, we should remove this as well. |
| 137 ArcAuthNotification::DisableForTesting(); | 137 ArcAuthNotification::DisableForTesting(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // static | 140 // static |
| 141 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { | 141 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
| 142 g_enable_check_android_management_for_testing = true; | 142 g_enable_check_android_management_for_testing = true; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void ArcSessionManager::OnSessionReady() { | 145 void ArcSessionManager::OnSessionStopped(ArcStopReason reason, |
| 146 for (auto& observer : arc_session_observer_list_) | 146 bool restarting) { |
| 147 observer.OnSessionReady(); | 147 if (restarting) { |
| 148 } | 148 // If ARC is being restarted, here do nothing, and just wait for its |
| 149 // next run. |
| 150 VLOG(1) << "ARC session is stopped, but being restarted: " << reason; |
| 151 return; |
| 152 } |
| 149 | 153 |
| 150 void ArcSessionManager::OnSessionStopped(StopReason reason) { | |
| 151 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 154 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 152 if (arc_sign_in_timer_.IsRunning()) | 155 if (arc_sign_in_timer_.IsRunning()) |
| 153 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 156 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
| 154 | 157 |
| 155 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 158 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 156 // This should be always true, but just in case as this is looked at | 159 // This should be always true, but just in case as this is looked at |
| 157 // inside RemoveArcData() at first. | 160 // inside RemoveArcData() at first. |
| 158 VLOG(1) << "ARC had previously requested to remove user data."; | 161 VLOG(1) << "ARC had previously requested to remove user data."; |
| 159 DCHECK(arc_session_runner_->IsStopped()); | 162 DCHECK(arc_session_runner_->IsStopped()); |
| 160 RemoveArcData(); | 163 RemoveArcData(); |
| 161 } else { | 164 } else { |
| 162 // To support special "Stop and enable ARC" procedure for enterprise, | 165 // To support special "Stop and enable ARC" procedure for enterprise, |
| 163 // here call MaybeReenableArc() asyncronously. | 166 // here call MaybeReenableArc() asyncronously. |
| 164 // TODO(hidehiko): Restructure the code. crbug.com/665316 | 167 // TODO(hidehiko): Restructure the code. crbug.com/665316 |
| 165 base::ThreadTaskRunnerHandle::Get()->PostTask( | 168 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 166 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, | 169 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, |
| 167 weak_ptr_factory_.GetWeakPtr())); | 170 weak_ptr_factory_.GetWeakPtr())); |
| 168 } | 171 } |
| 169 | 172 |
| 170 for (auto& observer : arc_session_observer_list_) | 173 for (auto& observer : observer_list_) |
| 171 observer.OnSessionStopped(reason); | 174 observer.OnArcSessionStopped(reason); |
| 172 } | 175 } |
| 173 | 176 |
| 174 void ArcSessionManager::RemoveArcData() { | 177 void ArcSessionManager::RemoveArcData() { |
| 175 // Ignore redundant data removal request. | 178 // Ignore redundant data removal request. |
| 176 if (state() == State::REMOVING_DATA_DIR) | 179 if (state() == State::REMOVING_DATA_DIR) |
| 177 return; | 180 return; |
| 178 | 181 |
| 179 // OnArcDataRemoved resets this flag. | 182 // OnArcDataRemoved resets this flag. |
| 180 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); | 183 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| 181 | 184 |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 void ArcSessionManager::AddObserver(Observer* observer) { | 578 void ArcSessionManager::AddObserver(Observer* observer) { |
| 576 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 579 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 577 observer_list_.AddObserver(observer); | 580 observer_list_.AddObserver(observer); |
| 578 } | 581 } |
| 579 | 582 |
| 580 void ArcSessionManager::RemoveObserver(Observer* observer) { | 583 void ArcSessionManager::RemoveObserver(Observer* observer) { |
| 581 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 584 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 582 observer_list_.RemoveObserver(observer); | 585 observer_list_.RemoveObserver(observer); |
| 583 } | 586 } |
| 584 | 587 |
| 585 void ArcSessionManager::AddSessionObserver(ArcSessionObserver* observer) { | |
| 586 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 587 arc_session_observer_list_.AddObserver(observer); | |
| 588 } | |
| 589 | |
| 590 void ArcSessionManager::RemoveSessionObserver(ArcSessionObserver* observer) { | |
| 591 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 592 arc_session_observer_list_.RemoveObserver(observer); | |
| 593 } | |
| 594 | |
| 595 bool ArcSessionManager::IsSessionRunning() const { | 588 bool ArcSessionManager::IsSessionRunning() const { |
| 596 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 589 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 597 return arc_session_runner_->IsRunning(); | 590 return arc_session_runner_->IsRunning(); |
| 598 } | 591 } |
| 599 | 592 |
| 600 bool ArcSessionManager::IsSessionStopped() const { | 593 bool ArcSessionManager::IsSessionStopped() const { |
| 601 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 594 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 602 return arc_session_runner_->IsStopped(); | 595 return arc_session_runner_->IsStopped(); |
| 603 } | 596 } |
| 604 | 597 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 993 |
| 1001 #undef MAP_STATE | 994 #undef MAP_STATE |
| 1002 | 995 |
| 1003 // Some compilers report an error even if all values of an enum-class are | 996 // Some compilers report an error even if all values of an enum-class are |
| 1004 // covered exhaustively in a switch statement. | 997 // covered exhaustively in a switch statement. |
| 1005 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 998 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 1006 return os; | 999 return os; |
| 1007 } | 1000 } |
| 1008 | 1001 |
| 1009 } // namespace arc | 1002 } // namespace arc |
| OLD | NEW |