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

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager.cc

Issue 2678273005: arc: Logging ARC data removal reasons (Closed)
Patch Set: Addressed feedback Created 3 years, 10 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 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 161
162 void ArcSessionManager::OnSessionStopped(StopReason reason) { 162 void ArcSessionManager::OnSessionStopped(StopReason reason) {
163 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. 163 // TODO(crbug.com/625923): Use |reason| to report more detailed errors.
164 if (arc_sign_in_timer_.IsRunning()) 164 if (arc_sign_in_timer_.IsRunning())
165 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); 165 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED);
166 166
167 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { 167 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) {
168 // This should be always true, but just in case as this is looked at 168 // This should be always true, but just in case as this is looked at
169 // inside RemoveArcData() at first. 169 // inside RemoveArcData() at first.
170 VLOG(1) << "ARC had previously requested to remove user data.";
170 DCHECK(arc_session_runner_->IsStopped()); 171 DCHECK(arc_session_runner_->IsStopped());
171 RemoveArcData(); 172 RemoveArcData();
172 } else { 173 } else {
173 // To support special "Stop and enable ARC" procedure for enterprise, 174 // To support special "Stop and enable ARC" procedure for enterprise,
174 // here call MaybeReenableArc() asyncronously. 175 // here call MaybeReenableArc() asyncronously.
175 // TODO(hidehiko): Restructure the code. crbug.com/665316 176 // TODO(hidehiko): Restructure the code. crbug.com/665316
176 base::ThreadTaskRunnerHandle::Get()->PostTask( 177 base::ThreadTaskRunnerHandle::Get()->PostTask(
177 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, 178 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc,
178 weak_ptr_factory_.GetWeakPtr())); 179 weak_ptr_factory_.GetWeakPtr()));
179 } 180 }
180 181
181 for (auto& observer : arc_session_observer_list_) 182 for (auto& observer : arc_session_observer_list_)
182 observer.OnSessionStopped(reason); 183 observer.OnSessionStopped(reason);
183 } 184 }
184 185
185 void ArcSessionManager::RemoveArcData() { 186 void ArcSessionManager::RemoveArcData() {
186 // Ignore redundant data removal request. 187 // Ignore redundant data removal request.
187 if (state() == State::REMOVING_DATA_DIR) 188 if (state() == State::REMOVING_DATA_DIR)
188 return; 189 return;
189 190
190 // OnArcDataRemoved resets this flag. 191 // OnArcDataRemoved resets this flag.
191 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); 192 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true);
192 193
193 if (!arc_session_runner_->IsStopped()) { 194 if (!arc_session_runner_->IsStopped()) {
194 // Just set a flag. On session stopped, this will be re-called, 195 // Just set a flag. On session stopped, this will be re-called,
195 // then session manager should remove the data. 196 // then session manager should remove the data.
196 return; 197 return;
197 } 198 }
198 199
200 VLOG(1) << "Starting ARC data removal";
199 SetState(State::REMOVING_DATA_DIR); 201 SetState(State::REMOVING_DATA_DIR);
200 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( 202 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData(
201 cryptohome::Identification( 203 cryptohome::Identification(
202 multi_user_util::GetAccountIdFromProfile(profile_)), 204 multi_user_util::GetAccountIdFromProfile(profile_)),
203 base::Bind(&ArcSessionManager::OnArcDataRemoved, 205 base::Bind(&ArcSessionManager::OnArcDataRemoved,
204 weak_ptr_factory_.GetWeakPtr())); 206 weak_ptr_factory_.GetWeakPtr()));
205 } 207 }
206 208
207 void ArcSessionManager::OnArcDataRemoved(bool success) { 209 void ArcSessionManager::OnArcDataRemoved(bool success) {
208 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; 210 if (success)
211 VLOG(1) << "ARC data removal successful";
212 else
213 LOG(ERROR) << "Request for ARC user data removal failed.";
209 214
210 // TODO(khmel): Browser tests may shutdown profile by itself. Update browser 215 // TODO(khmel): Browser tests may shutdown profile by itself. Update browser
211 // tests and remove this check. 216 // tests and remove this check.
212 if (state() == State::NOT_INITIALIZED) 217 if (state() == State::NOT_INITIALIZED)
213 return; 218 return;
214 219
215 for (auto& observer : observer_list_) 220 for (auto& observer : observer_list_)
216 observer.OnArcDataRemoved(); 221 observer.OnArcDataRemoved();
217 222
218 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); 223 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 playstore_launcher_.reset( 311 playstore_launcher_.reset(
307 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); 312 new ArcAppLauncher(profile_, kPlayStoreAppId, true));
308 } 313 }
309 314
310 for (auto& observer : observer_list_) 315 for (auto& observer : observer_list_)
311 observer.OnArcInitialStart(); 316 observer.OnArcInitialStart();
312 return; 317 return;
313 } 318 }
314 319
315 ArcSupportHost::Error error; 320 ArcSupportHost::Error error;
321 VLOG(1) << "ARC provisioning failed: " << result << ".";
316 switch (result) { 322 switch (result) {
317 case ProvisioningResult::GMS_NETWORK_ERROR: 323 case ProvisioningResult::GMS_NETWORK_ERROR:
318 error = ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR; 324 error = ArcSupportHost::Error::SIGN_IN_NETWORK_ERROR;
319 break; 325 break;
320 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE: 326 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE:
321 case ProvisioningResult::GMS_SIGN_IN_FAILED: 327 case ProvisioningResult::GMS_SIGN_IN_FAILED:
322 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT: 328 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT:
323 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR: 329 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR:
324 error = ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR; 330 error = ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR;
325 break; 331 break;
(...skipping 29 matching lines...) Expand all
355 } 361 }
356 362
357 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 363 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
358 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 364 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
359 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 365 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
360 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is 366 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is
361 // fully setup, but Chrome does not. 367 // fully setup, but Chrome does not.
362 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || 368 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT ||
363 // Just to be safe, remove data if we don't know the cause. 369 // Just to be safe, remove data if we don't know the cause.
364 result == ProvisioningResult::UNKNOWN_ERROR) { 370 result == ProvisioningResult::UNKNOWN_ERROR) {
371 VLOG(1) << "ARC provisioning failed permanently. Removing user data";
365 RemoveArcData(); 372 RemoveArcData();
366 } 373 }
367 374
368 // We'll delay shutting down the ARC instance in this case to allow people 375 // We'll delay shutting down the ARC instance in this case to allow people
369 // to send feedback. 376 // to send feedback.
370 if (support_host_) 377 if (support_host_)
371 support_host_->ShowError(error, true /* = show send feedback button */); 378 support_host_->ShowError(error, true /* = show send feedback button */);
372 } 379 }
373 380
374 void ArcSessionManager::SetState(State state) { 381 void ArcSessionManager::SetState(State state) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 pref_change_registrar_.Init(profile_->GetPrefs()); 433 pref_change_registrar_.Init(profile_->GetPrefs());
427 pref_change_registrar_.Add( 434 pref_change_registrar_.Add(
428 prefs::kArcEnabled, 435 prefs::kArcEnabled,
429 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, 436 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged,
430 weak_ptr_factory_.GetWeakPtr())); 437 weak_ptr_factory_.GetWeakPtr()));
431 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 438 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
432 // Don't start ARC if there is a pending request to remove the data. Restart 439 // Don't start ARC if there is a pending request to remove the data. Restart
433 // ARC once data removal finishes. 440 // ARC once data removal finishes.
434 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { 441 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) {
435 reenable_arc_ = true; 442 reenable_arc_ = true;
443 VLOG(1) << "ARC previously requested to remove data.";
436 RemoveArcData(); 444 RemoveArcData();
437 } else { 445 } else {
438 OnOptInPreferenceChanged(); 446 OnOptInPreferenceChanged();
439 } 447 }
440 } else { 448 } else {
449 VLOG(1) << "ARC disabled on profile. Removing data.";
441 RemoveArcData(); 450 RemoveArcData();
442 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); 451 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
443 OnIsSyncingChanged(); 452 OnIsSyncingChanged();
444 } 453 }
445 } 454 }
446 455
447 void ArcSessionManager::OnIsSyncingChanged() { 456 void ArcSessionManager::OnIsSyncingChanged() {
448 sync_preferences::PrefServiceSyncable* const pref_service_syncable = 457 sync_preferences::PrefServiceSyncable* const pref_service_syncable =
449 PrefServiceSyncableFromProfile(profile_); 458 PrefServiceSyncableFromProfile(profile_);
450 if (!pref_service_syncable->IsSyncing()) 459 if (!pref_service_syncable->IsSyncing())
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 observer.OnArcOptInChanged(arc_enabled); 524 observer.OnArcOptInChanged(arc_enabled);
516 525
517 // Hide auth notification if it was opened before and arc.enabled pref was 526 // Hide auth notification if it was opened before and arc.enabled pref was
518 // explicitly set to true or false. 527 // explicitly set to true or false.
519 if (!g_disable_ui_for_testing && 528 if (!g_disable_ui_for_testing &&
520 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { 529 profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) {
521 ArcAuthNotification::Hide(); 530 ArcAuthNotification::Hide();
522 } 531 }
523 532
524 if (!arc_enabled) { 533 if (!arc_enabled) {
525 // Reset any pending request to re-enable Arc. 534 // Reset any pending request to re-enable ARC.
535 VLOG(1) << "ARC opt-out. Removing user data.";
526 reenable_arc_ = false; 536 reenable_arc_ = false;
527 StopArc(); 537 StopArc();
528 RemoveArcData(); 538 RemoveArcData();
529 return; 539 return;
530 } 540 }
531 541
532 if (state_ == State::ACTIVE) 542 if (state_ == State::ACTIVE)
533 return; 543 return;
534 544
535 if (state_ == State::REMOVING_DATA_DIR) { 545 if (state_ == State::REMOVING_DATA_DIR) {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 } 951 }
942 952
943 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( 953 void ArcSessionManager::SetAttemptUserExitCallbackForTesting(
944 const base::Closure& callback) { 954 const base::Closure& callback) {
945 DCHECK(!callback.is_null()); 955 DCHECK(!callback.is_null());
946 attempt_user_exit_callback_ = callback; 956 attempt_user_exit_callback_ = callback;
947 } 957 }
948 958
949 std::ostream& operator<<(std::ostream& os, 959 std::ostream& operator<<(std::ostream& os,
950 const ArcSessionManager::State& state) { 960 const ArcSessionManager::State& state) {
961 #define MAP_STATE(name) \
962 case ArcSessionManager::State::name: \
963 return os << #name
964
951 switch (state) { 965 switch (state) {
952 case ArcSessionManager::State::NOT_INITIALIZED: 966 MAP_STATE(NOT_INITIALIZED);
953 return os << "NOT_INITIALIZED"; 967 MAP_STATE(STOPPED);
954 case ArcSessionManager::State::STOPPED: 968 MAP_STATE(SHOWING_TERMS_OF_SERVICE);
955 return os << "STOPPED"; 969 MAP_STATE(CHECKING_ANDROID_MANAGEMENT);
956 case ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE: 970 MAP_STATE(REMOVING_DATA_DIR);
957 return os << "SHOWING_TERMS_OF_SERVICE"; 971 MAP_STATE(ACTIVE);
958 case ArcSessionManager::State::CHECKING_ANDROID_MANAGEMENT:
959 return os << "CHECKING_ANDROID_MANAGEMENT";
960 case ArcSessionManager::State::REMOVING_DATA_DIR:
961 return os << "REMOVING_DATA_DIR";
962 case ArcSessionManager::State::ACTIVE:
963 return os << "ACTIVE";
964 } 972 }
965 973
966 // Some compiler reports an error even if all values of an enum-class are 974 #undef MAP_STATE
967 // covered indivisually in a switch statement. 975
968 NOTREACHED(); 976 // Some compilers report an error even if all values of an enum-class are
977 // covered exhaustively in a switch statement.
978 NOTREACHED() << "Invalid value " << static_cast<int>(state);
969 return os; 979 return os;
970 } 980 }
971 981
972 } // namespace arc 982 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698