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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 support_host->ui_page() == ArcSupportHost::UIPage::NO_PAGE || | 70 support_host->ui_page() == ArcSupportHost::UIPage::NO_PAGE || |
71 support_host->ui_page() == ArcSupportHost::UIPage::ERROR) { | 71 support_host->ui_page() == ArcSupportHost::UIPage::ERROR) { |
72 return; | 72 return; |
73 } | 73 } |
74 | 74 |
75 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 75 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
76 } | 76 } |
77 | 77 |
78 } // namespace | 78 } // namespace |
79 | 79 |
80 class ArcSessionManager::ScopedOptInFlowTracker { | |
Luis Héctor Chávez
2017/03/30 17:07:20
Please add a small comment explaining this class a
khmel
2017/03/30 17:21:07
Done.
| |
81 public: | |
82 ScopedOptInFlowTracker() { | |
83 UpdateOptInFlowResultUMA(OptInFlowResult::STARTED); | |
84 } | |
85 | |
86 ~ScopedOptInFlowTracker() { | |
87 if (shutdown_) | |
88 return; | |
89 | |
90 UpdateOptInFlowResultUMA(success_ ? OptInFlowResult::SUCCEEDED | |
91 : OptInFlowResult::CANCELED); | |
92 if (error_) { | |
93 UpdateOptInFlowResultUMA(success_ | |
94 ? OptInFlowResult::SUCCEEDED_AFTER_RETRY | |
95 : OptInFlowResult::CANCELED_AFTER_ERROR); | |
96 } | |
97 } | |
98 | |
99 // Tracks error occurred during the OptIn flow. | |
100 void TrackError() { | |
101 DCHECK(!success_ && !shutdown_); | |
102 error_ = true; | |
103 } | |
104 | |
105 // Tracks that OptIn finished successfully. | |
106 void TrackSuccess() { | |
107 DCHECK(!success_ && !shutdown_); | |
108 success_ = true; | |
109 } | |
110 | |
111 // Tracks that OptIn was not completed before shutdown. | |
112 void TrackShutdown() { | |
113 DCHECK(!success_ && !shutdown_); | |
114 shutdown_ = true; | |
115 } | |
116 | |
117 private: | |
118 bool error_ = false; | |
119 bool success_ = false; | |
120 bool shutdown_ = false; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(ScopedOptInFlowTracker); | |
123 }; | |
124 | |
80 ArcSessionManager::ArcSessionManager( | 125 ArcSessionManager::ArcSessionManager( |
81 std::unique_ptr<ArcSessionRunner> arc_session_runner) | 126 std::unique_ptr<ArcSessionRunner> arc_session_runner) |
82 : arc_session_runner_(std::move(arc_session_runner)), | 127 : arc_session_runner_(std::move(arc_session_runner)), |
83 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), | 128 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), |
84 weak_ptr_factory_(this) { | 129 weak_ptr_factory_(this) { |
85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
86 DCHECK(!g_arc_session_manager); | 131 DCHECK(!g_arc_session_manager); |
87 g_arc_session_manager = this; | 132 g_arc_session_manager = this; |
88 arc_session_runner_->AddObserver(this); | 133 arc_session_runner_->AddObserver(this); |
89 } | 134 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 // We don't expect ProvisioningResult::SUCCESS is reported twice or reported | 249 // We don't expect ProvisioningResult::SUCCESS is reported twice or reported |
205 // after an error. | 250 // after an error. |
206 DCHECK_NE(result, ProvisioningResult::SUCCESS); | 251 DCHECK_NE(result, ProvisioningResult::SUCCESS); |
207 // TODO(khmel): Consider changing LOG to NOTREACHED once we guaranty that | 252 // TODO(khmel): Consider changing LOG to NOTREACHED once we guaranty that |
208 // no double message can happen in production. | 253 // no double message can happen in production. |
209 LOG(WARNING) << "Provisioning result was already reported. Ignoring " | 254 LOG(WARNING) << "Provisioning result was already reported. Ignoring " |
210 << "additional result " << static_cast<int>(result) << "."; | 255 << "additional result " << static_cast<int>(result) << "."; |
211 return; | 256 return; |
212 } | 257 } |
213 provisioning_reported_ = true; | 258 provisioning_reported_ = true; |
259 if (scoped_opt_in_tracker_ && result != ProvisioningResult::SUCCESS) | |
260 scoped_opt_in_tracker_->TrackError(); | |
214 | 261 |
215 if (result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { | 262 if (result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { |
216 if (IsArcKioskMode()) { | 263 if (IsArcKioskMode()) { |
217 VLOG(1) << "Robot account auth code fetching error"; | 264 VLOG(1) << "Robot account auth code fetching error"; |
218 // Log out the user. All the cleanup will be done in Shutdown() method. | 265 // Log out the user. All the cleanup will be done in Shutdown() method. |
219 // The callback is not called because auth code is empty. | 266 // The callback is not called because auth code is empty. |
220 attempt_user_exit_callback_.Run(); | 267 attempt_user_exit_callback_.Run(); |
221 return; | 268 return; |
222 } | 269 } |
223 | 270 |
224 // For backwards compatibility, use NETWORK_ERROR for | 271 // For backwards compatibility, use NETWORK_ERROR for |
225 // CHROME_SERVER_COMMUNICATION_ERROR case. | 272 // CHROME_SERVER_COMMUNICATION_ERROR case. |
226 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 273 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
227 } else if (!sign_in_start_time_.is_null()) { | 274 } else if (!sign_in_start_time_.is_null()) { |
228 arc_sign_in_timer_.Stop(); | 275 arc_sign_in_timer_.Stop(); |
229 | 276 |
230 UpdateProvisioningTiming(base::Time::Now() - sign_in_start_time_, | 277 UpdateProvisioningTiming(base::Time::Now() - sign_in_start_time_, |
231 result == ProvisioningResult::SUCCESS, | 278 result == ProvisioningResult::SUCCESS, |
232 policy_util::IsAccountManaged(profile_)); | 279 policy_util::IsAccountManaged(profile_)); |
233 UpdateProvisioningResultUMA(result, | 280 UpdateProvisioningResultUMA(result, |
234 policy_util::IsAccountManaged(profile_)); | 281 policy_util::IsAccountManaged(profile_)); |
235 if (result != ProvisioningResult::SUCCESS) | 282 if (result != ProvisioningResult::SUCCESS) |
236 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); | 283 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); |
237 } | 284 } |
238 | 285 |
239 if (result == ProvisioningResult::SUCCESS) { | 286 if (result == ProvisioningResult::SUCCESS) { |
240 if (support_host_) | 287 if (support_host_) |
241 support_host_->Close(); | 288 support_host_->Close(); |
242 | 289 |
290 if (scoped_opt_in_tracker_) { | |
291 scoped_opt_in_tracker_->TrackSuccess(); | |
292 scoped_opt_in_tracker_.reset(); | |
293 } | |
294 | |
243 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) | 295 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) |
244 return; | 296 return; |
245 | 297 |
246 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); | 298 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); |
247 | 299 |
248 // Launch Play Store app, except for the following cases: | 300 // Launch Play Store app, except for the following cases: |
249 // * When Opt-in verification is disabled (for tests); | 301 // * When Opt-in verification is disabled (for tests); |
250 // * In ARC Kiosk mode, because the only one UI in kiosk mode must be the | 302 // * In ARC Kiosk mode, because the only one UI in kiosk mode must be the |
251 // kiosk app and device is not needed for opt-in; | 303 // kiosk app and device is not needed for opt-in; |
252 // * When ARC is managed and all OptIn preferences are managed too, because | 304 // * When ARC is managed and all OptIn preferences are managed too, because |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 enable_requested_ = false; | 441 enable_requested_ = false; |
390 ShutdownSession(); | 442 ShutdownSession(); |
391 if (support_host_) { | 443 if (support_host_) { |
392 support_host_->Close(); | 444 support_host_->Close(); |
393 support_host_->RemoveObserver(this); | 445 support_host_->RemoveObserver(this); |
394 support_host_.reset(); | 446 support_host_.reset(); |
395 } | 447 } |
396 context_.reset(); | 448 context_.reset(); |
397 profile_ = nullptr; | 449 profile_ = nullptr; |
398 SetState(State::NOT_INITIALIZED); | 450 SetState(State::NOT_INITIALIZED); |
451 if (scoped_opt_in_tracker_) { | |
452 scoped_opt_in_tracker_->TrackShutdown(); | |
453 scoped_opt_in_tracker_.reset(); | |
454 } | |
399 } | 455 } |
400 | 456 |
401 void ArcSessionManager::ShutdownSession() { | 457 void ArcSessionManager::ShutdownSession() { |
402 arc_sign_in_timer_.Stop(); | 458 arc_sign_in_timer_.Stop(); |
403 playstore_launcher_.reset(); | 459 playstore_launcher_.reset(); |
404 terms_of_service_negotiator_.reset(); | 460 terms_of_service_negotiator_.reset(); |
405 android_management_checker_.reset(); | 461 android_management_checker_.reset(); |
406 arc_session_runner_->RequestStop(); | 462 arc_session_runner_->RequestStop(); |
407 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 463 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might |
408 // still be running when we return from this function. Do not set the | 464 // still be running when we return from this function. Do not set the |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 | 597 |
542 void ArcSessionManager::RequestDisable() { | 598 void ArcSessionManager::RequestDisable() { |
543 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 599 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
544 DCHECK(profile_); | 600 DCHECK(profile_); |
545 | 601 |
546 if (!enable_requested_) { | 602 if (!enable_requested_) { |
547 VLOG(1) << "ARC is already disabled. Do nothing."; | 603 VLOG(1) << "ARC is already disabled. Do nothing."; |
548 return; | 604 return; |
549 } | 605 } |
550 enable_requested_ = false; | 606 enable_requested_ = false; |
607 scoped_opt_in_tracker_.reset(); | |
551 | 608 |
552 // Reset any pending request to re-enable ARC. | 609 // Reset any pending request to re-enable ARC. |
553 reenable_arc_ = false; | 610 reenable_arc_ = false; |
554 StopArc(); | 611 StopArc(); |
555 VLOG(1) << "ARC opt-out. Removing user data."; | 612 VLOG(1) << "ARC opt-out. Removing user data."; |
556 RequestArcDataRemoval(); | 613 RequestArcDataRemoval(); |
557 } | 614 } |
558 | 615 |
559 void ArcSessionManager::RequestArcDataRemoval() { | 616 void ArcSessionManager::RequestArcDataRemoval() { |
560 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 617 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 | 652 |
596 // TODO(hidehiko): Remove this condition, when the state machine is fixed. | 653 // TODO(hidehiko): Remove this condition, when the state machine is fixed. |
597 if (!arc_session_runner_->IsStopped()) { | 654 if (!arc_session_runner_->IsStopped()) { |
598 // If the user attempts to re-enable ARC while the ARC instance is still | 655 // If the user attempts to re-enable ARC while the ARC instance is still |
599 // running the user should not be able to continue until the ARC instance | 656 // running the user should not be able to continue until the ARC instance |
600 // has stopped. | 657 // has stopped. |
601 if (support_host_) { | 658 if (support_host_) { |
602 support_host_->ShowError( | 659 support_host_->ShowError( |
603 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | 660 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
604 } | 661 } |
662 UpdateOptInCancelUMA(OptInCancelReason::SESSION_BUSY); | |
605 return; | 663 return; |
606 } | 664 } |
607 | 665 |
608 // TODO(hidehiko): DCHECK if |state_| is STOPPED, when the state machine | 666 // TODO(hidehiko): DCHECK if |state_| is STOPPED, when the state machine |
609 // is fixed. | 667 // is fixed. |
610 SetState(State::NEGOTIATING_TERMS_OF_SERVICE); | 668 SetState(State::NEGOTIATING_TERMS_OF_SERVICE); |
611 | 669 |
670 if (!scoped_opt_in_tracker_ && | |
671 !profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | |
672 scoped_opt_in_tracker_ = base::MakeUnique<ScopedOptInFlowTracker>(); | |
673 } | |
674 | |
612 if (!IsArcTermsOfServiceNegotiationNeeded()) { | 675 if (!IsArcTermsOfServiceNegotiationNeeded()) { |
613 // Moves to next state, Android management check, immediately, as if | 676 // Moves to next state, Android management check, immediately, as if |
614 // Terms of Service negotiation is done successfully. | 677 // Terms of Service negotiation is done successfully. |
615 StartAndroidManagementCheck(); | 678 StartAndroidManagementCheck(); |
616 return; | 679 return; |
617 } | 680 } |
618 | 681 |
619 if (IsOobeOptInActive()) { | 682 if (IsOobeOptInActive()) { |
620 VLOG(1) << "Use OOBE negotiator."; | 683 VLOG(1) << "Use OOBE negotiator."; |
621 terms_of_service_negotiator_ = | 684 terms_of_service_negotiator_ = |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
973 | 1036 |
974 #undef MAP_STATE | 1037 #undef MAP_STATE |
975 | 1038 |
976 // 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 |
977 // covered exhaustively in a switch statement. | 1040 // covered exhaustively in a switch statement. |
978 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 1041 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
979 return os; | 1042 return os; |
980 } | 1043 } |
981 | 1044 |
982 } // namespace arc | 1045 } // namespace arc |
OLD | NEW |