Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/policy/consumer_management_service.h" | 5 #include "chrome/browser/chromeos/policy/consumer_management_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_process_platform_part.h" | 17 #include "chrome/browser/browser_process_platform_part.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
| 20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 23 #include "chrome/browser/notifications/notification.h" | |
| 24 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 22 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 24 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_manager_factory.h" |
| 28 #include "chrome/browser/ui/browser_navigator.h" | |
| 25 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | |
| 26 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 31 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
| 27 #include "chromeos/dbus/cryptohome_client.h" | 32 #include "chromeos/dbus/cryptohome_client.h" |
| 28 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 33 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 34 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 30 #include "components/signin/core/browser/signin_manager_base.h" | 35 #include "components/signin/core/browser/signin_manager_base.h" |
| 31 #include "components/user_manager/user_manager.h" | 36 #include "components/user_manager/user_manager.h" |
| 32 #include "content/public/browser/notification_details.h" | 37 #include "content/public/browser/notification_details.h" |
| 33 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
| 40 #include "content/public/common/page_transition_types.h" | |
| 35 #include "google_apis/gaia/gaia_constants.h" | 41 #include "google_apis/gaia/gaia_constants.h" |
| 36 #include "google_apis/gaia/google_service_auth_error.h" | 42 #include "google_apis/gaia/google_service_auth_error.h" |
| 43 #include "grit/generated_resources.h" | |
| 44 #include "grit/theme_resources.h" | |
| 37 #include "policy/proto/device_management_backend.pb.h" | 45 #include "policy/proto/device_management_backend.pb.h" |
| 46 #include "third_party/WebKit/public/web/WebTextDirection.h" | |
| 47 #include "ui/base/l10n/l10n_util.h" | |
| 48 #include "ui/base/resource/resource_bundle.h" | |
| 49 #include "ui/base/window_open_disposition.h" | |
| 50 #include "ui/message_center/notification.h" | |
| 51 #include "ui/message_center/notification_types.h" | |
| 52 #include "ui/message_center/notifier_settings.h" | |
| 53 #include "url/gurl.h" | |
| 38 | 54 |
| 39 namespace { | 55 namespace { |
| 40 | 56 |
| 41 const char* kAttributeOwnerId = "consumer_management.owner_id"; | 57 // Boot atttributes ID. |
| 58 const char kAttributeOwnerId[] = "consumer_management.owner_id"; | |
| 59 | |
| 60 // Desktop notification constants. | |
| 61 const char kEnrollmentNotificationId[] = "consumer_management.enroll"; | |
| 62 const char kEnrollmentNotificationUrl[] = "chrome://consumer-management/enroll"; | |
| 63 | |
| 64 // The relative path to the settings page URL for opening the consumer | |
|
bartfab (slow)
2014/08/21 12:04:25
How about:
The path to the consumer management en
davidyu
2014/08/22 04:23:10
Done.
| |
| 65 // management enrollment/unenrollment confirmation overlay. | |
| 66 const char kConsumerManagementOverlay[] = "consumer-management-overlay"; | |
| 42 | 67 |
| 43 } // namespace | 68 } // namespace |
| 44 | 69 |
| 45 namespace policy { | 70 namespace policy { |
| 46 | 71 |
| 47 ConsumerManagementService::ConsumerManagementService( | 72 ConsumerManagementService::ConsumerManagementService( |
| 48 chromeos::CryptohomeClient* client) | 73 chromeos::CryptohomeClient* client) |
| 49 : Consumer("consumer_management_service"), | 74 : Consumer("consumer_management_service"), |
| 50 client_(client), | 75 client_(client), |
| 51 enrolling_token_service_(NULL), | 76 enrolling_profile_(NULL), |
| 52 weak_ptr_factory_(this) { | 77 weak_ptr_factory_(this) { |
| 53 registrar_.Add(this, | 78 registrar_.Add(this, |
| 54 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 79 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 55 content::NotificationService::AllSources()); | 80 content::NotificationService::AllSources()); |
| 56 } | 81 } |
| 57 | 82 |
| 58 ConsumerManagementService::~ConsumerManagementService() { | 83 ConsumerManagementService::~ConsumerManagementService() { |
| 59 registrar_.Remove(this, | 84 registrar_.Remove(this, |
| 60 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 85 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 61 content::NotificationService::AllSources()); | 86 content::NotificationService::AllSources()); |
| 62 if (enrolling_token_service_) | 87 if (enrolling_profile_) { |
| 63 enrolling_token_service_->RemoveObserver(this); | 88 ProfileOAuth2TokenServiceFactory::GetForProfile(enrolling_profile_)-> |
| 89 RemoveObserver(this); | |
| 90 } | |
| 64 } | 91 } |
| 65 | 92 |
| 66 // static | 93 // static |
| 67 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) { | 94 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 68 registry->RegisterIntegerPref( | 95 registry->RegisterIntegerPref( |
| 69 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE); | 96 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE); |
| 70 } | 97 } |
| 71 | 98 |
| 72 ConsumerManagementService::ConsumerEnrollmentState | 99 ConsumerManagementService::ConsumerEnrollmentState |
| 73 ConsumerManagementService::GetEnrollmentState() const { | 100 ConsumerManagementService::GetEnrollmentState() const { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 89 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) { | 116 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) { |
| 90 cryptohome::GetBootAttributeRequest request; | 117 cryptohome::GetBootAttributeRequest request; |
| 91 request.set_name(kAttributeOwnerId); | 118 request.set_name(kAttributeOwnerId); |
| 92 client_->GetBootAttribute( | 119 client_->GetBootAttribute( |
| 93 request, | 120 request, |
| 94 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone, | 121 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone, |
| 95 weak_ptr_factory_.GetWeakPtr(), | 122 weak_ptr_factory_.GetWeakPtr(), |
| 96 callback)); | 123 callback)); |
| 97 } | 124 } |
| 98 | 125 |
| 99 void ConsumerManagementService::OnGetBootAttributeDone( | |
| 100 const GetOwnerCallback& callback, | |
| 101 chromeos::DBusMethodCallStatus call_status, | |
| 102 bool dbus_success, | |
| 103 const cryptohome::BaseReply& reply) { | |
| 104 if (!dbus_success || reply.error() != 0) { | |
| 105 LOG(ERROR) << "Failed to get the owner info from boot lockbox."; | |
| 106 callback.Run(""); | |
| 107 return; | |
| 108 } | |
| 109 | |
| 110 callback.Run( | |
| 111 reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value()); | |
| 112 } | |
| 113 | |
| 114 void ConsumerManagementService::SetOwner(const std::string& user_id, | 126 void ConsumerManagementService::SetOwner(const std::string& user_id, |
| 115 const SetOwnerCallback& callback) { | 127 const SetOwnerCallback& callback) { |
| 116 cryptohome::SetBootAttributeRequest request; | 128 cryptohome::SetBootAttributeRequest request; |
| 117 request.set_name(kAttributeOwnerId); | 129 request.set_name(kAttributeOwnerId); |
| 118 request.set_value(user_id.data(), user_id.size()); | 130 request.set_value(user_id.data(), user_id.size()); |
| 119 client_->SetBootAttribute( | 131 client_->SetBootAttribute( |
| 120 request, | 132 request, |
| 121 base::Bind(&ConsumerManagementService::OnSetBootAttributeDone, | 133 base::Bind(&ConsumerManagementService::OnSetBootAttributeDone, |
| 122 weak_ptr_factory_.GetWeakPtr(), | 134 weak_ptr_factory_.GetWeakPtr(), |
| 123 callback)); | 135 callback)); |
| 124 } | 136 } |
| 125 | 137 |
| 126 void ConsumerManagementService::OnSetBootAttributeDone( | |
| 127 const SetOwnerCallback& callback, | |
| 128 chromeos::DBusMethodCallStatus call_status, | |
| 129 bool dbus_success, | |
| 130 const cryptohome::BaseReply& reply) { | |
| 131 if (!dbus_success || reply.error() != 0) { | |
| 132 LOG(ERROR) << "Failed to set owner info in boot lockbox."; | |
| 133 callback.Run(false); | |
| 134 return; | |
| 135 } | |
| 136 | |
| 137 cryptohome::FlushAndSignBootAttributesRequest request; | |
| 138 client_->FlushAndSignBootAttributes( | |
| 139 request, | |
| 140 base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone, | |
| 141 weak_ptr_factory_.GetWeakPtr(), | |
| 142 callback)); | |
| 143 } | |
| 144 | |
| 145 void ConsumerManagementService::OnFlushAndSignBootAttributesDone( | |
| 146 const SetOwnerCallback& callback, | |
| 147 chromeos::DBusMethodCallStatus call_status, | |
| 148 bool dbus_success, | |
| 149 const cryptohome::BaseReply& reply) { | |
| 150 if (!dbus_success || reply.error() != 0) { | |
| 151 LOG(ERROR) << "Failed to flush and sign boot lockbox."; | |
| 152 callback.Run(false); | |
| 153 return; | |
| 154 } | |
| 155 | |
| 156 callback.Run(true); | |
| 157 } | |
| 158 | |
| 159 void ConsumerManagementService::Observe( | 138 void ConsumerManagementService::Observe( |
| 160 int type, | 139 int type, |
| 161 const content::NotificationSource& source, | 140 const content::NotificationSource& source, |
| 162 const content::NotificationDetails& details) { | 141 const content::NotificationDetails& details) { |
| 163 if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) { | 142 if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) { |
| 164 NOTREACHED() << "Unexpected notification " << type; | 143 NOTREACHED() << "Unexpected notification " << type; |
| 165 return; | 144 return; |
| 166 } | 145 } |
| 167 | 146 |
| 168 Profile* profile = content::Details<Profile>(details).ptr(); | 147 Profile* profile = content::Details<Profile>(details).ptr(); |
| 169 if (chromeos::ProfileHelper::IsOwnerProfile(profile)) | 148 if (chromeos::ProfileHelper::IsOwnerProfile(profile)) |
| 170 OnOwnerSignin(profile); | 149 OnOwnerSignin(profile); |
| 171 } | 150 } |
| 172 | 151 |
| 173 void ConsumerManagementService::OnRefreshTokenAvailable( | 152 void ConsumerManagementService::OnRefreshTokenAvailable( |
| 174 const std::string& account_id) { | 153 const std::string& account_id) { |
| 175 if (account_id == enrolling_account_id_) { | 154 CHECK(enrolling_profile_); |
| 176 enrolling_token_service_->RemoveObserver(this); | 155 |
| 156 if (account_id == GetAccountIdFromProfile(enrolling_profile_)) { | |
| 157 ProfileOAuth2TokenServiceFactory::GetForProfile(enrolling_profile_)-> | |
| 158 RemoveObserver(this); | |
| 177 OnOwnerRefreshTokenAvailable(); | 159 OnOwnerRefreshTokenAvailable(); |
| 178 } | 160 } |
| 179 } | 161 } |
| 180 | 162 |
| 181 void ConsumerManagementService::OnGetTokenSuccess( | 163 void ConsumerManagementService::OnGetTokenSuccess( |
| 182 const OAuth2TokenService::Request* request, | 164 const OAuth2TokenService::Request* request, |
| 183 const std::string& access_token, | 165 const std::string& access_token, |
| 184 const base::Time& expiration_time) { | 166 const base::Time& expiration_time) { |
| 185 DCHECK_EQ(token_request_, request); | 167 DCHECK_EQ(token_request_, request); |
| 186 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release()); | 168 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release()); |
| 187 | 169 |
| 188 OnOwnerAccessTokenAvailable(access_token); | 170 OnOwnerAccessTokenAvailable(access_token); |
| 189 } | 171 } |
| 190 | 172 |
| 191 void ConsumerManagementService::OnGetTokenFailure( | 173 void ConsumerManagementService::OnGetTokenFailure( |
| 192 const OAuth2TokenService::Request* request, | 174 const OAuth2TokenService::Request* request, |
| 193 const GoogleServiceAuthError& error) { | 175 const GoogleServiceAuthError& error) { |
| 194 DCHECK_EQ(token_request_, request); | 176 DCHECK_EQ(token_request_, request); |
| 195 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release()); | 177 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release()); |
| 196 | 178 |
| 197 LOG(ERROR) << "Failed to get the access token: " << error.ToString(); | 179 LOG(ERROR) << "Failed to get the access token: " << error.ToString(); |
| 198 EndEnrollment(ENROLLMENT_GET_TOKEN_FAILED); | 180 EndEnrollment(ENROLLMENT_GET_TOKEN_FAILED); |
| 199 } | 181 } |
| 200 | 182 |
| 183 ConsumerManagementService::DesktopNotificationDelegate:: | |
| 184 DesktopNotificationDelegate( | |
| 185 const std::string& id, | |
| 186 const base::Closure& button_click_callback) | |
| 187 : id_(id), | |
| 188 button_click_callback_(button_click_callback) { | |
| 189 } | |
| 190 | |
| 191 ConsumerManagementService::DesktopNotificationDelegate:: | |
| 192 ~DesktopNotificationDelegate() { | |
| 193 } | |
| 194 | |
| 195 std::string ConsumerManagementService::DesktopNotificationDelegate::id() const { | |
| 196 return id_; | |
| 197 } | |
| 198 | |
| 199 content::WebContents* ConsumerManagementService::DesktopNotificationDelegate:: | |
| 200 GetWebContents() const { | |
| 201 return NULL; | |
| 202 } | |
| 203 | |
| 204 void ConsumerManagementService::DesktopNotificationDelegate::Display() { | |
| 205 } | |
| 206 | |
| 207 void ConsumerManagementService::DesktopNotificationDelegate::ButtonClick( | |
| 208 int button_index) { | |
| 209 button_click_callback_.Run(); | |
| 210 } | |
| 211 | |
| 212 void ConsumerManagementService::DesktopNotificationDelegate::Error() { | |
| 213 } | |
| 214 | |
| 215 void ConsumerManagementService::DesktopNotificationDelegate::Close( | |
| 216 bool by_user) { | |
| 217 } | |
| 218 | |
| 219 void ConsumerManagementService::DesktopNotificationDelegate::Click() { | |
| 220 } | |
| 221 | |
| 222 void ConsumerManagementService::OnGetBootAttributeDone( | |
| 223 const GetOwnerCallback& callback, | |
| 224 chromeos::DBusMethodCallStatus call_status, | |
| 225 bool dbus_success, | |
| 226 const cryptohome::BaseReply& reply) { | |
| 227 if (!dbus_success || reply.error() != 0) { | |
| 228 LOG(ERROR) << "Failed to get the owner info from boot lockbox."; | |
| 229 callback.Run(""); | |
| 230 return; | |
| 231 } | |
| 232 | |
| 233 callback.Run( | |
| 234 reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value()); | |
| 235 } | |
| 236 | |
| 237 void ConsumerManagementService::OnSetBootAttributeDone( | |
| 238 const SetOwnerCallback& callback, | |
| 239 chromeos::DBusMethodCallStatus call_status, | |
| 240 bool dbus_success, | |
| 241 const cryptohome::BaseReply& reply) { | |
| 242 if (!dbus_success || reply.error() != 0) { | |
| 243 LOG(ERROR) << "Failed to set owner info in boot lockbox."; | |
| 244 callback.Run(false); | |
| 245 return; | |
| 246 } | |
| 247 | |
| 248 cryptohome::FlushAndSignBootAttributesRequest request; | |
| 249 client_->FlushAndSignBootAttributes( | |
| 250 request, | |
| 251 base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone, | |
| 252 weak_ptr_factory_.GetWeakPtr(), | |
| 253 callback)); | |
| 254 } | |
| 255 | |
| 256 void ConsumerManagementService::OnFlushAndSignBootAttributesDone( | |
| 257 const SetOwnerCallback& callback, | |
| 258 chromeos::DBusMethodCallStatus call_status, | |
| 259 bool dbus_success, | |
| 260 const cryptohome::BaseReply& reply) { | |
| 261 if (!dbus_success || reply.error() != 0) { | |
| 262 LOG(ERROR) << "Failed to flush and sign boot lockbox."; | |
| 263 callback.Run(false); | |
| 264 return; | |
| 265 } | |
| 266 | |
| 267 callback.Run(true); | |
| 268 } | |
| 269 | |
| 201 void ConsumerManagementService::OnOwnerSignin(Profile* profile) { | 270 void ConsumerManagementService::OnOwnerSignin(Profile* profile) { |
| 202 const ConsumerEnrollmentState state = GetEnrollmentState(); | 271 const ConsumerEnrollmentState state = GetEnrollmentState(); |
| 203 switch (state) { | 272 switch (state) { |
| 204 case ENROLLMENT_NONE: | 273 case ENROLLMENT_NONE: |
| 205 // Do nothing. | 274 // Do nothing. |
| 206 return; | 275 return; |
| 207 | 276 |
| 208 case ENROLLMENT_OWNER_STORED: | 277 case ENROLLMENT_OWNER_STORED: |
| 209 // Continue the enrollment process after the owner signs in. | 278 // Continue the enrollment process after the owner signs in. |
| 210 ContinueEnrollmentProcess(profile); | 279 ContinueEnrollmentProcess(profile); |
| 211 return; | 280 return; |
| 212 | 281 |
| 213 case ENROLLMENT_SUCCESS: | 282 case ENROLLMENT_SUCCESS: |
| 214 case ENROLLMENT_CANCELED: | 283 case ENROLLMENT_CANCELED: |
| 215 case ENROLLMENT_BOOT_LOCKBOX_FAILED: | 284 case ENROLLMENT_BOOT_LOCKBOX_FAILED: |
| 216 case ENROLLMENT_DM_SERVER_FAILED: | 285 case ENROLLMENT_DM_SERVER_FAILED: |
| 217 case ENROLLMENT_GET_TOKEN_FAILED: | 286 case ENROLLMENT_GET_TOKEN_FAILED: |
| 218 ShowDesktopNotificationAndResetState(state); | 287 ShowDesktopNotificationAndResetState(state, profile); |
| 219 return; | 288 return; |
| 220 | 289 |
| 221 case ENROLLMENT_REQUESTED: | 290 case ENROLLMENT_REQUESTED: |
| 222 case ENROLLMENT_LAST: | 291 case ENROLLMENT_LAST: |
| 223 NOTREACHED() << "Unexpected enrollment state " << state; | 292 NOTREACHED() << "Unexpected enrollment state " << state; |
| 224 return; | 293 return; |
| 225 } | 294 } |
| 226 } | 295 } |
| 227 | 296 |
| 228 void ConsumerManagementService::ContinueEnrollmentProcess(Profile* profile) { | 297 void ConsumerManagementService::ContinueEnrollmentProcess(Profile* profile) { |
| 298 enrolling_profile_ = profile; | |
| 299 | |
| 229 // First, we need to ensure that the refresh token is available. | 300 // First, we need to ensure that the refresh token is available. |
| 230 SigninManagerBase* signin_manager = | 301 const std::string account_id = GetAccountIdFromProfile(profile); |
|
bartfab (slow)
2014/08/21 12:04:25
Nit: s/std::string/std::string&/
davidyu
2014/08/22 04:23:10
Done.
| |
| 231 SigninManagerFactory::GetForProfile(profile); | 302 ProfileOAuth2TokenService* token_service = |
| 232 enrolling_account_id_ = signin_manager->GetAuthenticatedAccountId(); | |
| 233 | |
| 234 enrolling_token_service_ = | |
| 235 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 303 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 236 if (enrolling_token_service_->RefreshTokenIsAvailable( | 304 if (token_service->RefreshTokenIsAvailable(account_id)) { |
| 237 enrolling_account_id_)) { | |
| 238 OnOwnerRefreshTokenAvailable(); | 305 OnOwnerRefreshTokenAvailable(); |
| 239 } else { | 306 } else { |
| 240 enrolling_token_service_->AddObserver(this); | 307 token_service->AddObserver(this); |
| 241 } | 308 } |
| 242 } | 309 } |
| 243 | 310 |
| 244 void ConsumerManagementService::OnOwnerRefreshTokenAvailable() { | 311 void ConsumerManagementService::OnOwnerRefreshTokenAvailable() { |
| 245 CHECK(enrolling_token_service_); | 312 CHECK(enrolling_profile_); |
| 246 | 313 |
| 247 // Now we can request the OAuth access token for device management to send the | 314 // Now we can request the OAuth access token for device management to send the |
| 248 // device registration request to the device management server. | 315 // device registration request to the device management server. |
| 249 OAuth2TokenService::ScopeSet oauth_scopes; | 316 OAuth2TokenService::ScopeSet oauth_scopes; |
| 250 oauth_scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); | 317 oauth_scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); |
| 251 | 318 const std::string account_id = GetAccountIdFromProfile(enrolling_profile_); |
|
bartfab (slow)
2014/08/21 12:04:25
Nit: s/std::string/std::string&/
davidyu
2014/08/22 04:23:10
Done.
| |
| 252 token_request_ = enrolling_token_service_->StartRequest( | 319 token_request_ = ProfileOAuth2TokenServiceFactory::GetForProfile( |
| 253 enrolling_account_id_, oauth_scopes, this); | 320 enrolling_profile_)->StartRequest(account_id, oauth_scopes, this); |
| 254 } | 321 } |
| 255 | 322 |
| 256 void ConsumerManagementService::OnOwnerAccessTokenAvailable( | 323 void ConsumerManagementService::OnOwnerAccessTokenAvailable( |
| 257 const std::string& access_token) { | 324 const std::string& access_token) { |
| 258 // Now that we have the access token, we got everything we need to send the | 325 // Now that we have the access token, we got everything we need to send the |
| 259 // device registration request to the device management server. | 326 // device registration request to the device management server. |
| 260 BrowserPolicyConnectorChromeOS* connector = | 327 BrowserPolicyConnectorChromeOS* connector = |
| 261 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 328 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 262 DeviceCloudPolicyInitializer* initializer = | 329 DeviceCloudPolicyInitializer* initializer = |
| 263 connector->GetDeviceCloudPolicyInitializer(); | 330 connector->GetDeviceCloudPolicyInitializer(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 285 << " store_status=" << status.store_status() | 352 << " store_status=" << status.store_status() |
| 286 << " validation_status=" << status.validation_status(); | 353 << " validation_status=" << status.validation_status(); |
| 287 EndEnrollment(ENROLLMENT_DM_SERVER_FAILED); | 354 EndEnrollment(ENROLLMENT_DM_SERVER_FAILED); |
| 288 return; | 355 return; |
| 289 } | 356 } |
| 290 | 357 |
| 291 EndEnrollment(ENROLLMENT_SUCCESS); | 358 EndEnrollment(ENROLLMENT_SUCCESS); |
| 292 } | 359 } |
| 293 | 360 |
| 294 void ConsumerManagementService::EndEnrollment(ConsumerEnrollmentState state) { | 361 void ConsumerManagementService::EndEnrollment(ConsumerEnrollmentState state) { |
| 362 Profile* profile = enrolling_profile_; | |
| 363 enrolling_profile_ = NULL; | |
| 364 | |
| 295 SetEnrollmentState(state); | 365 SetEnrollmentState(state); |
| 296 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) | 366 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) |
| 297 ShowDesktopNotificationAndResetState(state); | 367 ShowDesktopNotificationAndResetState(state, profile); |
| 298 } | 368 } |
| 299 | 369 |
| 300 void ConsumerManagementService::ShowDesktopNotificationAndResetState( | 370 void ConsumerManagementService::ShowDesktopNotificationAndResetState( |
| 301 ConsumerEnrollmentState state) { | 371 ConsumerEnrollmentState state, Profile* profile) { |
| 302 // TODO(davidyu): Show a desktop notification to the current user, who should | 372 base::string16 title; |
| 303 // be the owner. | 373 base::string16 body; |
| 374 base::string16 button_label; | |
| 375 base::Closure button_click_callback; | |
| 376 | |
| 377 if (state == ENROLLMENT_SUCCESS) { | |
| 378 title = l10n_util::GetStringUTF16( | |
| 379 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_TITLE); | |
| 380 body = l10n_util::GetStringUTF16( | |
| 381 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_BODY); | |
| 382 button_label = l10n_util::GetStringUTF16( | |
| 383 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_MODIFY_SETTINGS_BUTTON); | |
| 384 button_click_callback = base::Bind( | |
| 385 &ConsumerManagementService::OpenSettingsPage, | |
| 386 weak_ptr_factory_.GetWeakPtr(), | |
| 387 profile); | |
| 388 } else { | |
| 389 title = l10n_util::GetStringUTF16( | |
| 390 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_TITLE); | |
| 391 body = l10n_util::GetStringUTF16( | |
| 392 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_BODY); | |
| 393 button_label = l10n_util::GetStringUTF16( | |
| 394 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_TRY_AGAIN_BUTTON); | |
| 395 button_click_callback = base::Bind( | |
| 396 &ConsumerManagementService::TryEnrollmentAgain, | |
| 397 weak_ptr_factory_.GetWeakPtr(), | |
| 398 profile); | |
| 399 } | |
| 400 | |
| 401 message_center::RichNotificationData optional_field; | |
| 402 optional_field.buttons.push_back(message_center::ButtonInfo(button_label)); | |
| 403 Notification notification( | |
| 404 message_center::NOTIFICATION_TYPE_SIMPLE, | |
| 405 GURL(kEnrollmentNotificationUrl), | |
| 406 title, | |
| 407 body, | |
| 408 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 409 IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON), | |
| 410 blink::WebTextDirectionDefault, | |
| 411 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | |
| 412 kEnrollmentNotificationId), | |
| 413 base::string16(), // display_source | |
| 414 base::UTF8ToUTF16(kEnrollmentNotificationId), | |
| 415 optional_field, | |
| 416 new DesktopNotificationDelegate(kEnrollmentNotificationId, | |
| 417 button_click_callback)); | |
| 418 notification.SetSystemPriority(); | |
| 419 g_browser_process->notification_ui_manager()->Add(notification, profile); | |
| 420 | |
| 304 SetEnrollmentState(ENROLLMENT_NONE); | 421 SetEnrollmentState(ENROLLMENT_NONE); |
| 305 } | 422 } |
| 306 | 423 |
| 424 void ConsumerManagementService::OpenSettingsPage(Profile* profile) const { | |
| 425 const GURL url(chrome::kChromeUISettingsURL); | |
| 426 chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK); | |
| 427 params.disposition = NEW_FOREGROUND_TAB; | |
| 428 chrome::Navigate(¶ms); | |
| 429 } | |
| 430 | |
| 431 void ConsumerManagementService::TryEnrollmentAgain(Profile* profile) const { | |
| 432 GURL base_url(chrome::kChromeUISettingsURL); | |
| 433 GURL url = base_url.Resolve(kConsumerManagementOverlay); | |
|
bartfab (slow)
2014/08/21 12:04:25
Nit: const.
davidyu
2014/08/22 04:23:10
Done.
| |
| 434 | |
| 435 chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK); | |
| 436 params.disposition = NEW_FOREGROUND_TAB; | |
| 437 chrome::Navigate(¶ms); | |
| 438 } | |
| 439 | |
| 440 const std::string& ConsumerManagementService::GetAccountIdFromProfile( | |
| 441 Profile* profile) const { | |
| 442 return SigninManagerFactory::GetForProfile(profile)-> | |
| 443 GetAuthenticatedAccountId(); | |
| 444 } | |
| 445 | |
| 307 } // namespace policy | 446 } // namespace policy |
| OLD | NEW |