| 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 "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 void ArcSessionManager::OnSessionStopped(ArcStopReason reason, | 206 void ArcSessionManager::OnSessionStopped(ArcStopReason reason, |
| 207 bool restarting) { | 207 bool restarting) { |
| 208 if (restarting) { | 208 if (restarting) { |
| 209 // If ARC is being restarted, here do nothing, and just wait for its | 209 // If ARC is being restarted, here do nothing, and just wait for its |
| 210 // next run. | 210 // next run. |
| 211 VLOG(1) << "ARC session is stopped, but being restarted: " << reason; | 211 VLOG(1) << "ARC session is stopped, but being restarted: " << reason; |
| 212 return; | 212 return; |
| 213 } | 213 } |
| 214 | 214 |
| 215 SetState(State::STOPPED); |
| 216 |
| 215 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 217 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 216 if (arc_sign_in_timer_.IsRunning()) | 218 if (arc_sign_in_timer_.IsRunning()) |
| 217 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 219 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
| 218 | 220 |
| 219 for (auto& observer : observer_list_) | 221 for (auto& observer : observer_list_) |
| 220 observer.OnArcSessionStopped(reason); | 222 observer.OnArcSessionStopped(reason); |
| 221 | 223 |
| 222 // Transition to the ARC data remove state. | |
| 223 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | |
| 224 // TODO(crbug.com/665316): This is the workaround for the bug. | |
| 225 // If it is not necessary to remove the data, MaybeStartArcDataRemoval() | |
| 226 // synchronously calls MaybeReenableArc(), which causes unexpected | |
| 227 // ARC session stop. (Please see the bug for details). | |
| 228 SetState(State::REMOVING_DATA_DIR); | |
| 229 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 230 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, | |
| 231 weak_ptr_factory_.GetWeakPtr())); | |
| 232 return; | |
| 233 } | |
| 234 | |
| 235 MaybeStartArcDataRemoval(); | 224 MaybeStartArcDataRemoval(); |
| 236 } | 225 } |
| 237 | 226 |
| 238 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { | 227 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { |
| 239 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 228 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 240 | 229 |
| 241 // If the Mojo message to notify finishing the provisioning is already sent | 230 // If the Mojo message to notify finishing the provisioning is already sent |
| 242 // from the container, it will be processed even after requesting to stop the | 231 // from the container, it will be processed even after requesting to stop the |
| 243 // container. Ignore all |result|s arriving while ARC is disabled, in order to | 232 // container. Ignore all |result|s arriving while ARC is disabled, in order to |
| 244 // avoid popping up an error message triggered below. This code intentionally | 233 // avoid popping up an error message triggered below. This code intentionally |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 ShutdownSession(); | 861 ShutdownSession(); |
| 873 if (support_host_) | 862 if (support_host_) |
| 874 support_host_->Close(); | 863 support_host_->Close(); |
| 875 } | 864 } |
| 876 | 865 |
| 877 void ArcSessionManager::MaybeStartArcDataRemoval() { | 866 void ArcSessionManager::MaybeStartArcDataRemoval() { |
| 878 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 867 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 879 DCHECK(profile_); | 868 DCHECK(profile_); |
| 880 // Data removal cannot run in parallel with ARC session. | 869 // Data removal cannot run in parallel with ARC session. |
| 881 DCHECK(arc_session_runner_->IsStopped()); | 870 DCHECK(arc_session_runner_->IsStopped()); |
| 882 | 871 DCHECK_EQ(State::STOPPED, state_); |
| 883 // TODO(hidehiko): DCHECK the previous state, when the state machine is | |
| 884 // fixed. | |
| 885 SetState(State::REMOVING_DATA_DIR); | 872 SetState(State::REMOVING_DATA_DIR); |
| 886 | 873 |
| 887 // TODO(hidehiko): Extract the implementation of data removal, so that | 874 // TODO(hidehiko): Extract the implementation of data removal, so that |
| 888 // shutdown can cancel the operation not to call OnArcDataRemoved callback. | 875 // shutdown can cancel the operation not to call OnArcDataRemoved callback. |
| 889 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 876 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 890 // ARC data removal is not requested. Just move to the next state. | 877 // ARC data removal is not requested. Just move to the next state. |
| 891 MaybeReenableArc(); | 878 MaybeReenableArc(); |
| 892 return; | 879 return; |
| 893 } | 880 } |
| 894 | 881 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 | 1036 |
| 1050 #undef MAP_STATE | 1037 #undef MAP_STATE |
| 1051 | 1038 |
| 1052 // Some compilers report an error even if all values of an enum-class are | 1039 // Some compilers report an error even if all values of an enum-class are |
| 1053 // covered exhaustively in a switch statement. | 1040 // covered exhaustively in a switch statement. |
| 1054 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 1041 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 1055 return os; | 1042 return os; |
| 1056 } | 1043 } |
| 1057 | 1044 |
| 1058 } // namespace arc | 1045 } // namespace arc |
| OLD | NEW |