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

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: Add support for transparent/translucent pixels in the user image 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|. If |should_remove_old_image| is true,
153 const base::FilePath& image_path) { 152 // remove the old image at |old_image_path|.
153 bool SaveAndDeleteImage(scoped_refptr<base::RefCountedBytes> image_bytes,
154 const base::FilePath& image_path,
155 const base::FilePath& old_image_path,
156 bool should_remove_old_image) {
satorux1 2016/12/02 04:59:36 removed should_remove_old_image parameter to simpl
154 if (image_bytes->size() == 0 || 157 if (image_bytes->size() == 0 ||
155 base::WriteFile(image_path, 158 base::WriteFile(image_path,
156 reinterpret_cast<const char*>(image_bytes->front()), 159 reinterpret_cast<const char*>(image_bytes->front()),
157 image_bytes->size()) == -1) { 160 image_bytes->size()) == -1) {
158 LOG(ERROR) << "Failed to save image to file."; 161 LOG(ERROR) << "Failed to save image to file: " << image_path.AsUTF8Unsafe();
159 return false; 162 return false;
160 } 163 }
164 if (should_remove_old_image) {
165 DCHECK(!old_image_path.empty());
166 if (!base::DeleteFile(old_image_path, false /* recursive */)) {
167 LOG(ERROR) << "Failed to delete old image: "
168 << old_image_path.AsUTF8Unsafe();
169 return false;
170 }
171 }
161 172
162 return true; 173 return true;
163 } 174 }
164 175
176 // Returns the robust codec enum for the given image path's extension.
177 // The user image is always stored in either JPEG or PNG.
178 ImageDecoder::ImageCodec ChooseRobustCodecFromPath(
179 const base::FilePath& image_path) {
180 if (image_path.Extension() == FILE_PATH_LITERAL(".jpg"))
181 return ImageDecoder::ROBUST_JPEG_CODEC;
182 if (image_path.Extension() == FILE_PATH_LITERAL(".png"))
183 return ImageDecoder::ROBUST_PNG_CODEC;
184
185 NOTREACHED() << "Invalid path: " << image_path.AsUTF8Unsafe();
186 return ImageDecoder::ROBUST_JPEG_CODEC;
187 }
188
189 // Returns the suffix for the given image format, that should be JPEG or PNG.
190 const char* ChooseExtensionFromImageFormat(
191 user_manager::UserImage::ImageFormat image_format) {
192 switch (image_format) {
193 case user_manager::UserImage::FORMAT_JPEG:
194 return ".jpg";
195 case user_manager::UserImage::FORMAT_PNG:
196 return ".png";
197 default:
198 NOTREACHED() << "Invalid format: " << image_format;
199 return ".jpg";
200 }
201 }
202
165 } // namespace 203 } // namespace
166 204
167 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info"; 205 const char UserImageManagerImpl::kUserImageProperties[] = "user_image_info";
168 const char UserImageManagerImpl::kImagePathNodeName[] = "path"; 206 const char UserImageManagerImpl::kImagePathNodeName[] = "path";
169 const char UserImageManagerImpl::kImageIndexNodeName[] = "index"; 207 const char UserImageManagerImpl::kImageIndexNodeName[] = "index";
170 const char UserImageManagerImpl::kImageURLNodeName[] = "url"; 208 const char UserImageManagerImpl::kImageURLNodeName[] = "url";
171 209
172 // static 210 // static
173 void UserImageManager::RegisterPrefs(PrefRegistrySimple* registry) { 211 void UserImageManager::RegisterPrefs(PrefRegistrySimple* registry) {
174 registry->RegisterDictionaryPref(UserImageManagerImpl::kUserImageProperties); 212 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); 264 std::unique_ptr<user_manager::UserImage> user_image);
227 265
228 // Updates the user object with |user_image|. 266 // Updates the user object with |user_image|.
229 void UpdateUser(std::unique_ptr<user_manager::UserImage> user_image); 267 void UpdateUser(std::unique_ptr<user_manager::UserImage> user_image);
230 268
231 // Updates the user object with |user_image|, and saves the image 269 // Updates the user object with |user_image|, and saves the image
232 // bytes. Local state will be updated as needed. 270 // bytes. Local state will be updated as needed.
233 void UpdateUserAndSaveImage( 271 void UpdateUserAndSaveImage(
234 std::unique_ptr<user_manager::UserImage> user_image); 272 std::unique_ptr<user_manager::UserImage> user_image);
235 273
236 // Saves |image_bytes| to disk in JPEG format if 274 // Saves |image_bytes| to disk in |image_format| if
237 // |image_is_safe_format|. Local state will be updated as needed. 275 // |image_is_safe_format|. Local state will be updated as needed.
238 void SaveImageAndUpdateLocalState( 276 void SaveImageAndUpdateLocalState(
239 bool image_is_safe_format, 277 bool image_is_safe_format,
240 scoped_refptr<base::RefCountedBytes> image_bytes); 278 scoped_refptr<base::RefCountedBytes> image_bytes,
279 user_manager::UserImage::ImageFormat image_format);
241 280
242 // Called back after the user image has been saved to 281 // Called back after the user image has been saved to
243 // disk. Updates the user image information in local state. The 282 // disk. Updates the user image information in local state. The
244 // information is only updated if |success| is true (indicating that 283 // information is only updated if |success| is true (indicating that
245 // the image was saved successfully) or the user image is the 284 // the image was saved successfully) or the user image is the
246 // profile image (indicating that even if the image could not be 285 // profile image (indicating that even if the image could not be
247 // saved because it is not available right now, it will be 286 // saved because it is not available right now, it will be
248 // downloaded eventually). 287 // downloaded eventually).
249 void OnSaveImageDone(bool success); 288 void OnSaveImageDone(bool success);
250 289
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 image_index_ < default_user_image::kDefaultImagesCount) { 334 image_index_ < default_user_image::kDefaultImagesCount) {
296 // Load one of the default images. This happens synchronously. 335 // Load one of the default images. This happens synchronously.
297 std::unique_ptr<user_manager::UserImage> user_image( 336 std::unique_ptr<user_manager::UserImage> user_image(
298 new user_manager::UserImage( 337 new user_manager::UserImage(
299 default_user_image::GetDefaultImage(image_index_))); 338 default_user_image::GetDefaultImage(image_index_)));
300 UpdateUser(std::move(user_image)); 339 UpdateUser(std::move(user_image));
301 NotifyJobDone(); 340 NotifyJobDone();
302 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || 341 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL ||
303 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { 342 image_index_ == user_manager::User::USER_IMAGE_PROFILE) {
304 // Load the user image from a file referenced by |image_path|. This happens 343 // Load the user image from a file referenced by |image_path|. This happens
305 // asynchronously. ROBUST_JPEG_CODEC can be used here because 344 // asynchronously. ROBUST_JPEG_CODEC or ROBUST_PNG_CODEC can be used here
306 // LoadImage() is called only for users whose user image has previously 345 // 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. 346 // previously been set by one of the Set*() methods, which transcode to
347 // JPEG or PNG format.
308 DCHECK(!image_path_.empty()); 348 DCHECK(!image_path_.empty());
309 user_image_loader::StartWithFilePath( 349 user_image_loader::StartWithFilePath(
310 parent_->background_task_runner_, image_path_, 350 parent_->background_task_runner_, image_path_,
311 ImageDecoder::ROBUST_JPEG_CODEC, 351 ChooseRobustCodecFromPath(image_path_),
312 0, // Do not crop. 352 0, // Do not crop.
313 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); 353 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false));
314 } else { 354 } else {
315 NOTREACHED(); 355 NOTREACHED();
316 NotifyJobDone(); 356 NotifyJobDone();
317 } 357 }
318 } 358 }
319 359
320 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { 360 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) {
321 DCHECK(!run_); 361 DCHECK(!run_);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 parent_->OnJobChangedUserImage(); 459 parent_->OnJobChangedUserImage();
420 } 460 }
421 461
422 void UserImageManagerImpl::Job::UpdateUserAndSaveImage( 462 void UserImageManagerImpl::Job::UpdateUserAndSaveImage(
423 std::unique_ptr<user_manager::UserImage> user_image) { 463 std::unique_ptr<user_manager::UserImage> user_image) {
424 const bool image_is_safe_format = user_image->is_safe_format(); 464 const bool image_is_safe_format = user_image->is_safe_format();
425 // Create a reference before user_image is passed. 465 // Create a reference before user_image is passed.
426 scoped_refptr<base::RefCountedBytes> image_bytes; 466 scoped_refptr<base::RefCountedBytes> image_bytes;
427 if (image_is_safe_format) 467 if (image_is_safe_format)
428 image_bytes = user_image->image_bytes(); 468 image_bytes = user_image->image_bytes();
469 const user_manager::UserImage::ImageFormat image_format =
470 user_image->image_format();
429 471
430 UpdateUser(std::move(user_image)); 472 UpdateUser(std::move(user_image));
431 473
432 SaveImageAndUpdateLocalState(image_is_safe_format, image_bytes); 474 SaveImageAndUpdateLocalState(image_is_safe_format, image_bytes, image_format);
433 } 475 }
434 476
435 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( 477 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState(
436 bool image_is_safe_format, 478 bool image_is_safe_format,
437 scoped_refptr<base::RefCountedBytes> image_bytes) { 479 scoped_refptr<base::RefCountedBytes> image_bytes,
480 user_manager::UserImage::ImageFormat image_format) {
438 base::FilePath user_data_dir; 481 base::FilePath user_data_dir;
439 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 482 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
440 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); 483 image_path_ = user_data_dir.AppendASCII(
484 user_id() + ChooseExtensionFromImageFormat(image_format));
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 // The old image file should be removed if the path is different. This
504 // can happen if the user image format is changed from JPEG to PNG or
505 // vice versa.
506 bool should_remove_old_image = false;
507 base::FilePath old_image_path;
508 // Because the user ID (i.e. email address) contains '.', the code here
509 // cannot use the dots notation (path expantion) hence is verbose.
510 PrefService* local_state = g_browser_process->local_state();
511 const base::DictionaryValue* prefs_images =
512 local_state->GetDictionary(kUserImageProperties);
513 if (prefs_images) {
514 const base::DictionaryValue* image_properties = nullptr;
515 prefs_images->GetDictionaryWithoutPathExpansion(user_id(),
achuithb 2016/12/01 23:12:16 Please add a TODO to replace this with GetAccountI
satorux1 2016/12/02 04:59:36 Filed a bug and added a TODO comment in SaveImageA
516 &image_properties);
517 if (image_properties) {
518 std::string value;
519 image_properties->GetString(kImagePathNodeName, &value);
520 old_image_path = base::FilePath::FromUTF8Unsafe(value);
521 if (!old_image_path.empty() && old_image_path != image_path_)
522 should_remove_old_image = true;
523 }
524 }
525
459 base::PostTaskAndReplyWithResult( 526 base::PostTaskAndReplyWithResult(
460 parent_->background_task_runner_.get(), FROM_HERE, 527 parent_->background_task_runner_.get(), FROM_HERE,
461 base::Bind(&SaveImage, image_bytes, image_path_), 528 base::Bind(&SaveAndDeleteImage, image_bytes, image_path_, old_image_path,
529 should_remove_old_image),
462 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr())); 530 base::Bind(&Job::OnSaveImageDone, weak_factory_.GetWeakPtr()));
463 } 531 }
464 532
465 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) { 533 void UserImageManagerImpl::Job::OnSaveImageDone(bool success) {
466 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE) 534 if (success || image_index_ == user_manager::User::USER_IMAGE_PROFILE)
467 UpdateLocalState(); 535 UpdateLocalState();
468 NotifyJobDone(); 536 NotifyJobDone();
469 } 537 }
470 538
471 void UserImageManagerImpl::Job::UpdateLocalState() { 539 void UserImageManagerImpl::Job::UpdateLocalState() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 UserImageManagerImpl::~UserImageManagerImpl() {} 579 UserImageManagerImpl::~UserImageManagerImpl() {}
512 580
513 void UserImageManagerImpl::LoadUserImage() { 581 void UserImageManagerImpl::LoadUserImage() {
514 PrefService* local_state = g_browser_process->local_state(); 582 PrefService* local_state = g_browser_process->local_state();
515 const base::DictionaryValue* prefs_images = 583 const base::DictionaryValue* prefs_images =
516 local_state->GetDictionary(kUserImageProperties); 584 local_state->GetDictionary(kUserImageProperties);
517 if (!prefs_images) 585 if (!prefs_images)
518 return; 586 return;
519 user_manager::User* user = GetUserAndModify(); 587 user_manager::User* user = GetUserAndModify();
520 588
521 const base::DictionaryValue* image_properties = NULL; 589 const base::DictionaryValue* image_properties = nullptr;
522 prefs_images->GetDictionaryWithoutPathExpansion(user_id(), &image_properties); 590 prefs_images->GetDictionaryWithoutPathExpansion(user_id(), &image_properties);
523 591
524 // If the user image for |user_id| is managed by policy and the policy-set 592 // 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 593 // image is being loaded and persisted right now, let that job continue. It
526 // will update the user image when done. 594 // will update the user image when done.
527 if (IsUserImageManaged() && job_.get()) 595 if (IsUserImageManaged() && job_.get())
528 return; 596 return;
529 597
530 if (!image_properties) { 598 if (!image_properties) {
531 SetInitialUserImage(); 599 SetInitialUserImage();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 return; 708 return;
641 job_.reset(new Job(this)); 709 job_.reset(new Job(this));
642 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); 710 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true);
643 } 711 }
644 712
645 void UserImageManagerImpl::SaveUserImageFromProfileImage() { 713 void UserImageManagerImpl::SaveUserImageFromProfileImage() {
646 if (IsUserImageManaged()) 714 if (IsUserImageManaged())
647 return; 715 return;
648 // Use the profile image if it has been downloaded already. Otherwise, use a 716 // Use the profile image if it has been downloaded already. Otherwise, use a
649 // stub image (gray avatar). 717 // stub image (gray avatar).
718 std::unique_ptr<user_manager::UserImage> user_image;
719 if (downloaded_profile_image_.isNull()) {
720 user_image = base::WrapUnique(new user_manager::UserImage);
721 } else {
722 user_image = user_manager::UserImage::CreateAndEncode(
723 downloaded_profile_image_, user_manager::UserImage::ChooseImageFormat(
724 *downloaded_profile_image_.bitmap()));
725 }
650 job_.reset(new Job(this)); 726 job_.reset(new Job(this));
651 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, 727 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE,
652 downloaded_profile_image_.isNull() 728 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 729 // If no profile image has been downloaded yet, ensure that a download is
657 // started. 730 // started.
658 if (downloaded_profile_image_.isNull()) 731 if (downloaded_profile_image_.isNull())
659 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); 732 DownloadProfileData(kProfileDownloadReasonProfileImageChosen);
660 } 733 }
661 734
662 void UserImageManagerImpl::DeleteUserImage() { 735 void UserImageManagerImpl::DeleteUserImage() {
663 job_.reset(); 736 job_.reset();
664 DeleteUserImageAndLocalStateEntry(kUserImageProperties); 737 DeleteUserImageAndLocalStateEntry(kUserImageProperties);
665 } 738 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 983
911 std::string image_path; 984 std::string image_path;
912 image_properties->GetString(kImagePathNodeName, &image_path); 985 image_properties->GetString(kImagePathNodeName, &image_path);
913 if (!image_path.empty()) { 986 if (!image_path.empty()) {
914 background_task_runner_->PostTask( 987 background_task_runner_->PostTask(
915 FROM_HERE, 988 FROM_HERE,
916 base::Bind(base::IgnoreResult(&base::DeleteFile), 989 base::Bind(base::IgnoreResult(&base::DeleteFile),
917 base::FilePath(image_path), 990 base::FilePath(image_path),
918 false)); 991 false));
919 } 992 }
920 update->RemoveWithoutPathExpansion(user_id(), NULL); 993 update->RemoveWithoutPathExpansion(user_id(), nullptr);
921 } 994 }
922 995
923 void UserImageManagerImpl::OnJobChangedUserImage() { 996 void UserImageManagerImpl::OnJobChangedUserImage() {
924 if (GetUser()->is_logged_in()) 997 if (GetUser()->is_logged_in())
925 TryToInitDownloadedProfileImage(); 998 TryToInitDownloadedProfileImage();
926 999
927 content::NotificationService::current()->Notify( 1000 content::NotificationService::current()->Notify(
928 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 1001 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
929 content::Source<UserImageManagerImpl>(this), 1002 content::Source<UserImageManagerImpl>(this),
930 content::Details<const user_manager::User>(GetUser())); 1003 content::Details<const user_manager::User>(GetUser()));
(...skipping 26 matching lines...) Expand all
957 } 1030 }
958 1031
959 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { 1032 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const {
960 const user_manager::User* user = GetUser(); 1033 const user_manager::User* user = GetUser();
961 if (!user) 1034 if (!user)
962 return false; 1035 return false;
963 return user->is_logged_in() && user->HasGaiaAccount(); 1036 return user->is_logged_in() && user->HasGaiaAccount();
964 } 1037 }
965 1038
966 } // namespace chromeos 1039 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698