| 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/user_manager.h" | 5 #include "chrome/browser/chromeos/login/user_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 220 } |
| 221 | 221 |
| 222 PrefService* local_state = g_browser_process->local_state(); | 222 PrefService* local_state = g_browser_process->local_state(); |
| 223 DictionaryPrefUpdate images_update(local_state, kUserImages); | 223 DictionaryPrefUpdate images_update(local_state, kUserImages); |
| 224 base::DictionaryValue* image_properties = new base::DictionaryValue(); | 224 base::DictionaryValue* image_properties = new base::DictionaryValue(); |
| 225 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); | 225 image_properties->Set(kImagePathNodeName, new StringValue(image_path)); |
| 226 image_properties->Set(kImageIndexNodeName, | 226 image_properties->Set(kImageIndexNodeName, |
| 227 new base::FundamentalValue(image_index)); | 227 new base::FundamentalValue(image_index)); |
| 228 images_update->SetWithoutPathExpansion(username, image_properties); | 228 images_update->SetWithoutPathExpansion(username, image_properties); |
| 229 DVLOG(1) << "Saving path to user image in Local State."; | 229 DVLOG(1) << "Saving path to user image in Local State."; |
| 230 local_state->SavePersistentPrefs(); | 230 local_state->ScheduleSavePersistentPrefs(); |
| 231 | 231 |
| 232 NotifyLocalStateChanged(); | 232 NotifyLocalStateChanged(); |
| 233 content::NotificationService::current()->Notify( | 233 content::NotificationService::current()->Notify( |
| 234 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 234 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
| 235 content::Source<UserManager>(this), | 235 content::Source<UserManager>(this), |
| 236 content::Details<const User>(&logged_in_user_)); | 236 content::Details<const User>(&logged_in_user_)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void UserManager::SaveImageToFile(const SkBitmap& image, | 239 void UserManager::SaveImageToFile(const SkBitmap& image, |
| 240 const FilePath& image_path, | 240 const FilePath& image_path, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 it != users.end(); | 427 it != users.end(); |
| 428 ++it) { | 428 ++it) { |
| 429 std::string user_email = it->email(); | 429 std::string user_email = it->email(); |
| 430 // Skip the most recent user. | 430 // Skip the most recent user. |
| 431 if (email != user_email) { | 431 if (email != user_email) { |
| 432 prefs_users_update->Append(Value::CreateStringValue(user_email)); | 432 prefs_users_update->Append(Value::CreateStringValue(user_email)); |
| 433 } else { | 433 } else { |
| 434 logged_in_user_ = *it; | 434 logged_in_user_ = *it; |
| 435 } | 435 } |
| 436 } | 436 } |
| 437 prefs->SavePersistentPrefs(); | 437 prefs->ScheduleSavePersistentPrefs(); |
| 438 NotifyOnLogin(); | 438 NotifyOnLogin(); |
| 439 if (current_user_is_new_) { | 439 if (current_user_is_new_) { |
| 440 SetDefaultUserImage(email); | 440 SetDefaultUserImage(email); |
| 441 } else { | 441 } else { |
| 442 // Download profile image if it's user image and see if it has changed. | 442 // Download profile image if it's user image and see if it has changed. |
| 443 int image_index = logged_in_user_.default_image_index(); | 443 int image_index = logged_in_user_.default_image_index(); |
| 444 if (image_index == User::kProfileImageIndex) { | 444 if (image_index == User::kProfileImageIndex) { |
| 445 BrowserThread::PostDelayedTask( | 445 BrowserThread::PostDelayedTask( |
| 446 BrowserThread::UI, | 446 BrowserThread::UI, |
| 447 FROM_HERE, | 447 FROM_HERE, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); | 511 DictionaryPrefUpdate prefs_images_update(prefs, kUserImages); |
| 512 std::string image_path_string; | 512 std::string image_path_string; |
| 513 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); | 513 prefs_images_update->GetStringWithoutPathExpansion(email, &image_path_string); |
| 514 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); | 514 prefs_images_update->RemoveWithoutPathExpansion(email, NULL); |
| 515 | 515 |
| 516 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 516 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
| 517 int oauth_status; | 517 int oauth_status; |
| 518 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | 518 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); |
| 519 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 519 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
| 520 | 520 |
| 521 prefs->SavePersistentPrefs(); | 521 prefs->ScheduleSavePersistentPrefs(); |
| 522 | 522 |
| 523 int default_image_id = kDefaultImagesCount; | 523 int default_image_id = kDefaultImagesCount; |
| 524 if (!IsDefaultImagePath(image_path_string, &default_image_id)) { | 524 if (!IsDefaultImagePath(image_path_string, &default_image_id)) { |
| 525 FilePath image_path(image_path_string); | 525 FilePath image_path(image_path_string); |
| 526 BrowserThread::PostTask( | 526 BrowserThread::PostTask( |
| 527 BrowserThread::FILE, | 527 BrowserThread::FILE, |
| 528 FROM_HERE, | 528 FROM_HERE, |
| 529 base::Bind(&UserManager::DeleteUserImage, | 529 base::Bind(&UserManager::DeleteUserImage, |
| 530 base::Unretained(this), | 530 base::Unretained(this), |
| 531 image_path)); | 531 image_path)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 593 } |
| 594 | 594 |
| 595 void UserManager::SaveUserOAuthStatus(const std::string& username, | 595 void UserManager::SaveUserOAuthStatus(const std::string& username, |
| 596 OAuthTokenStatus oauth_token_status) { | 596 OAuthTokenStatus oauth_token_status) { |
| 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 598 PrefService* local_state = g_browser_process->local_state(); | 598 PrefService* local_state = g_browser_process->local_state(); |
| 599 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); | 599 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); |
| 600 oauth_status_update->SetWithoutPathExpansion(username, | 600 oauth_status_update->SetWithoutPathExpansion(username, |
| 601 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | 601 new base::FundamentalValue(static_cast<int>(oauth_token_status))); |
| 602 DVLOG(1) << "Saving user OAuth token status in Local State."; | 602 DVLOG(1) << "Saving user OAuth token status in Local State."; |
| 603 local_state->SavePersistentPrefs(); | 603 local_state->ScheduleSavePersistentPrefs(); |
| 604 } | 604 } |
| 605 | 605 |
| 606 UserManager::OAuthTokenStatus UserManager::GetUserOAuthStatus( | 606 UserManager::OAuthTokenStatus UserManager::GetUserOAuthStatus( |
| 607 const std::string& username) const { | 607 const std::string& username) const { |
| 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 609 | 609 |
| 610 if (CommandLine::ForCurrentProcess()->HasSwitch( | 610 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 611 switches::kSkipOAuthLogin)) { | 611 switches::kSkipOAuthLogin)) { |
| 612 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. | 612 // Use OAUTH_TOKEN_STATUS_VALID flag if kSkipOAuthLogin is present. |
| 613 return OAUTH_TOKEN_STATUS_VALID; | 613 return OAUTH_TOKEN_STATUS_VALID; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 observer_list_, | 849 observer_list_, |
| 850 LocalStateChanged(this)); | 850 LocalStateChanged(this)); |
| 851 } | 851 } |
| 852 | 852 |
| 853 void UserManager::DownloadProfileImage() { | 853 void UserManager::DownloadProfileImage() { |
| 854 profile_image_downloader_.reset(new ProfileImageDownloader(this)); | 854 profile_image_downloader_.reset(new ProfileImageDownloader(this)); |
| 855 profile_image_downloader_->Start(); | 855 profile_image_downloader_->Start(); |
| 856 } | 856 } |
| 857 | 857 |
| 858 } // namespace chromeos | 858 } // namespace chromeos |
| OLD | NEW |