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 "components/wallpaper/wallpaper_manager_base.h" | 5 #include "components/wallpaper/wallpaper_manager_base.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <vector> | 8 #include <vector> |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // color. | 68 // color. |
69 const SkColor kDefaultWallpaperColor = SK_ColorGRAY; | 69 const SkColor kDefaultWallpaperColor = SK_ColorGRAY; |
70 | 70 |
71 // The path ids for directories. | 71 // The path ids for directories. |
72 int dir_user_data_path_id = -1; // chrome::DIR_USER_DATA | 72 int dir_user_data_path_id = -1; // chrome::DIR_USER_DATA |
73 int dir_chromeos_wallpapers_path_id = -1; // chrome::DIR_CHROMEOS_WALLPAPERS | 73 int dir_chromeos_wallpapers_path_id = -1; // chrome::DIR_CHROMEOS_WALLPAPERS |
74 int dir_chromeos_custom_wallpapers_path_id = | 74 int dir_chromeos_custom_wallpapers_path_id = |
75 -1; // chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS | 75 -1; // chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS |
76 | 76 |
77 bool MoveCustomWallpaperDirectory(const char* sub_dir, | 77 bool MoveCustomWallpaperDirectory(const char* sub_dir, |
78 const std::string& user_id, | 78 const std::string& from_name, |
79 const std::string& user_id_hash) { | 79 const std::string& to_name) { |
80 base::FilePath base_path = | 80 base::FilePath base_path = |
81 WallpaperManagerBase::GetCustomWallpaperDir(sub_dir); | 81 WallpaperManagerBase::GetCustomWallpaperDir(sub_dir); |
82 base::FilePath to_path = base_path.Append(user_id_hash); | 82 base::FilePath to_path = base_path.Append(to_name); |
83 base::FilePath from_path = base_path.Append(user_id); | 83 base::FilePath from_path = base_path.Append(from_name); |
84 if (base::PathExists(from_path)) | 84 if (base::PathExists(from_path)) |
85 return base::Move(from_path, to_path); | 85 return base::Move(from_path, to_path); |
86 return false; | 86 return false; |
87 } | 87 } |
88 | 88 |
89 // Deletes a list of wallpaper files in |file_list|. | 89 // Deletes a list of wallpaper files in |file_list|. |
90 void DeleteWallpaperInList(const std::vector<base::FilePath>& file_list) { | 90 void DeleteWallpaperInList(const std::vector<base::FilePath>& file_list) { |
91 for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); | 91 for (std::vector<base::FilePath>::const_iterator it = file_list.begin(); |
92 it != file_list.end(); ++it) { | 92 it != file_list.end(); ++it) { |
93 base::FilePath path = *it; | 93 base::FilePath path = *it; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 // TestApi. For testing purpose | 253 // TestApi. For testing purpose |
254 WallpaperManagerBase::TestApi::TestApi(WallpaperManagerBase* wallpaper_manager) | 254 WallpaperManagerBase::TestApi::TestApi(WallpaperManagerBase* wallpaper_manager) |
255 : wallpaper_manager_(wallpaper_manager) { | 255 : wallpaper_manager_(wallpaper_manager) { |
256 } | 256 } |
257 | 257 |
258 WallpaperManagerBase::TestApi::~TestApi() { | 258 WallpaperManagerBase::TestApi::~TestApi() { |
259 } | 259 } |
260 | 260 |
261 bool WallpaperManagerBase::TestApi::GetWallpaperFromCache( | 261 bool WallpaperManagerBase::TestApi::GetWallpaperFromCache( |
262 const std::string& user_id, | 262 const AccountId& account_id, |
263 gfx::ImageSkia* image) { | 263 gfx::ImageSkia* image) { |
264 return wallpaper_manager_->GetWallpaperFromCache(user_id, image); | 264 return wallpaper_manager_->GetWallpaperFromCache(account_id, image); |
265 } | 265 } |
266 | 266 |
267 bool WallpaperManagerBase::TestApi::GetPathFromCache( | 267 bool WallpaperManagerBase::TestApi::GetPathFromCache( |
268 const std::string& user_id, | 268 const AccountId& account_id, |
269 base::FilePath* path) { | 269 base::FilePath* path) { |
270 return wallpaper_manager_->GetPathFromCache(user_id, path); | 270 return wallpaper_manager_->GetPathFromCache(account_id, path); |
271 } | 271 } |
272 | 272 |
273 void WallpaperManagerBase::TestApi::SetWallpaperCache( | 273 void WallpaperManagerBase::TestApi::SetWallpaperCache( |
274 const std::string& user_id, | 274 const AccountId& account_id, |
275 const base::FilePath& path, | 275 const base::FilePath& path, |
276 const gfx::ImageSkia& image) { | 276 const gfx::ImageSkia& image) { |
277 DCHECK(!image.isNull()); | 277 DCHECK(!image.isNull()); |
278 wallpaper_manager_->wallpaper_cache_[user_id] = | 278 wallpaper_manager_->wallpaper_cache_[account_id] = |
279 CustomWallpaperElement(path, image); | 279 CustomWallpaperElement(path, image); |
280 } | 280 } |
281 | 281 |
282 void WallpaperManagerBase::TestApi::ClearDisposableWallpaperCache() { | 282 void WallpaperManagerBase::TestApi::ClearDisposableWallpaperCache() { |
283 wallpaper_manager_->ClearDisposableWallpaperCache(); | 283 wallpaper_manager_->ClearDisposableWallpaperCache(); |
284 } | 284 } |
285 | 285 |
286 // static | 286 // static |
287 void WallpaperManagerBase::SetPathIds( | 287 void WallpaperManagerBase::SetPathIds( |
288 int dir_user_data_enum, | 288 int dir_user_data_enum, |
(...skipping 23 matching lines...) Expand all Loading... |
312 | 312 |
313 void WallpaperManagerBase::EnsureLoggedInUserWallpaperLoaded() { | 313 void WallpaperManagerBase::EnsureLoggedInUserWallpaperLoaded() { |
314 WallpaperInfo info; | 314 WallpaperInfo info; |
315 if (GetLoggedInUserWallpaperInfo(&info)) { | 315 if (GetLoggedInUserWallpaperInfo(&info)) { |
316 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", info.type, | 316 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", info.type, |
317 user_manager::User::WALLPAPER_TYPE_COUNT); | 317 user_manager::User::WALLPAPER_TYPE_COUNT); |
318 if (info == current_user_wallpaper_info_) | 318 if (info == current_user_wallpaper_info_) |
319 return; | 319 return; |
320 } | 320 } |
321 SetUserWallpaperNow( | 321 SetUserWallpaperNow( |
322 user_manager::UserManager::Get()->GetLoggedInUser()->email()); | 322 user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId()); |
323 } | 323 } |
324 | 324 |
325 void WallpaperManagerBase::ClearDisposableWallpaperCache() { | 325 void WallpaperManagerBase::ClearDisposableWallpaperCache() { |
326 // Cancel callback for previous cache requests. | 326 // Cancel callback for previous cache requests. |
327 weak_factory_.InvalidateWeakPtrs(); | 327 weak_factory_.InvalidateWeakPtrs(); |
328 // Keep the wallpaper of logged in users in cache at multi-profile mode. | 328 // Keep the wallpaper of logged in users in cache at multi-profile mode. |
329 std::set<std::string> logged_in_users_names; | 329 std::set<AccountId> logged_in_user_account_ids; |
330 const user_manager::UserList& logged_users = | 330 const user_manager::UserList& logged_users = |
331 user_manager::UserManager::Get()->GetLoggedInUsers(); | 331 user_manager::UserManager::Get()->GetLoggedInUsers(); |
332 for (user_manager::UserList::const_iterator it = logged_users.begin(); | 332 for (user_manager::UserList::const_iterator it = logged_users.begin(); |
333 it != logged_users.end(); ++it) { | 333 it != logged_users.end(); ++it) { |
334 logged_in_users_names.insert((*it)->email()); | 334 logged_in_user_account_ids.insert((*it)->GetAccountId()); |
335 } | 335 } |
336 | 336 |
337 CustomWallpaperMap logged_in_users_cache; | 337 CustomWallpaperMap logged_in_users_cache; |
338 for (CustomWallpaperMap::iterator it = wallpaper_cache_.begin(); | 338 for (CustomWallpaperMap::iterator it = wallpaper_cache_.begin(); |
339 it != wallpaper_cache_.end(); ++it) { | 339 it != wallpaper_cache_.end(); ++it) { |
340 if (logged_in_users_names.find(it->first) != logged_in_users_names.end()) { | 340 if (logged_in_user_account_ids.find(it->first) != |
| 341 logged_in_user_account_ids.end()) { |
341 logged_in_users_cache.insert(*it); | 342 logged_in_users_cache.insert(*it); |
342 } | 343 } |
343 } | 344 } |
344 wallpaper_cache_ = logged_in_users_cache; | 345 wallpaper_cache_ = logged_in_users_cache; |
345 } | 346 } |
346 | 347 |
347 bool WallpaperManagerBase::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { | 348 bool WallpaperManagerBase::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { |
348 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 349 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
349 | 350 |
350 if (user_manager::UserManager::Get()->IsLoggedInAsStub()) { | 351 if (user_manager::UserManager::Get()->IsLoggedInAsStub()) { |
351 info->location = current_user_wallpaper_info_.location = ""; | 352 info->location = current_user_wallpaper_info_.location = ""; |
352 info->layout = current_user_wallpaper_info_.layout = | 353 info->layout = current_user_wallpaper_info_.layout = |
353 WALLPAPER_LAYOUT_CENTER_CROPPED; | 354 WALLPAPER_LAYOUT_CENTER_CROPPED; |
354 info->type = current_user_wallpaper_info_.type = | 355 info->type = current_user_wallpaper_info_.type = |
355 user_manager::User::DEFAULT; | 356 user_manager::User::DEFAULT; |
356 info->date = current_user_wallpaper_info_.date = | 357 info->date = current_user_wallpaper_info_.date = |
357 base::Time::Now().LocalMidnight(); | 358 base::Time::Now().LocalMidnight(); |
358 return true; | 359 return true; |
359 } | 360 } |
360 | 361 |
361 return GetUserWallpaperInfo( | 362 return GetUserWallpaperInfo( |
362 user_manager::UserManager::Get()->GetLoggedInUser()->email(), info); | 363 user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId(), |
| 364 info); |
363 } | 365 } |
364 | 366 |
365 // static | 367 // static |
366 bool WallpaperManagerBase::ResizeImage( | 368 bool WallpaperManagerBase::ResizeImage( |
367 const gfx::ImageSkia& image, | 369 const gfx::ImageSkia& image, |
368 WallpaperLayout layout, | 370 WallpaperLayout layout, |
369 int preferred_width, | 371 int preferred_width, |
370 int preferred_height, | 372 int preferred_height, |
371 scoped_refptr<base::RefCountedBytes>* output, | 373 scoped_refptr<base::RefCountedBytes>* output, |
372 gfx::ImageSkia* output_skia) { | 374 gfx::ImageSkia* output_skia) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 scoped_refptr<base::RefCountedBytes> data; | 439 scoped_refptr<base::RefCountedBytes> data; |
438 if (ResizeImage(image, layout, preferred_width, preferred_height, &data, | 440 if (ResizeImage(image, layout, preferred_width, preferred_height, &data, |
439 output_skia)) { | 441 output_skia)) { |
440 return SaveWallpaperInternal( | 442 return SaveWallpaperInternal( |
441 path, reinterpret_cast<const char*>(data->front()), data->size()); | 443 path, reinterpret_cast<const char*>(data->front()), data->size()); |
442 } | 444 } |
443 return false; | 445 return false; |
444 } | 446 } |
445 | 447 |
446 bool WallpaperManagerBase::IsPolicyControlled( | 448 bool WallpaperManagerBase::IsPolicyControlled( |
447 const std::string& user_id) const { | 449 const AccountId& account_id) const { |
448 WallpaperInfo info; | 450 WallpaperInfo info; |
449 if (!GetUserWallpaperInfo(user_id, &info)) | 451 if (!GetUserWallpaperInfo(account_id, &info)) |
450 return false; | 452 return false; |
451 return info.type == user_manager::User::POLICY; | 453 return info.type == user_manager::User::POLICY; |
452 } | 454 } |
453 | 455 |
454 void WallpaperManagerBase::OnPolicySet(const std::string& policy, | 456 void WallpaperManagerBase::OnPolicySet(const std::string& policy, |
455 const std::string& user_id) { | 457 const AccountId& account_id) { |
456 WallpaperInfo info; | 458 WallpaperInfo info; |
457 GetUserWallpaperInfo(user_id, &info); | 459 GetUserWallpaperInfo(account_id, &info); |
458 info.type = user_manager::User::POLICY; | 460 info.type = user_manager::User::POLICY; |
459 SetUserWallpaperInfo(user_id, info, true /* is_persistent */); | 461 SetUserWallpaperInfo(account_id, info, true /* is_persistent */); |
460 } | 462 } |
461 | 463 |
462 void WallpaperManagerBase::OnPolicyCleared(const std::string& policy, | 464 void WallpaperManagerBase::OnPolicyCleared(const std::string& policy, |
463 const std::string& user_id) { | 465 const AccountId& account_id) { |
464 WallpaperInfo info; | 466 WallpaperInfo info; |
465 GetUserWallpaperInfo(user_id, &info); | 467 GetUserWallpaperInfo(account_id, &info); |
466 info.type = user_manager::User::DEFAULT; | 468 info.type = user_manager::User::DEFAULT; |
467 SetUserWallpaperInfo(user_id, info, true /* is_persistent */); | 469 SetUserWallpaperInfo(account_id, info, true /* is_persistent */); |
468 SetDefaultWallpaperNow(user_id); | 470 SetDefaultWallpaperNow(account_id); |
469 } | 471 } |
470 | 472 |
471 // static | 473 // static |
472 base::FilePath WallpaperManagerBase::GetCustomWallpaperPath( | 474 base::FilePath WallpaperManagerBase::GetCustomWallpaperPath( |
473 const char* sub_dir, | 475 const char* sub_dir, |
474 const std::string& user_id_hash, | 476 const std::string& user_id_hash, |
475 const std::string& file) { | 477 const std::string& file) { |
476 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); | 478 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); |
477 return custom_wallpaper_path.Append(user_id_hash).Append(file); | 479 return custom_wallpaper_path.Append(user_id_hash).Append(file); |
478 } | 480 } |
(...skipping 13 matching lines...) Expand all Loading... |
492 sequence_token_, base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 494 sequence_token_, base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
493 } | 495 } |
494 | 496 |
495 WallpaperManagerBase::~WallpaperManagerBase() { | 497 WallpaperManagerBase::~WallpaperManagerBase() { |
496 // TODO(bshe): Lifetime of WallpaperManagerBase needs more consideration. | 498 // TODO(bshe): Lifetime of WallpaperManagerBase needs more consideration. |
497 // http://crbug.com/171694 | 499 // http://crbug.com/171694 |
498 weak_factory_.InvalidateWeakPtrs(); | 500 weak_factory_.InvalidateWeakPtrs(); |
499 } | 501 } |
500 | 502 |
501 void WallpaperManagerBase::SetPolicyControlledWallpaper( | 503 void WallpaperManagerBase::SetPolicyControlledWallpaper( |
502 const std::string& user_id, | 504 const AccountId& account_id, |
503 const user_manager::UserImage& user_image) { | 505 const user_manager::UserImage& user_image) { |
504 const user_manager::User* user = user_manager::UserManager::Get()->FindUser( | 506 const user_manager::User* user = |
505 AccountId::FromUserEmail(user_id)); | 507 user_manager::UserManager::Get()->FindUser(account_id); |
506 if (!user) { | 508 if (!user) { |
507 NOTREACHED() << "Unknown user."; | 509 NOTREACHED() << "Unknown user."; |
508 return; | 510 return; |
509 } | 511 } |
510 | 512 |
511 if (user->username_hash().empty()) { | 513 if (user->username_hash().empty()) { |
512 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | 514 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
513 user_id, | 515 account_id.GetUserEmail(), |
514 base::Bind(&WallpaperManagerBase::SetCustomWallpaperOnSanitizedUsername, | 516 base::Bind(&WallpaperManagerBase::SetCustomWallpaperOnSanitizedUsername, |
515 weak_factory_.GetWeakPtr(), user_id, user_image.image(), | 517 weak_factory_.GetWeakPtr(), account_id, user_image.image(), |
516 true /* update wallpaper */)); | 518 true /* update wallpaper */)); |
517 } else { | 519 } else { |
518 SetCustomWallpaper(user_id, user->username_hash(), "policy-controlled.jpeg", | 520 SetCustomWallpaper( |
519 WALLPAPER_LAYOUT_CENTER_CROPPED, | 521 account_id, user->username_hash(), "policy-controlled.jpeg", |
520 user_manager::User::POLICY, user_image.image(), | 522 WALLPAPER_LAYOUT_CENTER_CROPPED, user_manager::User::POLICY, |
521 true /* update wallpaper */); | 523 user_image.image(), true /* update wallpaper */); |
522 } | 524 } |
523 } | 525 } |
524 | 526 |
525 void WallpaperManagerBase::SetCustomWallpaperOnSanitizedUsername( | 527 void WallpaperManagerBase::SetCustomWallpaperOnSanitizedUsername( |
526 const std::string& user_id, | 528 const AccountId& account_id, |
527 const gfx::ImageSkia& image, | 529 const gfx::ImageSkia& image, |
528 bool update_wallpaper, | 530 bool update_wallpaper, |
529 bool cryptohome_success, | 531 bool cryptohome_success, |
530 const std::string& user_id_hash) { | 532 const std::string& user_id_hash) { |
531 if (!cryptohome_success) | 533 if (!cryptohome_success) |
532 return; | 534 return; |
533 SetCustomWallpaper(user_id, user_id_hash, "policy-controlled.jpeg", | 535 SetCustomWallpaper(account_id, user_id_hash, "policy-controlled.jpeg", |
534 WALLPAPER_LAYOUT_CENTER_CROPPED, | 536 WALLPAPER_LAYOUT_CENTER_CROPPED, |
535 user_manager::User::POLICY, image, update_wallpaper); | 537 user_manager::User::POLICY, image, update_wallpaper); |
536 } | 538 } |
537 | 539 |
538 // static | 540 // static |
539 void WallpaperManagerBase::SaveCustomWallpaper( | 541 void WallpaperManagerBase::SaveCustomWallpaper( |
540 const std::string& user_id_hash, | 542 const std::string& user_id_hash, |
541 const base::FilePath& original_path, | 543 const base::FilePath& original_path, |
542 WallpaperLayout layout, | 544 WallpaperLayout layout, |
543 scoped_ptr<gfx::ImageSkia> image) { | 545 scoped_ptr<gfx::ImageSkia> image) { |
(...skipping 21 matching lines...) Expand all Loading... |
565 ResizeAndSaveWallpaper(*image, small_wallpaper_path, layout, | 567 ResizeAndSaveWallpaper(*image, small_wallpaper_path, layout, |
566 kSmallWallpaperMaxWidth, kSmallWallpaperMaxHeight, | 568 kSmallWallpaperMaxWidth, kSmallWallpaperMaxHeight, |
567 NULL); | 569 NULL); |
568 ResizeAndSaveWallpaper(*image, large_wallpaper_path, layout, | 570 ResizeAndSaveWallpaper(*image, large_wallpaper_path, layout, |
569 kLargeWallpaperMaxWidth, kLargeWallpaperMaxHeight, | 571 kLargeWallpaperMaxWidth, kLargeWallpaperMaxHeight, |
570 NULL); | 572 NULL); |
571 } | 573 } |
572 | 574 |
573 // static | 575 // static |
574 void WallpaperManagerBase::MoveCustomWallpapersOnWorker( | 576 void WallpaperManagerBase::MoveCustomWallpapersOnWorker( |
575 const std::string& user_id, | 577 const AccountId& account_id, |
576 const std::string& user_id_hash, | 578 const std::string& user_id_hash, |
577 base::WeakPtr<WallpaperManagerBase> weak_ptr) { | 579 base::WeakPtr<WallpaperManagerBase> weak_ptr) { |
578 if (MoveCustomWallpaperDirectory(kOriginalWallpaperSubDir, user_id, | 580 if (MoveCustomWallpaperDirectory(kOriginalWallpaperSubDir, |
579 user_id_hash)) { | 581 account_id.GetUserEmail(), user_id_hash)) { |
580 // Consider success if the original wallpaper is moved to the new directory. | 582 // Consider success if the original wallpaper is moved to the new directory. |
581 // Original wallpaper is the fallback if the correct resolution wallpaper | 583 // Original wallpaper is the fallback if the correct resolution wallpaper |
582 // can not be found. | 584 // can not be found. |
583 BrowserThread::PostTask( | 585 BrowserThread::PostTask( |
584 BrowserThread::UI, FROM_HERE, | 586 BrowserThread::UI, FROM_HERE, |
585 base::Bind(&WallpaperManagerBase::MoveCustomWallpapersSuccess, weak_ptr, | 587 base::Bind(&WallpaperManagerBase::MoveCustomWallpapersSuccess, weak_ptr, |
586 user_id, user_id_hash)); | 588 account_id, user_id_hash)); |
587 } | 589 } |
588 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash); | 590 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, account_id.GetUserEmail(), |
589 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash); | |
590 MoveCustomWallpaperDirectory(kThumbnailWallpaperSubDir, user_id, | |
591 user_id_hash); | 591 user_id_hash); |
| 592 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, account_id.GetUserEmail(), |
| 593 user_id_hash); |
| 594 MoveCustomWallpaperDirectory(kThumbnailWallpaperSubDir, |
| 595 account_id.GetUserEmail(), user_id_hash); |
592 } | 596 } |
593 | 597 |
594 // static | 598 // static |
595 void WallpaperManagerBase::GetCustomWallpaperInternal( | 599 void WallpaperManagerBase::GetCustomWallpaperInternal( |
596 const std::string& user_id, | 600 const AccountId& account_id, |
597 const WallpaperInfo& info, | 601 const WallpaperInfo& info, |
598 const base::FilePath& wallpaper_path, | 602 const base::FilePath& wallpaper_path, |
599 bool update_wallpaper, | 603 bool update_wallpaper, |
600 MovableOnDestroyCallbackHolder on_finish, | 604 MovableOnDestroyCallbackHolder on_finish, |
601 base::WeakPtr<WallpaperManagerBase> weak_ptr) { | 605 base::WeakPtr<WallpaperManagerBase> weak_ptr) { |
602 base::FilePath valid_path = wallpaper_path; | 606 base::FilePath valid_path = wallpaper_path; |
603 if (!base::PathExists(wallpaper_path)) { | 607 if (!base::PathExists(wallpaper_path)) { |
604 // Falls back on original file if the correct resolution file does not | 608 // Falls back on original file if the correct resolution file does not |
605 // exist. This may happen when the original custom wallpaper is small or | 609 // exist. This may happen when the original custom wallpaper is small or |
606 // browser shutdown before resized wallpaper saved. | 610 // browser shutdown before resized wallpaper saved. |
607 valid_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); | 611 valid_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); |
608 valid_path = valid_path.Append(info.location); | 612 valid_path = valid_path.Append(info.location); |
609 } | 613 } |
610 | 614 |
611 if (!base::PathExists(valid_path)) { | 615 if (!base::PathExists(valid_path)) { |
612 // Falls back to custom wallpaper that uses email as part of its file path. | 616 // Falls back to custom wallpaper that uses AccountId as part of its file |
613 // Note that email is used instead of user_id_hash here. | 617 // path. |
| 618 // Note that account id is used instead of user_id_hash here. |
614 LOG(ERROR) << "Failed to load custom wallpaper from its original fallback " | 619 LOG(ERROR) << "Failed to load custom wallpaper from its original fallback " |
615 "file path: " << valid_path.value(); | 620 "file path: " << valid_path.value(); |
616 valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, | 621 valid_path = GetCustomWallpaperPath( |
617 info.location); | 622 kOriginalWallpaperSubDir, account_id.GetUserEmail(), info.location); |
618 } | 623 } |
619 | 624 |
620 if (!base::PathExists(valid_path)) { | 625 if (!base::PathExists(valid_path)) { |
621 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " | 626 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " |
622 << "Fallback to default wallpaper. Expected wallpaper path: " | 627 << "Fallback to default wallpaper. Expected wallpaper path: " |
623 << wallpaper_path.value(); | 628 << wallpaper_path.value(); |
624 BrowserThread::PostTask( | 629 BrowserThread::PostTask( |
625 BrowserThread::UI, FROM_HERE, | 630 BrowserThread::UI, FROM_HERE, |
626 base::Bind(&WallpaperManagerBase::DoSetDefaultWallpaper, weak_ptr, | 631 base::Bind(&WallpaperManagerBase::DoSetDefaultWallpaper, weak_ptr, |
627 user_id, base::Passed(on_finish.Pass()))); | 632 account_id, base::Passed(on_finish.Pass()))); |
628 } else { | 633 } else { |
629 BrowserThread::PostTask( | 634 BrowserThread::PostTask( |
630 BrowserThread::UI, FROM_HERE, | 635 BrowserThread::UI, FROM_HERE, |
631 base::Bind(&WallpaperManagerBase::StartLoad, weak_ptr, user_id, info, | 636 base::Bind(&WallpaperManagerBase::StartLoad, weak_ptr, account_id, info, |
632 update_wallpaper, valid_path, | 637 update_wallpaper, valid_path, |
633 base::Passed(on_finish.Pass()))); | 638 base::Passed(on_finish.Pass()))); |
634 } | 639 } |
635 } | 640 } |
636 | 641 |
637 void WallpaperManagerBase::InitInitialUserWallpaper(const std::string& user_id, | 642 void WallpaperManagerBase::InitInitialUserWallpaper(const AccountId& account_id, |
638 bool is_persistent) { | 643 bool is_persistent) { |
639 current_user_wallpaper_info_.location = ""; | 644 current_user_wallpaper_info_.location = ""; |
640 current_user_wallpaper_info_.layout = WALLPAPER_LAYOUT_CENTER_CROPPED; | 645 current_user_wallpaper_info_.layout = WALLPAPER_LAYOUT_CENTER_CROPPED; |
641 current_user_wallpaper_info_.type = user_manager::User::DEFAULT; | 646 current_user_wallpaper_info_.type = user_manager::User::DEFAULT; |
642 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); | 647 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); |
643 | 648 |
644 WallpaperInfo info = current_user_wallpaper_info_; | 649 WallpaperInfo info = current_user_wallpaper_info_; |
645 SetUserWallpaperInfo(user_id, info, is_persistent); | 650 SetUserWallpaperInfo(account_id, info, is_persistent); |
646 } | 651 } |
647 | 652 |
648 void WallpaperManagerBase::SetUserWallpaperDelayed(const std::string& user_id) { | 653 void WallpaperManagerBase::SetUserWallpaperDelayed( |
649 ScheduleSetUserWallpaper(user_id, true); | 654 const AccountId& account_id) { |
| 655 ScheduleSetUserWallpaper(account_id, true); |
650 } | 656 } |
651 | 657 |
652 void WallpaperManagerBase::SetUserWallpaperNow(const std::string& user_id) { | 658 void WallpaperManagerBase::SetUserWallpaperNow(const AccountId& account_id) { |
653 ScheduleSetUserWallpaper(user_id, false); | 659 ScheduleSetUserWallpaper(account_id, false); |
654 } | 660 } |
655 | 661 |
656 void WallpaperManagerBase::UpdateWallpaper(bool clear_cache) { | 662 void WallpaperManagerBase::UpdateWallpaper(bool clear_cache) { |
657 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateWallpaperForTesting()); | 663 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateWallpaperForTesting()); |
658 if (clear_cache) | 664 if (clear_cache) |
659 wallpaper_cache_.clear(); | 665 wallpaper_cache_.clear(); |
660 // For GAIA login flow, the last_selected_user_ may not be set before user | 666 // For GAIA login flow, the last_selected_user_ may not be set before user |
661 // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will | 667 // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will |
662 // be set. It could result a black screen on external monitors. | 668 // be set. It could result a black screen on external monitors. |
663 // See http://crbug.com/265689 for detail. | 669 // See http://crbug.com/265689 for detail. |
664 if (last_selected_user_.empty()) { | 670 if (last_selected_user_.empty()) { |
665 SetDefaultWallpaperNow(chromeos::login::SignInAccountId().GetUserEmail()); | 671 SetDefaultWallpaperNow(chromeos::login::SignInAccountId()); |
666 return; | 672 return; |
667 } | 673 } |
668 SetUserWallpaperNow(last_selected_user_); | 674 SetUserWallpaperNow(last_selected_user_); |
669 } | 675 } |
670 | 676 |
671 void WallpaperManagerBase::AddObserver( | 677 void WallpaperManagerBase::AddObserver( |
672 WallpaperManagerBase::Observer* observer) { | 678 WallpaperManagerBase::Observer* observer) { |
673 observers_.AddObserver(observer); | 679 observers_.AddObserver(observer); |
674 } | 680 } |
675 | 681 |
676 void WallpaperManagerBase::RemoveObserver( | 682 void WallpaperManagerBase::RemoveObserver( |
677 WallpaperManagerBase::Observer* observer) { | 683 WallpaperManagerBase::Observer* observer) { |
678 observers_.RemoveObserver(observer); | 684 observers_.RemoveObserver(observer); |
679 } | 685 } |
680 | 686 |
681 void WallpaperManagerBase::NotifyAnimationFinished() { | 687 void WallpaperManagerBase::NotifyAnimationFinished() { |
682 FOR_EACH_OBSERVER(Observer, observers_, | 688 FOR_EACH_OBSERVER(Observer, observers_, |
683 OnWallpaperAnimationFinished(last_selected_user_)); | 689 OnWallpaperAnimationFinished(last_selected_user_)); |
684 } | 690 } |
685 | 691 |
686 // WallpaperManager, protected: ----------------------------------------------- | 692 // WallpaperManager, protected: ----------------------------------------------- |
687 | 693 |
688 bool WallpaperManagerBase::GetWallpaperFromCache(const std::string& user_id, | 694 bool WallpaperManagerBase::GetWallpaperFromCache(const AccountId& account_id, |
689 gfx::ImageSkia* image) { | 695 gfx::ImageSkia* image) { |
690 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 696 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
691 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(user_id); | 697 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(account_id); |
692 if (it != wallpaper_cache_.end() && !(*it).second.second.isNull()) { | 698 if (it != wallpaper_cache_.end() && !(*it).second.second.isNull()) { |
693 *image = (*it).second.second; | 699 *image = (*it).second.second; |
694 return true; | 700 return true; |
695 } | 701 } |
696 return false; | 702 return false; |
697 } | 703 } |
698 | 704 |
699 bool WallpaperManagerBase::GetPathFromCache(const std::string& user_id, | 705 bool WallpaperManagerBase::GetPathFromCache(const AccountId& account_id, |
700 base::FilePath* path) { | 706 base::FilePath* path) { |
701 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 707 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
702 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(user_id); | 708 CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(account_id); |
703 if (it != wallpaper_cache_.end()) { | 709 if (it != wallpaper_cache_.end()) { |
704 *path = (*it).second.first; | 710 *path = (*it).second.first; |
705 return true; | 711 return true; |
706 } | 712 } |
707 return false; | 713 return false; |
708 } | 714 } |
709 | 715 |
710 int WallpaperManagerBase::loaded_wallpapers_for_test() const { | 716 int WallpaperManagerBase::loaded_wallpapers_for_test() const { |
711 return loaded_wallpapers_for_test_; | 717 return loaded_wallpapers_for_test_; |
712 } | 718 } |
713 | 719 |
714 void WallpaperManagerBase::CacheUsersWallpapers() { | 720 void WallpaperManagerBase::CacheUsersWallpapers() { |
715 // TODO(dpolukhin): crbug.com/408734. | 721 // TODO(dpolukhin): crbug.com/408734. |
716 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 722 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
717 user_manager::UserList users = user_manager::UserManager::Get()->GetUsers(); | 723 user_manager::UserList users = user_manager::UserManager::Get()->GetUsers(); |
718 | 724 |
719 if (!users.empty()) { | 725 if (!users.empty()) { |
720 user_manager::UserList::const_iterator it = users.begin(); | 726 user_manager::UserList::const_iterator it = users.begin(); |
721 // Skip the wallpaper of first user in the list. It should have been cached. | 727 // Skip the wallpaper of first user in the list. It should have been cached. |
722 it++; | 728 it++; |
723 for (int cached = 0; it != users.end() && cached < kMaxWallpapersToCache; | 729 for (int cached = 0; it != users.end() && cached < kMaxWallpapersToCache; |
724 ++it, ++cached) { | 730 ++it, ++cached) { |
725 std::string user_id = (*it)->email(); | 731 CacheUserWallpaper((*it)->GetAccountId()); |
726 CacheUserWallpaper(user_id); | |
727 } | 732 } |
728 } | 733 } |
729 } | 734 } |
730 | 735 |
731 void WallpaperManagerBase::CacheUserWallpaper(const std::string& user_id) { | 736 void WallpaperManagerBase::CacheUserWallpaper(const AccountId& account_id) { |
732 CustomWallpaperMap::iterator it = wallpaper_cache_.find(user_id); | 737 CustomWallpaperMap::iterator it = wallpaper_cache_.find(account_id); |
733 if (it != wallpaper_cache_.end() && !it->second.second.isNull()) | 738 if (it != wallpaper_cache_.end() && !it->second.second.isNull()) |
734 return; | 739 return; |
735 WallpaperInfo info; | 740 WallpaperInfo info; |
736 if (GetUserWallpaperInfo(user_id, &info)) { | 741 if (GetUserWallpaperInfo(account_id, &info)) { |
737 if (info.location.empty()) | 742 if (info.location.empty()) |
738 return; | 743 return; |
739 | 744 |
740 base::FilePath wallpaper_dir; | 745 base::FilePath wallpaper_dir; |
741 base::FilePath wallpaper_path; | 746 base::FilePath wallpaper_path; |
742 if (info.type == user_manager::User::CUSTOMIZED || | 747 if (info.type == user_manager::User::CUSTOMIZED || |
743 info.type == user_manager::User::POLICY) { | 748 info.type == user_manager::User::POLICY) { |
744 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); | 749 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
745 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 750 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
746 wallpaper_path = wallpaper_path.Append(info.location); | 751 wallpaper_path = wallpaper_path.Append(info.location); |
747 // Set the path to the cache. | 752 // Set the path to the cache. |
748 wallpaper_cache_[user_id] = CustomWallpaperElement(wallpaper_path, | 753 wallpaper_cache_[account_id] = |
749 gfx::ImageSkia()); | 754 CustomWallpaperElement(wallpaper_path, gfx::ImageSkia()); |
750 task_runner_->PostTask( | 755 task_runner_->PostTask( |
751 FROM_HERE, | 756 FROM_HERE, |
752 base::Bind(&WallpaperManagerBase::GetCustomWallpaperInternal, user_id, | 757 base::Bind(&WallpaperManagerBase::GetCustomWallpaperInternal, |
753 info, wallpaper_path, false /* do not update wallpaper */, | 758 account_id, info, wallpaper_path, |
| 759 false /* do not update wallpaper */, |
754 base::Passed(MovableOnDestroyCallbackHolder()), | 760 base::Passed(MovableOnDestroyCallbackHolder()), |
755 weak_factory_.GetWeakPtr())); | 761 weak_factory_.GetWeakPtr())); |
756 return; | 762 return; |
757 } | 763 } |
758 LoadWallpaper(user_id, info, false /* do not update wallpaper */, | 764 LoadWallpaper(account_id, info, false /* do not update wallpaper */, |
759 MovableOnDestroyCallbackHolder().Pass()); | 765 MovableOnDestroyCallbackHolder().Pass()); |
760 } | 766 } |
761 } | 767 } |
762 | 768 |
763 void WallpaperManagerBase::DeleteUserWallpapers( | 769 void WallpaperManagerBase::DeleteUserWallpapers( |
764 const std::string& user_id, | 770 const AccountId& account_id, |
765 const std::string& path_to_file) { | 771 const std::string& path_to_file) { |
766 std::vector<base::FilePath> file_to_remove; | 772 std::vector<base::FilePath> file_to_remove; |
767 // Remove small user wallpaper. | 773 // Remove small user wallpaper. |
768 base::FilePath wallpaper_path = GetCustomWallpaperDir(kSmallWallpaperSubDir); | 774 base::FilePath wallpaper_path = GetCustomWallpaperDir(kSmallWallpaperSubDir); |
769 // Remove old directory if exists | 775 // Remove old directory if exists |
770 file_to_remove.push_back(wallpaper_path.Append(user_id)); | 776 file_to_remove.push_back(wallpaper_path.Append(account_id.GetUserEmail())); |
771 wallpaper_path = wallpaper_path.Append(path_to_file).DirName(); | 777 wallpaper_path = wallpaper_path.Append(path_to_file).DirName(); |
772 file_to_remove.push_back(wallpaper_path); | 778 file_to_remove.push_back(wallpaper_path); |
773 | 779 |
774 // Remove large user wallpaper. | 780 // Remove large user wallpaper. |
775 wallpaper_path = GetCustomWallpaperDir(kLargeWallpaperSubDir); | 781 wallpaper_path = GetCustomWallpaperDir(kLargeWallpaperSubDir); |
776 file_to_remove.push_back(wallpaper_path.Append(user_id)); | 782 file_to_remove.push_back(wallpaper_path.Append(account_id.GetUserEmail())); |
777 wallpaper_path = wallpaper_path.Append(path_to_file); | 783 wallpaper_path = wallpaper_path.Append(path_to_file); |
778 file_to_remove.push_back(wallpaper_path); | 784 file_to_remove.push_back(wallpaper_path); |
779 | 785 |
780 // Remove user wallpaper thumbnail. | 786 // Remove user wallpaper thumbnail. |
781 wallpaper_path = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); | 787 wallpaper_path = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); |
782 file_to_remove.push_back(wallpaper_path.Append(user_id)); | 788 file_to_remove.push_back(wallpaper_path.Append(account_id.GetUserEmail())); |
783 wallpaper_path = wallpaper_path.Append(path_to_file); | 789 wallpaper_path = wallpaper_path.Append(path_to_file); |
784 file_to_remove.push_back(wallpaper_path); | 790 file_to_remove.push_back(wallpaper_path); |
785 | 791 |
786 // Remove original user wallpaper. | 792 // Remove original user wallpaper. |
787 wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); | 793 wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir); |
788 file_to_remove.push_back(wallpaper_path.Append(user_id)); | 794 file_to_remove.push_back(wallpaper_path.Append(account_id.GetUserEmail())); |
789 wallpaper_path = wallpaper_path.Append(path_to_file); | 795 wallpaper_path = wallpaper_path.Append(path_to_file); |
790 file_to_remove.push_back(wallpaper_path); | 796 file_to_remove.push_back(wallpaper_path); |
791 | 797 |
792 base::WorkerPool::PostTask( | 798 base::WorkerPool::PostTask( |
793 FROM_HERE, base::Bind(&DeleteWallpaperInList, file_to_remove), false); | 799 FROM_HERE, base::Bind(&DeleteWallpaperInList, file_to_remove), false); |
794 } | 800 } |
795 | 801 |
796 void WallpaperManagerBase::SetCommandLineForTesting( | 802 void WallpaperManagerBase::SetCommandLineForTesting( |
797 base::CommandLine* command_line) { | 803 base::CommandLine* command_line) { |
798 command_line_for_testing_ = command_line; | 804 command_line_for_testing_ = command_line; |
799 SetDefaultWallpaperPathsFromCommandLine(command_line); | 805 SetDefaultWallpaperPathsFromCommandLine(command_line); |
800 } | 806 } |
801 | 807 |
802 base::CommandLine* WallpaperManagerBase::GetCommandLine() { | 808 base::CommandLine* WallpaperManagerBase::GetCommandLine() { |
803 base::CommandLine* command_line = | 809 base::CommandLine* command_line = |
804 command_line_for_testing_ ? command_line_for_testing_ | 810 command_line_for_testing_ ? command_line_for_testing_ |
805 : base::CommandLine::ForCurrentProcess(); | 811 : base::CommandLine::ForCurrentProcess(); |
806 return command_line; | 812 return command_line; |
807 } | 813 } |
808 | 814 |
809 void WallpaperManagerBase::LoadWallpaper( | 815 void WallpaperManagerBase::LoadWallpaper( |
810 const std::string& user_id, | 816 const AccountId& account_id, |
811 const WallpaperInfo& info, | 817 const WallpaperInfo& info, |
812 bool update_wallpaper, | 818 bool update_wallpaper, |
813 MovableOnDestroyCallbackHolder on_finish) { | 819 MovableOnDestroyCallbackHolder on_finish) { |
814 base::FilePath wallpaper_dir; | 820 base::FilePath wallpaper_dir; |
815 base::FilePath wallpaper_path; | 821 base::FilePath wallpaper_path; |
816 | 822 |
817 // Do a sanity check that file path information is not empty. | 823 // Do a sanity check that file path information is not empty. |
818 if (info.type == user_manager::User::ONLINE || | 824 if (info.type == user_manager::User::ONLINE || |
819 info.type == user_manager::User::DEFAULT) { | 825 info.type == user_manager::User::DEFAULT) { |
820 if (info.location.empty()) { | 826 if (info.location.empty()) { |
821 if (base::SysInfo::IsRunningOnChromeOS()) { | 827 if (base::SysInfo::IsRunningOnChromeOS()) { |
822 NOTREACHED() << "User wallpaper info appears to be broken: " << user_id; | 828 NOTREACHED() << "User wallpaper info appears to be broken: " |
| 829 << account_id.Serialize(); |
823 } else { | 830 } else { |
824 // Filename might be empty on debug configurations when stub users | 831 // Filename might be empty on debug configurations when stub users |
825 // were created directly in Local State (for testing). Ignore such | 832 // were created directly in Local State (for testing). Ignore such |
826 // errors i.e. allowsuch type of debug configurations on the desktop. | 833 // errors i.e. allowsuch type of debug configurations on the desktop. |
827 LOG(WARNING) << "User wallpaper info is empty: " << user_id; | 834 LOG(WARNING) << "User wallpaper info is empty: " |
| 835 << account_id.Serialize(); |
828 | 836 |
829 // |on_finish| callback will get called on destruction. | 837 // |on_finish| callback will get called on destruction. |
830 return; | 838 return; |
831 } | 839 } |
832 } | 840 } |
833 } | 841 } |
834 | 842 |
835 if (info.type == user_manager::User::ONLINE) { | 843 if (info.type == user_manager::User::ONLINE) { |
836 std::string file_name = GURL(info.location).ExtractFileName(); | 844 std::string file_name = GURL(info.location).ExtractFileName(); |
837 WallpaperResolution resolution = GetAppropriateResolution(); | 845 WallpaperResolution resolution = GetAppropriateResolution(); |
838 // Only solid color wallpapers have stretch layout and they have only one | 846 // Only solid color wallpapers have stretch layout and they have only one |
839 // resolution. | 847 // resolution. |
840 if (info.layout != WALLPAPER_LAYOUT_STRETCH && | 848 if (info.layout != WALLPAPER_LAYOUT_STRETCH && |
841 resolution == WALLPAPER_RESOLUTION_SMALL) { | 849 resolution == WALLPAPER_RESOLUTION_SMALL) { |
842 file_name = base::FilePath(file_name) | 850 file_name = base::FilePath(file_name) |
843 .InsertBeforeExtension(kSmallWallpaperSuffix) | 851 .InsertBeforeExtension(kSmallWallpaperSuffix) |
844 .value(); | 852 .value(); |
845 } | 853 } |
846 DCHECK(dir_chromeos_wallpapers_path_id != -1); | 854 DCHECK(dir_chromeos_wallpapers_path_id != -1); |
847 CHECK(PathService::Get(dir_chromeos_wallpapers_path_id, | 855 CHECK(PathService::Get(dir_chromeos_wallpapers_path_id, |
848 &wallpaper_dir)); | 856 &wallpaper_dir)); |
849 wallpaper_path = wallpaper_dir.Append(file_name); | 857 wallpaper_path = wallpaper_dir.Append(file_name); |
850 | 858 |
851 // If the wallpaper exists and it contains already the correct image we can | 859 // If the wallpaper exists and it contains already the correct image we can |
852 // return immediately. | 860 // return immediately. |
853 CustomWallpaperMap::iterator it = wallpaper_cache_.find(user_id); | 861 CustomWallpaperMap::iterator it = wallpaper_cache_.find(account_id); |
854 if (it != wallpaper_cache_.end() && | 862 if (it != wallpaper_cache_.end() && |
855 it->second.first == wallpaper_path && | 863 it->second.first == wallpaper_path && |
856 !it->second.second.isNull()) | 864 !it->second.second.isNull()) |
857 return; | 865 return; |
858 | 866 |
859 loaded_wallpapers_for_test_++; | 867 loaded_wallpapers_for_test_++; |
860 StartLoad(user_id, info, update_wallpaper, wallpaper_path, | 868 StartLoad(account_id, info, update_wallpaper, wallpaper_path, |
861 on_finish.Pass()); | 869 on_finish.Pass()); |
862 } else if (info.type == user_manager::User::DEFAULT) { | 870 } else if (info.type == user_manager::User::DEFAULT) { |
863 // Default wallpapers are migrated from M21 user profiles. A code refactor | 871 // Default wallpapers are migrated from M21 user profiles. A code refactor |
864 // overlooked that case and caused these wallpapers not being loaded at all. | 872 // overlooked that case and caused these wallpapers not being loaded at all. |
865 // On some slow devices, it caused login webui not visible after upgrade to | 873 // On some slow devices, it caused login webui not visible after upgrade to |
866 // M26 from M21. See crosbug.com/38429 for details. | 874 // M26 from M21. See crosbug.com/38429 for details. |
867 base::FilePath user_data_dir; | 875 base::FilePath user_data_dir; |
868 DCHECK(dir_user_data_path_id != -1); | 876 DCHECK(dir_user_data_path_id != -1); |
869 PathService::Get(dir_user_data_path_id, &user_data_dir); | 877 PathService::Get(dir_user_data_path_id, &user_data_dir); |
870 wallpaper_path = user_data_dir.Append(info.location); | 878 wallpaper_path = user_data_dir.Append(info.location); |
871 StartLoad(user_id, info, update_wallpaper, wallpaper_path, | 879 StartLoad(account_id, info, update_wallpaper, wallpaper_path, |
872 on_finish.Pass()); | 880 on_finish.Pass()); |
873 } else { | 881 } else { |
874 // In unexpected cases, revert to default wallpaper to fail safely. See | 882 // In unexpected cases, revert to default wallpaper to fail safely. See |
875 // crosbug.com/38429. | 883 // crosbug.com/38429. |
876 LOG(ERROR) << "Wallpaper reverts to default unexpected."; | 884 LOG(ERROR) << "Wallpaper reverts to default unexpected."; |
877 DoSetDefaultWallpaper(user_id, on_finish.Pass()); | 885 DoSetDefaultWallpaper(account_id, on_finish.Pass()); |
878 } | 886 } |
879 } | 887 } |
880 | 888 |
881 void WallpaperManagerBase::MoveCustomWallpapersSuccess( | 889 void WallpaperManagerBase::MoveCustomWallpapersSuccess( |
882 const std::string& user_id, | 890 const AccountId& account_id, |
883 const std::string& user_id_hash) { | 891 const std::string& user_id_hash) { |
884 WallpaperInfo info; | 892 WallpaperInfo info; |
885 GetUserWallpaperInfo(user_id, &info); | 893 GetUserWallpaperInfo(account_id, &info); |
886 if (info.type == user_manager::User::CUSTOMIZED) { | 894 if (info.type == user_manager::User::CUSTOMIZED) { |
887 // New file field should include user id hash in addition to file name. | 895 // New file field should include user id hash in addition to file name. |
888 // This is needed because at login screen, user id hash is not available. | 896 // This is needed because at login screen, user id hash is not available. |
889 info.location = base::FilePath(user_id_hash).Append(info.location).value(); | 897 info.location = base::FilePath(user_id_hash).Append(info.location).value(); |
890 bool is_persistent = | 898 bool is_persistent = |
891 !user_manager::UserManager::Get()->IsUserNonCryptohomeDataEphemeral( | 899 !user_manager::UserManager::Get()->IsUserNonCryptohomeDataEphemeral( |
892 AccountId::FromUserEmail(user_id)); | 900 account_id); |
893 SetUserWallpaperInfo(user_id, info, is_persistent); | 901 SetUserWallpaperInfo(account_id, info, is_persistent); |
894 } | 902 } |
895 } | 903 } |
896 | 904 |
897 void WallpaperManagerBase::MoveLoggedInUserCustomWallpaper() { | 905 void WallpaperManagerBase::MoveLoggedInUserCustomWallpaper() { |
898 const user_manager::User* logged_in_user = | 906 const user_manager::User* logged_in_user = |
899 user_manager::UserManager::Get()->GetLoggedInUser(); | 907 user_manager::UserManager::Get()->GetLoggedInUser(); |
900 if (logged_in_user) { | 908 if (logged_in_user) { |
901 task_runner_->PostTask( | 909 task_runner_->PostTask( |
902 FROM_HERE, | 910 FROM_HERE, |
903 base::Bind(&WallpaperManagerBase::MoveCustomWallpapersOnWorker, | 911 base::Bind(&WallpaperManagerBase::MoveCustomWallpapersOnWorker, |
904 logged_in_user->email(), logged_in_user->username_hash(), | 912 logged_in_user->GetAccountId(), |
| 913 logged_in_user->username_hash(), |
905 weak_factory_.GetWeakPtr())); | 914 weak_factory_.GetWeakPtr())); |
906 } | 915 } |
907 } | 916 } |
908 | 917 |
909 void WallpaperManagerBase::SaveLastLoadTime(const base::TimeDelta elapsed) { | 918 void WallpaperManagerBase::SaveLastLoadTime(const base::TimeDelta elapsed) { |
910 while (last_load_times_.size() >= kLastLoadsStatsMsMaxSize) | 919 while (last_load_times_.size() >= kLastLoadsStatsMsMaxSize) |
911 last_load_times_.pop_front(); | 920 last_load_times_.pop_front(); |
912 | 921 |
913 if (elapsed > base::TimeDelta::FromMicroseconds(0)) { | 922 if (elapsed > base::TimeDelta::FromMicroseconds(0)) { |
914 last_load_times_.push_back(elapsed); | 923 last_load_times_.push_back(elapsed); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 void WallpaperManagerBase::CreateSolidDefaultWallpaper() { | 1068 void WallpaperManagerBase::CreateSolidDefaultWallpaper() { |
1060 loaded_wallpapers_for_test_++; | 1069 loaded_wallpapers_for_test_++; |
1061 SkBitmap bitmap; | 1070 SkBitmap bitmap; |
1062 bitmap.allocN32Pixels(1, 1); | 1071 bitmap.allocN32Pixels(1, 1); |
1063 bitmap.eraseColor(kDefaultWallpaperColor); | 1072 bitmap.eraseColor(kDefaultWallpaperColor); |
1064 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 1073 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
1065 default_wallpaper_image_.reset(new user_manager::UserImage(image)); | 1074 default_wallpaper_image_.reset(new user_manager::UserImage(image)); |
1066 } | 1075 } |
1067 | 1076 |
1068 } // namespace wallpaper | 1077 } // namespace wallpaper |
OLD | NEW |