OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/login/enterprise_enrollment_screen.h" | 5 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chromeos/login/screen_observer.h" | 9 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 10 #include "chrome/browser/policy/browser_policy_connector.h" |
10 #include "chrome/common/net/gaia/gaia_constants.h" | 11 #include "chrome/common/net/gaia/gaia_constants.h" |
11 | 12 |
12 namespace chromeos { | 13 namespace chromeos { |
13 | 14 |
14 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( | 15 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( |
15 WizardScreenDelegate* delegate) | 16 WizardScreenDelegate* delegate) |
16 : ViewScreen<EnterpriseEnrollmentView>(delegate) {} | 17 : ViewScreen<EnterpriseEnrollmentView>(delegate) {} |
17 | 18 |
18 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} | 19 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} |
19 | 20 |
20 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, | 21 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, |
21 const std::string& password, | 22 const std::string& password, |
22 const std::string& captcha, | 23 const std::string& captcha, |
23 const std::string& access_code) { | 24 const std::string& access_code) { |
24 captcha_token_.clear(); | 25 captcha_token_.clear(); |
| 26 user_ = user; |
25 auth_fetcher_.reset( | 27 auth_fetcher_.reset( |
26 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, | 28 new GaiaAuthFetcher(this, GaiaConstants::kChromeSource, |
27 g_browser_process->system_request_context())); | 29 g_browser_process->system_request_context())); |
28 | 30 |
29 if (access_code.empty()) { | 31 if (access_code.empty()) { |
30 auth_fetcher_->StartClientLogin(user, password, | 32 auth_fetcher_->StartClientLogin(user, password, |
31 GaiaConstants::kDeviceManagementService, | 33 GaiaConstants::kDeviceManagementService, |
32 captcha_token_, captcha, | 34 captcha_token_, captcha, |
33 GaiaAuthFetcher::HostedAccountsAllowed); | 35 GaiaAuthFetcher::HostedAccountsAllowed); |
34 } else { | 36 } else { |
35 auth_fetcher_->StartClientLogin(user, access_code, | 37 auth_fetcher_->StartClientLogin(user, access_code, |
36 GaiaConstants::kDeviceManagementService, | 38 GaiaConstants::kDeviceManagementService, |
37 std::string(), std::string(), | 39 std::string(), std::string(), |
38 GaiaAuthFetcher::HostedAccountsAllowed); | 40 GaiaAuthFetcher::HostedAccountsAllowed); |
39 } | 41 } |
40 } | 42 } |
41 | 43 |
42 void EnterpriseEnrollmentScreen::CancelEnrollment() { | 44 void EnterpriseEnrollmentScreen::CancelEnrollment() { |
43 auth_fetcher_.reset(); | 45 auth_fetcher_.reset(); |
| 46 registrar_.reset(); |
| 47 g_browser_process->browser_policy_connector()->StopAutoRetry(); |
44 ScreenObserver* observer = delegate()->GetObserver(this); | 48 ScreenObserver* observer = delegate()->GetObserver(this); |
45 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED); | 49 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_CANCELLED); |
46 } | 50 } |
47 | 51 |
48 void EnterpriseEnrollmentScreen::CloseConfirmation() { | 52 void EnterpriseEnrollmentScreen::CloseConfirmation() { |
49 auth_fetcher_.reset(); | 53 auth_fetcher_.reset(); |
50 ScreenObserver* observer = delegate()->GetObserver(this); | 54 ScreenObserver* observer = delegate()->GetObserver(this); |
51 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); | 55 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); |
52 } | 56 } |
53 | 57 |
54 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { | |
55 return new EnterpriseEnrollmentView(this); | |
56 } | |
57 | |
58 void EnterpriseEnrollmentScreen::OnClientLoginSuccess( | 58 void EnterpriseEnrollmentScreen::OnClientLoginSuccess( |
59 const ClientLoginResult& result) { | 59 const ClientLoginResult& result) { |
60 auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid, | 60 auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid, |
61 GaiaConstants::kDeviceManagementService); | 61 GaiaConstants::kDeviceManagementService); |
62 } | 62 } |
63 | 63 |
64 void EnterpriseEnrollmentScreen::OnClientLoginFailure( | 64 void EnterpriseEnrollmentScreen::OnClientLoginFailure( |
65 const GoogleServiceAuthError& error) { | 65 const GoogleServiceAuthError& error) { |
66 HandleAuthError(error); | 66 HandleAuthError(error); |
67 } | 67 } |
68 | 68 |
69 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( | 69 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( |
70 const std::string& service, | 70 const std::string& service, |
71 const std::string& auth_token) { | 71 const std::string& auth_token) { |
72 if (service != GaiaConstants::kDeviceManagementService) { | 72 if (service != GaiaConstants::kDeviceManagementService) { |
73 NOTREACHED() << service; | 73 NOTREACHED() << service; |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 auth_fetcher_.reset(); | 77 scoped_ptr<GaiaAuthFetcher> auth_fetcher(auth_fetcher_.release()); |
78 | 78 |
79 // TODO(mnissler): Trigger actual enrollment here! | 79 policy::BrowserPolicyConnector* connector = |
| 80 g_browser_process->browser_policy_connector(); |
| 81 if (!connector->cloud_policy_subsystem()) { |
| 82 NOTREACHED() << "Cloud policy subsystem not initialized."; |
| 83 if (view()) |
| 84 view()->ShowFatalEnrollmentError(); |
| 85 return; |
| 86 } |
80 | 87 |
81 if (view()) | 88 registrar_.reset(new policy::CloudPolicySubsystem::ObserverRegistrar( |
82 view()->ShowConfirmationScreen(); | 89 connector->cloud_policy_subsystem(), this)); |
| 90 |
| 91 // Push the credentials to the policy infrastructure. It'll start enrollment |
| 92 // and notify us of progress through CloudPolicySubsystem::Observer. |
| 93 connector->SetCredentials(user_, auth_token); |
83 } | 94 } |
84 | 95 |
85 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( | 96 void EnterpriseEnrollmentScreen::OnIssueAuthTokenFailure( |
86 const std::string& service, | 97 const std::string& service, |
87 const GoogleServiceAuthError& error) { | 98 const GoogleServiceAuthError& error) { |
88 if (service != GaiaConstants::kDeviceManagementService) { | 99 if (service != GaiaConstants::kDeviceManagementService) { |
89 NOTREACHED() << service; | 100 NOTREACHED() << service; |
90 return; | 101 return; |
91 } | 102 } |
92 | 103 |
93 HandleAuthError(error); | 104 HandleAuthError(error); |
94 } | 105 } |
95 | 106 |
| 107 void EnterpriseEnrollmentScreen::OnPolicyStateChanged( |
| 108 policy::CloudPolicySubsystem::PolicySubsystemState state, |
| 109 policy::CloudPolicySubsystem::ErrorDetails error_details) { |
| 110 |
| 111 if (view()) { |
| 112 switch (state) { |
| 113 case policy::CloudPolicySubsystem::UNENROLLED: |
| 114 // Still working... |
| 115 return; |
| 116 case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN: |
| 117 case policy::CloudPolicySubsystem::LOCAL_ERROR: |
| 118 view()->ShowFatalEnrollmentError(); |
| 119 break; |
| 120 case policy::CloudPolicySubsystem::UNMANAGED: |
| 121 view()->ShowAccountError(); |
| 122 break; |
| 123 case policy::CloudPolicySubsystem::NETWORK_ERROR: |
| 124 view()->ShowNetworkEnrollmentError(); |
| 125 break; |
| 126 case policy::CloudPolicySubsystem::SUCCESS: |
| 127 // Success! |
| 128 registrar_.reset(); |
| 129 view()->ShowConfirmationScreen(); |
| 130 return; |
| 131 } |
| 132 |
| 133 // We have an error. |
| 134 LOG(WARNING) << "Policy subsystem error during enrollment: " << state |
| 135 << " details: " << error_details; |
| 136 } |
| 137 |
| 138 // Stop the policy infrastructure. |
| 139 registrar_.reset(); |
| 140 g_browser_process->browser_policy_connector()->StopAutoRetry(); |
| 141 } |
| 142 |
| 143 EnterpriseEnrollmentView* EnterpriseEnrollmentScreen::AllocateView() { |
| 144 return new EnterpriseEnrollmentView(this); |
| 145 } |
| 146 |
96 void EnterpriseEnrollmentScreen::HandleAuthError( | 147 void EnterpriseEnrollmentScreen::HandleAuthError( |
97 const GoogleServiceAuthError& error) { | 148 const GoogleServiceAuthError& error) { |
98 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); | 149 scoped_ptr<GaiaAuthFetcher> scoped_killer(auth_fetcher_.release()); |
99 | 150 |
100 if (!view()) | 151 if (!view()) |
101 return; | 152 return; |
102 | 153 |
103 switch (error.state()) { | 154 switch (error.state()) { |
104 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: | 155 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS: |
105 case GoogleServiceAuthError::CONNECTION_FAILED: | 156 case GoogleServiceAuthError::CONNECTION_FAILED: |
(...skipping 14 matching lines...) Expand all Loading... |
120 case GoogleServiceAuthError::REQUEST_CANCELED: | 171 case GoogleServiceAuthError::REQUEST_CANCELED: |
121 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); | 172 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); |
122 view()->ShowFatalAuthError(); | 173 view()->ShowFatalAuthError(); |
123 return; | 174 return; |
124 } | 175 } |
125 | 176 |
126 NOTREACHED() << error.state(); | 177 NOTREACHED() << error.state(); |
127 } | 178 } |
128 | 179 |
129 } // namespace chromeos | 180 } // namespace chromeos |
OLD | NEW |