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

Side by Side Diff: chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc

Issue 2537713002: Add support for transparent/translucent pixels in the user image (Closed)
Patch Set: fix test failures Created 4 years 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 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/login/users/avatar/user_image_manager_impl.h" 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/rand_util.h" 19 #include "base/rand_util.h"
20 #include "base/sequenced_task_runner.h" 20 #include "base/sequenced_task_runner.h"
21 #include "base/strings/string_util.h"
21 #include "base/task_runner_util.h" 22 #include "base/task_runner_util.h"
22 #include "base/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
24 #include "base/time/time.h" 25 #include "base/time/time.h"
25 #include "base/trace_event/trace_event.h" 26 #include "base/trace_event/trace_event.h"
26 #include "base/values.h" 27 #include "base/values.h"
27 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/chromeos/login/helper.h" 30 #include "chrome/browser/chromeos/login/helper.h"
30 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h" 31 #include "chrome/browser/chromeos/login/users/avatar/user_image_loader.h"
(...skipping 21 matching lines...) Expand all
52 53
53 // Delay betweeen user login and attempt to update user's profile data. 54 // Delay betweeen user login and attempt to update user's profile data.
54 const int kProfileDataDownloadDelaySec = 10; 55 const int kProfileDataDownloadDelaySec = 10;
55 56
56 // Interval betweeen retries to update user's profile data. 57 // Interval betweeen retries to update user's profile data.
57 const int kProfileDataDownloadRetryIntervalSec = 300; 58 const int kProfileDataDownloadRetryIntervalSec = 300;
58 59
59 // Delay betweeen subsequent profile refresh attempts (24 hrs). 60 // Delay betweeen subsequent profile refresh attempts (24 hrs).
60 const int kProfileRefreshIntervalSec = 24 * 3600; 61 const int kProfileRefreshIntervalSec = 24 * 3600;
61 62
62 const char kSafeImagePathExtension[] = ".jpg";
63
64 // Enum for reporting histograms about profile picture download. 63 // Enum for reporting histograms about profile picture download.
65 enum ProfileDownloadResult { 64 enum ProfileDownloadResult {
66 kDownloadSuccessChanged, 65 kDownloadSuccessChanged,
67 kDownloadSuccess, 66 kDownloadSuccess,
68 kDownloadFailure, 67 kDownloadFailure,
69 kDownloadDefault, 68 kDownloadDefault,
70 kDownloadCached, 69 kDownloadCached,
71 70
72 // Must be the last, convenient count. 71 // Must be the last, convenient count.
73 kDownloadResultsCount 72 kDownloadResultsCount
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 case user_manager::User::USER_IMAGE_EXTERNAL: 141 case user_manager::User::USER_IMAGE_EXTERNAL:
143 // TODO(ivankr): Distinguish this from selected from file. 142 // TODO(ivankr): Distinguish this from selected from file.
144 return default_user_image::kHistogramImageFromCamera; 143 return default_user_image::kHistogramImageFromCamera;
145 case user_manager::User::USER_IMAGE_PROFILE: 144 case user_manager::User::USER_IMAGE_PROFILE:
146 return default_user_image::kHistogramImageFromProfile; 145 return default_user_image::kHistogramImageFromProfile;
147 default: 146 default:
148 return image_index; 147 return image_index;
149 } 148 }
150 } 149 }
151 150
152 bool SaveImage(scoped_refptr<base::RefCountedBytes> image_bytes, 151 // Saves |image_bytes| at |image_path|, and delete the old file at
153 const base::FilePath& image_path) { 152 // |old_image_path| if needed.
153 bool SaveAndDeleteImage(scoped_refptr<base::RefCountedBytes> image_bytes,
154 const base::FilePath& image_path,
155 const base::FilePath& old_image_path) {
154 if (image_bytes->size() == 0 || 156 if (image_bytes->size() == 0 ||
155 base::WriteFile(image_path, 157 base::WriteFile(image_path,
156 reinterpret_cast<const char*>(image_bytes->front()), 158 reinterpret_cast<const char*>(image_bytes->front()),
157 image_bytes->size()) == -1) { 159 image_bytes->size()) == -1) {
158 LOG(ERROR) << "Failed to save image to file."; 160 LOG(ERROR) << "Failed to save image to file: " << image_path.AsUTF8Unsafe();
159 return false; 161 return false;
160 } 162 }
163 if (!old_image_path.empty() && old_image_path != image_path) {
164 if (!base::DeleteFile(old_image_path, false /* recursive */)) {
165 LOG(ERROR) << "Failed to delete old image: "
166 << old_image_path.AsUTF8Unsafe();
167 return false;
168 }
169 }
161 170
162 return true; 171 return true;
163 } 172 }
164 173
174 // Returns the robust codec enum for the given image path's extension.
175 // The user image is always stored in either JPEG or PNG.
176 ImageDecoder::ImageCodec ChooseRobustCodecFromPath(
177 const base::FilePath& image_path) {
178 if (image_path.Extension() == FILE_PATH_LITERAL(".jpg"))
179 return ImageDecoder::ROBUST_JPEG_CODEC;
180 if (image_path.Extension() == FILE_PATH_LITERAL(".png"))
181 return ImageDecoder::ROBUST_PNG_CODEC;
182
183 NOTREACHED() << "Invalid path: " << image_path.AsUTF8Unsafe();
184 return ImageDecoder::ROBUST_JPEG_CODEC;
185 }
186
187 // Returns the suffix for the given image format, that should be JPEG or PNG.
188 const char* ChooseExtensionFromImageFormat(
189 user_manager::UserImage::ImageFormat image_format) {
190 switch (image_format) {
191 case user_manager::UserImage::FORMAT_JPEG:
192 return ".jpg";
193 case user_manager::UserImage::FORMAT_PNG:
194 return ".png";
195 default:
196 NOTREACHED() << "Invalid format: " << image_format;
197 return ".jpg";
198 }
199 }
200
165 } // namespace 201 } // namespace
166 202
167 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info"; 203 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info";
168 const char UserImageManagerImpl::kImagePathNodeName[] = "path"; 204 const char UserImageManagerImpl::kImagePathNodeName[] = "path";
169 const char UserImageManagerImpl::kImageIndexNodeName[] = "index"; 205 const char UserImageManagerImpl::kImageIndexNodeName[] = "index";
170 const char UserImageManagerImpl::kImageURLNodeName[] = "url"; 206 const char UserImageManagerImpl::kImageURLNodeName[] = "url";
171 207
172 // static 208 // static
173 void UserImageManager::RegisterPrefs(PrefRegistrySimple* registry) { 209 void UserImageManager::RegisterPrefs(PrefRegistrySimple* registry) {
174 registry->RegisterDictionaryPref(UserImageManagerImpl::kUserImageProperties); 210 registry->RegisterDictionaryPref(UserImageManagerImpl::kUserImageProperties);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 std::unique_ptr<user_manager::UserImage> user_image); 262 std::unique_ptr<user_manager::UserImage> user_image);
227 263
228 // Updates the user object with |user_image|. 264 // Updates the user object with |user_image|.
229 void UpdateUser(std::unique_ptr<user_manager::UserImage> user_image); 265 void UpdateUser(std::unique_ptr<user_manager::UserImage> user_image);
230 266
231 // Updates the user object with |user_image|, and saves the image 267 // Updates the user object with |user_image|, and saves the image
232 // bytes. Local state will be updated as needed. 268 // bytes. Local state will be updated as needed.
233 void UpdateUserAndSaveImage( 269 void UpdateUserAndSaveImage(
234 std::unique_ptr<user_manager::UserImage> user_image); 270 std::unique_ptr<user_manager::UserImage> user_image);
235 271
236 // Saves |image_bytes| to disk in JPEG format if 272 // Saves |image_bytes| to disk in |image_format| if
237 // |image_is_safe_format|. Local state will be updated as needed. 273 // |image_is_safe_format|. Local state will be updated as needed.
238 void SaveImageAndUpdateLocalState( 274 void SaveImageAndUpdateLocalState(
239 bool image_is_safe_format, 275 bool image_is_safe_format,
240 scoped_refptr<base::RefCountedBytes> image_bytes); 276 scoped_refptr<base::RefCountedBytes> image_bytes,
277 user_manager::UserImage::ImageFormat image_format);
241 278
242 // Called back after the user image has been saved to 279 // Called back after the user image has been saved to
243 // disk. Updates the user image information in local state. The 280 // disk. Updates the user image information in local state. The
244 // information is only updated if |success| is true (indicating that 281 // information is only updated if |success| is true (indicating that
245 // the image was saved successfully) or the user image is the 282 // the image was saved successfully) or the user image is the
246 // profile image (indicating that even if the image could not be 283 // profile image (indicating that even if the image could not be
247 // saved because it is not available right now, it will be 284 // saved because it is not available right now, it will be
248 // downloaded eventually). 285 // downloaded eventually).
249 void OnSaveImageDone(bool success); 286 void OnSaveImageDone(bool success);
250 287
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 image_index_ < default_user_image::kDefaultImagesCount) { 332 image_index_ < default_user_image::kDefaultImagesCount) {
296 // Load one of the default images. This happens synchronously. 333 // Load one of the default images. This happens synchronously.
297 std::unique_ptr<user_manager::UserImage> user_image( 334 std::unique_ptr<user_manager::UserImage> user_image(
298 new user_manager::UserImage( 335 new user_manager::UserImage(
299 default_user_image::GetDefaultImage(image_index_))); 336 default_user_image::GetDefaultImage(image_index_)));
300 UpdateUser(std::move(user_image)); 337 UpdateUser(std::move(user_image));
301 NotifyJobDone(); 338 NotifyJobDone();
302 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || 339 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL ||
303 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { 340 image_index_ == user_manager::User::USER_IMAGE_PROFILE) {
304 // Load the user image from a file referenced by |image_path|. This happens 341 // Load the user image from a file referenced by |image_path|. This happens
305 // asynchronously. ROBUST_JPEG_CODEC can be used here because 342 // asynchronously. ROBUST_JPEG_CODEC or ROBUST_PNG_CODEC can be used here
306 // LoadImage() is called only for users whose user image has previously 343 // because LoadImage() is called only for users whose user image has
307 // been set by one of the Set*() methods, which transcode to JPEG format. 344 // previously been set by one of the Set*() methods, which transcode to
345 // JPEG or PNG format.
308 DCHECK(!image_path_.empty()); 346 DCHECK(!image_path_.empty());
309 user_image_loader::StartWithFilePath( 347 user_image_loader::StartWithFilePath(
310 parent_->background_task_runner_, image_path_, 348 parent_->background_task_runner_, image_path_,
311 ImageDecoder::ROBUST_JPEG_CODEC, 349 ChooseRobustCodecFromPath(image_path_),
312 0, // Do not crop. 350 0, // Do not crop.
313 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); 351 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false));
314 } else { 352 } else {
315 NOTREACHED(); 353 NOTREACHED();
316 NotifyJobDone(); 354 NotifyJobDone();
317 } 355 }
318 } 356 }
319 357
320 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { 358 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) {
321 DCHECK(!run_); 359 DCHECK(!run_);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 parent_->OnJobChangedUserImage(); 457 parent_->OnJobChangedUserImage();
420 } 458 }
421 459
422 void UserImageManagerImpl::Job::UpdateUserAndSaveImage( 460 void UserImageManagerImpl::Job::UpdateUserAndSaveImage(
423 std::unique_ptr<user_manager::UserImage> user_image) { 461 std::unique_ptr<user_manager::UserImage> user_image) {
424 const bool image_is_safe_format = user_image->is_safe_format(); 462 const bool image_is_safe_format = user_image->is_safe_format();
425 // Create a reference before user_image is passed. 463 // Create a reference before user_image is passed.
426 scoped_refptr<base::RefCountedBytes> image_bytes; 464 scoped_refptr<base::RefCountedBytes> image_bytes;
427 if (image_is_safe_format) 465 if (image_is_safe_format)
428 image_bytes = user_image->image_bytes(); 466 image_bytes = user_image->image_bytes();
467 const user_manager::UserImage::ImageFormat image_format =
468 user_image->image_format();
429 469
430 UpdateUser(std::move(user_image)); 470 UpdateUser(std::move(user_image));
431 471
432 SaveImageAndUpdateLocalState(image_is_safe_format, image_bytes); 472 SaveImageAndUpdateLocalState(image_is_safe_format, image_bytes, image_format);
433 } 473 }
434 474
435 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( 475 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState(
436 bool image_is_safe_format, 476 bool image_is_safe_format,
437 scoped_refptr<base::RefCountedBytes> image_bytes) { 477 scoped_refptr<base::RefCountedBytes> image_bytes,
438 base::FilePath user_data_dir; 478 user_manager::UserImage::ImageFormat image_format) {
439 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 479 // This can happen if a stub profile image is chosen (i.e. the profile
440 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); 480 // image hasn't been downloaded yet)
achuithb 2016/12/02 08:28:18 nit: period
satorux1 2016/12/05 01:57:40 Done.
481 if (!image_bytes) {
482 OnSaveImageDone(false);
483 return;
satorux1 2016/12/02 06:42:58 Added this to fix the following NOTREACHED() failu
achuithb 2016/12/02 08:28:18 Acknowledged.
484 }
441 485
442 // This should always be true, because of the following reasons: 486 // This should always be true, because of the following reasons:
443 // 487 //
444 // 1) Profile image from Google account -> UserImage is created with 488 // 1) Profile image from Google account -> UserImage is created with
445 // CreateAndEncode() that generates safe bytes representation. 489 // CreateAndEncode() that generates safe bytes representation.
446 // 2) Profile image from user-specified image -> The bytes representation 490 // 2) Profile image from user-specified image -> The bytes representation
447 // is regenerated after the original image is decoded and cropped. 491 // is regenerated after the original image is decoded and cropped.
448 // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is 492 // 3) Profile image from policy (via OnExternalDataFetched()) -> JPEG is
449 // only allowed and ROBUST_JPEG_CODEC is used. 493 // only allowed and ROBUST_JPEG_CODEC is used.
450 // 494 //
451 // However, check the value just in case because an unsafe image should 495 // However, check the value just in case because an unsafe image should
452 // never be saved. 496 // never be saved.
453 if (!image_is_safe_format) { 497 if (!image_is_safe_format) {
454 LOG(ERROR) << "User image is not in safe format"; 498 LOG(ERROR) << "User image is not in safe format";
455 OnSaveImageDone(false); 499 OnSaveImageDone(false);
456 return; 500 return;
457 } 501 }
458 502
503 base::FilePath user_data_dir;
504 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
505 // TODO(crbug.com/670557): Use GetAccountIdKey() instead of user_id().
506 image_path_ = user_data_dir.AppendASCII(
507 user_id() + ChooseExtensionFromImageFormat(image_format));
satorux1 2016/12/02 06:42:58 Moved this code here, as there is no need to gener
achuithb 2016/12/02 08:28:18 Acknowledged.
508
509 // The old image file should be removed if the path is different. This
510 // can happen if the user image format is changed from JPEG to PNG or
511 // vice versa.
512 base::FilePath old_image_path;
513 // Because the user ID (i.e. email address) contains '.', the code here
514 // cannot use the dots notation (path expantion) hence is verbose.
515 PrefService* local_state = g_browser_process->local_state();
516 const base::DictionaryValue* prefs_images =
517 local_state->GetDictionary(kUserImageProperties);
518 if (prefs_images) {
519 const base::DictionaryValue* image_properties = nullptr;
520 prefs_images->GetDictionaryWithoutPathExpansion(user_id(),
521 &image_properties);
522 if (image_properties) {
523 std::string value;
524 image_properties->GetString(kImagePathNodeName, &value);
525 old_image_path = base::FilePath::FromUTF8Unsafe(value);
526 }
527 }
528
459 base::PostTaskAndReplyWithResult( 529 base::PostTaskAndReplyWithResult(
460 parent_->background_task_runner_.get(), FROM_HERE, 530 parent_->background_task_runner_.get(), FROM_HERE,
461 base::Bind(&SaveImage, image_bytes, image_path_), 531 base::Bind(&SaveAndDeleteImage, image_bytes, image_path_, old_image_path),
462 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); 532 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr()));
463 } 533 }
464 534
465 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { 535 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) {
466 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE) 536 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE)
467 UpdateLocalState(); 537 UpdateLocalState();
468 NotifyJobDone(); 538 NotifyJobDone();
469 } 539 }
470 540
471 void UserImageManagerImpl::Job::UpdateLocalState() { 541 void UserImageManagerImpl::Job::UpdateLocalState() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 UserImageManagerImpl::~UserImageManagerImpl() {} 581 UserImageManagerImpl::~UserImageManagerImpl() {}
512 582
513 void UserImageManagerImpl::LoadUserImage() { 583 void UserImageManagerImpl::LoadUserImage() {
514 PrefService* local_state = g_browser_process->local_state(); 584 PrefService* local_state = g_browser_process->local_state();
515 const base::DictionaryValue* prefs_images = 585 const base::DictionaryValue* prefs_images =
516 local_state->GetDictionary(kUserImageProperties); 586 local_state->GetDictionary(kUserImageProperties);
517 if (!prefs_images) 587 if (!prefs_images)
518 return; 588 return;
519 user_manager::User* user = GetUserAndModify(); 589 user_manager::User* user = GetUserAndModify();
520 590
521 const base::DictionaryValue* image_properties = NULL; 591 const base::DictionaryValue* image_properties = nullptr;
522 prefs_images->GetDictionaryWithoutPathExpansion(user_id(), &image_properties); 592 prefs_images->GetDictionaryWithoutPathExpansion(user_id(), &image_properties);
523 593
524 // If the user image for |user_id| is managed by policy and the policy-set 594 // If the user image for |user_id| is managed by policy and the policy-set
525 // image is being loaded and persisted right now, let that job continue. It 595 // image is being loaded and persisted right now, let that job continue. It
526 // will update the user image when done. 596 // will update the user image when done.
527 if (IsUserImageManaged() && job_.get()) 597 if (IsUserImageManaged() && job_.get())
528 return; 598 return;
529 599
530 if (!image_properties) { 600 if (!image_properties) {
531 SetInitialUserImage(); 601 SetInitialUserImage();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 return; 710 return;
641 job_.reset(new Job(this)); 711 job_.reset(new Job(this));
642 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); 712 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true);
643 } 713 }
644 714
645 void UserImageManagerImpl::SaveUserImageFromProfileImage() { 715 void UserImageManagerImpl::SaveUserImageFromProfileImage() {
646 if (IsUserImageManaged()) 716 if (IsUserImageManaged())
647 return; 717 return;
648 // Use the profile image if it has been downloaded already. Otherwise, use a 718 // Use the profile image if it has been downloaded already. Otherwise, use a
649 // stub image (gray avatar). 719 // stub image (gray avatar).
720 std::unique_ptr<user_manager::UserImage> user_image;
721 if (downloaded_profile_image_.isNull()) {
722 user_image = base::WrapUnique(new user_manager::UserImage);
723 } else {
724 user_image = user_manager::UserImage::CreateAndEncode(
725 downloaded_profile_image_, user_manager::UserImage::ChooseImageFormat(
726 *downloaded_profile_image_.bitmap()));
727 }
650 job_.reset(new Job(this)); 728 job_.reset(new Job(this));
651 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, 729 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE,
652 downloaded_profile_image_.isNull() 730 std::move(user_image));
653 ? base::WrapUnique(new user_manager::UserImage)
654 : user_manager::UserImage::CreateAndEncode(
655 downloaded_profile_image_));
656 // If no profile image has been downloaded yet, ensure that a download is 731 // If no profile image has been downloaded yet, ensure that a download is
657 // started. 732 // started.
658 if (downloaded_profile_image_.isNull()) 733 if (downloaded_profile_image_.isNull())
659 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); 734 DownloadProfileData(kProfileDownloadReasonProfileImageChosen);
660 } 735 }
661 736
662 void UserImageManagerImpl::DeleteUserImage() { 737 void UserImageManagerImpl::DeleteUserImage() {
663 job_.reset(); 738 job_.reset();
664 DeleteUserImageAndLocalStateEntry(kUserImageProperties); 739 DeleteUserImageAndLocalStateEntry(kUserImageProperties);
665 } 740 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 985
911 std::string image_path; 986 std::string image_path;
912 image_properties->GetString(kImagePathNodeName, &image_path); 987 image_properties->GetString(kImagePathNodeName, &image_path);
913 if (!image_path.empty()) { 988 if (!image_path.empty()) {
914 background_task_runner_->PostTask( 989 background_task_runner_->PostTask(
915 FROM_HERE, 990 FROM_HERE,
916 base::Bind(base::IgnoreResult(&base::DeleteFile), 991 base::Bind(base::IgnoreResult(&base::DeleteFile),
917 base::FilePath(image_path), 992 base::FilePath(image_path),
918 false)); 993 false));
919 } 994 }
920 update->RemoveWithoutPathExpansion(user_id(), NULL); 995 update->RemoveWithoutPathExpansion(user_id(), nullptr);
921 } 996 }
922 997
923 void UserImageManagerImpl::OnJobChangedUserImage() { 998 void UserImageManagerImpl::OnJobChangedUserImage() {
924 if (GetUser()->is_logged_in()) 999 if (GetUser()->is_logged_in())
925 TryToInitDownloadedProfileImage(); 1000 TryToInitDownloadedProfileImage();
926 1001
927 content::NotificationService::current()->Notify( 1002 content::NotificationService::current()->Notify(
928 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 1003 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
929 content::Source<UserImageManagerImpl>(this), 1004 content::Source<UserImageManagerImpl>(this),
930 content::Details<const user_manager::User>(GetUser())); 1005 content::Details<const user_manager::User>(GetUser()));
(...skipping 26 matching lines...) Expand all
957 } 1032 }
958 1033
959 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { 1034 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const {
960 const user_manager::User* user = GetUser(); 1035 const user_manager::User* user = GetUser();
961 if (!user) 1036 if (!user)
962 return false; 1037 return false;
963 return user->is_logged_in() && user->HasGaiaAccount(); 1038 return user->is_logged_in() && user->HasGaiaAccount();
964 } 1039 }
965 1040
966 } // namespace chromeos 1041 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698