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

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.cc

Issue 331033002: Revert of Remove more unretained (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/wallpaper/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_constants.h" 10 #include "ash/ash_constants.h"
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo); 519 registry->RegisterDictionaryPref(prefs::kUsersWallpaperInfo);
520 registry->RegisterDictionaryPref(kUserWallpapers); 520 registry->RegisterDictionaryPref(kUserWallpapers);
521 registry->RegisterDictionaryPref(kUserWallpapersProperties); 521 registry->RegisterDictionaryPref(kUserWallpapersProperties);
522 } 522 }
523 523
524 void WallpaperManager::AddObservers() { 524 void WallpaperManager::AddObservers() {
525 show_user_name_on_signin_subscription_ = 525 show_user_name_on_signin_subscription_ =
526 CrosSettings::Get()->AddSettingsObserver( 526 CrosSettings::Get()->AddSettingsObserver(
527 kAccountsPrefShowUserNamesOnSignIn, 527 kAccountsPrefShowUserNamesOnSignIn,
528 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, 528 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper,
529 weak_factory_.GetWeakPtr())); 529 base::Unretained(this)));
530 } 530 }
531 531
532 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { 532 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() {
533 // Some browser tests do not have a shell instance. As no wallpaper is needed 533 // Some browser tests do not have a shell instance. As no wallpaper is needed
534 // in these tests anyway, avoid loading one, preventing crashes and speeding 534 // in these tests anyway, avoid loading one, preventing crashes and speeding
535 // up the tests. 535 // up the tests.
536 if (!ash::Shell::HasInstance()) 536 if (!ash::Shell::HasInstance())
537 return; 537 return;
538 538
539 WallpaperInfo info; 539 WallpaperInfo info;
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper 889 // Block shutdown on this task. Otherwise, we may lose the custom wallpaper
890 // that the user selected. 890 // that the user selected.
891 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner = 891 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner =
892 BrowserThread::GetBlockingPool() 892 BrowserThread::GetBlockingPool()
893 ->GetSequencedTaskRunnerWithShutdownBehavior( 893 ->GetSequencedTaskRunnerWithShutdownBehavior(
894 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN); 894 sequence_token_, base::SequencedWorkerPool::BLOCK_SHUTDOWN);
895 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. 895 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
896 blocking_task_runner->PostTask( 896 blocking_task_runner->PostTask(
897 FROM_HERE, 897 FROM_HERE,
898 base::Bind(&WallpaperManager::SaveCustomWallpaper, 898 base::Bind(&WallpaperManager::SaveCustomWallpaper,
899 weak_factory_.GetWeakPtr(), 899 base::Unretained(this),
900 user_id_hash, 900 user_id_hash,
901 base::FilePath(wallpaper_info.file), 901 base::FilePath(wallpaper_info.file),
902 wallpaper_info.layout, 902 wallpaper_info.layout,
903 base::Passed(deep_copy.Pass()))); 903 base::Passed(deep_copy.Pass())));
904 } 904 }
905 905
906 std::string relative_path = base::FilePath(user_id_hash).Append(file).value(); 906 std::string relative_path = base::FilePath(user_id_hash).Append(file).value();
907 // User's custom wallpaper path is determined by relative path and the 907 // User's custom wallpaper path is determined by relative path and the
908 // appropriate wallpaper resolution in GetCustomWallpaperInternal. 908 // appropriate wallpaper resolution in GetCustomWallpaperInternal.
909 WallpaperInfo info = { 909 WallpaperInfo info = {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 1174
1175 base::FilePath wallpaper_dir; 1175 base::FilePath wallpaper_dir;
1176 base::FilePath wallpaper_path; 1176 base::FilePath wallpaper_path;
1177 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { 1177 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) {
1178 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); 1178 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution();
1179 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); 1179 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
1180 wallpaper_path = wallpaper_path.Append(info.file); 1180 wallpaper_path = wallpaper_path.Append(info.file);
1181 task_runner_->PostTask( 1181 task_runner_->PostTask(
1182 FROM_HERE, 1182 FROM_HERE,
1183 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 1183 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
1184 weak_factory_.GetWeakPtr(), 1184 base::Unretained(this),
1185 user_id, 1185 user_id,
1186 info, 1186 info,
1187 wallpaper_path, 1187 wallpaper_path,
1188 false /* do not update wallpaper */, 1188 false /* do not update wallpaper */,
1189 base::Passed(MovableOnDestroyCallbackHolder()))); 1189 base::Passed(MovableOnDestroyCallbackHolder())));
1190 return; 1190 return;
1191 } 1191 }
1192 LoadWallpaper(user_id, 1192 LoadWallpaper(user_id,
1193 info, 1193 info,
1194 false /* do not update wallpaper */, 1194 false /* do not update wallpaper */,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 IsRunningSequenceOnCurrentThread(sequence_token_)); 1394 IsRunningSequenceOnCurrentThread(sequence_token_));
1395 if (MoveCustomWallpaperDirectory( 1395 if (MoveCustomWallpaperDirectory(
1396 kOriginalWallpaperSubDir, user_id, user_id_hash)) { 1396 kOriginalWallpaperSubDir, user_id, user_id_hash)) {
1397 // Consider success if the original wallpaper is moved to the new directory. 1397 // Consider success if the original wallpaper is moved to the new directory.
1398 // Original wallpaper is the fallback if the correct resolution wallpaper 1398 // Original wallpaper is the fallback if the correct resolution wallpaper
1399 // can not be found. 1399 // can not be found.
1400 BrowserThread::PostTask( 1400 BrowserThread::PostTask(
1401 BrowserThread::UI, 1401 BrowserThread::UI,
1402 FROM_HERE, 1402 FROM_HERE,
1403 base::Bind(&WallpaperManager::MoveCustomWallpapersSuccess, 1403 base::Bind(&WallpaperManager::MoveCustomWallpapersSuccess,
1404 weak_factory_.GetWeakPtr(), 1404 base::Unretained(this),
1405 user_id, 1405 user_id,
1406 user_id_hash)); 1406 user_id_hash));
1407 } 1407 }
1408 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash); 1408 MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash);
1409 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash); 1409 MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash);
1410 MoveCustomWallpaperDirectory( 1410 MoveCustomWallpaperDirectory(
1411 kThumbnailWallpaperSubDir, user_id, user_id_hash); 1411 kThumbnailWallpaperSubDir, user_id, user_id_hash);
1412 } 1412 }
1413 1413
1414 void WallpaperManager::MoveCustomWallpapersSuccess( 1414 void WallpaperManager::MoveCustomWallpapersSuccess(
(...skipping 11 matching lines...) Expand all
1426 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id); 1426 !UserManager::Get()->IsUserNonCryptohomeDataEphemeral(user_id);
1427 SetUserWallpaperInfo(user_id, info, is_persistent); 1427 SetUserWallpaperInfo(user_id, info, is_persistent);
1428 } 1428 }
1429 } 1429 }
1430 1430
1431 void WallpaperManager::MoveLoggedInUserCustomWallpaper() { 1431 void WallpaperManager::MoveLoggedInUserCustomWallpaper() {
1432 const User* logged_in_user = UserManager::Get()->GetLoggedInUser(); 1432 const User* logged_in_user = UserManager::Get()->GetLoggedInUser();
1433 task_runner_->PostTask( 1433 task_runner_->PostTask(
1434 FROM_HERE, 1434 FROM_HERE,
1435 base::Bind(&WallpaperManager::MoveCustomWallpapersOnWorker, 1435 base::Bind(&WallpaperManager::MoveCustomWallpapersOnWorker,
1436 weak_factory_.GetWeakPtr(), 1436 base::Unretained(this),
1437 logged_in_user->email(), 1437 logged_in_user->email(),
1438 logged_in_user->username_hash())); 1438 logged_in_user->username_hash()));
1439 } 1439 }
1440 1440
1441 void WallpaperManager::GetCustomWallpaperInternal( 1441 void WallpaperManager::GetCustomWallpaperInternal(
1442 const std::string& user_id, 1442 const std::string& user_id,
1443 const WallpaperInfo& info, 1443 const WallpaperInfo& info,
1444 const base::FilePath& wallpaper_path, 1444 const base::FilePath& wallpaper_path,
1445 bool update_wallpaper, 1445 bool update_wallpaper,
1446 MovableOnDestroyCallbackHolder on_finish) { 1446 MovableOnDestroyCallbackHolder on_finish) {
(...skipping 15 matching lines...) Expand all
1462 valid_path = 1462 valid_path =
1463 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, info.file); 1463 GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id, info.file);
1464 } 1464 }
1465 1465
1466 if (!base::PathExists(valid_path)) { 1466 if (!base::PathExists(valid_path)) {
1467 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " << 1467 LOG(ERROR) << "Failed to load previously selected custom wallpaper. " <<
1468 "Fallback to default wallpaper"; 1468 "Fallback to default wallpaper";
1469 BrowserThread::PostTask(BrowserThread::UI, 1469 BrowserThread::PostTask(BrowserThread::UI,
1470 FROM_HERE, 1470 FROM_HERE,
1471 base::Bind(&WallpaperManager::DoSetDefaultWallpaper, 1471 base::Bind(&WallpaperManager::DoSetDefaultWallpaper,
1472 weak_factory_.GetWeakPtr(), 1472 base::Unretained(this),
1473 user_id, 1473 user_id,
1474 base::Passed(on_finish.Pass()))); 1474 base::Passed(on_finish.Pass())));
1475 } else { 1475 } else {
1476 BrowserThread::PostTask(BrowserThread::UI, 1476 BrowserThread::PostTask(BrowserThread::UI,
1477 FROM_HERE, 1477 FROM_HERE,
1478 base::Bind(&WallpaperManager::StartLoad, 1478 base::Bind(&WallpaperManager::StartLoad,
1479 weak_factory_.GetWeakPtr(), 1479 base::Unretained(this),
1480 user_id, 1480 user_id,
1481 info, 1481 info,
1482 update_wallpaper, 1482 update_wallpaper,
1483 valid_path, 1483 valid_path,
1484 base::Passed(on_finish.Pass()))); 1484 base::Passed(on_finish.Pass())));
1485 } 1485 }
1486 } 1486 }
1487 1487
1488 void WallpaperManager::OnWallpaperDecoded( 1488 void WallpaperManager::OnWallpaperDecoded(
1489 const std::string& user_id, 1489 const std::string& user_id,
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 loaded_wallpapers_++; 1906 loaded_wallpapers_++;
1907 SkBitmap bitmap; 1907 SkBitmap bitmap;
1908 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0); 1908 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 0);
1909 bitmap.allocPixels(); 1909 bitmap.allocPixels();
1910 bitmap.eraseColor(kDefaultWallpaperColor); 1910 bitmap.eraseColor(kDefaultWallpaperColor);
1911 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 1911 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
1912 default_wallpaper_image_.reset(new UserImage(image)); 1912 default_wallpaper_image_.reset(new UserImage(image));
1913 } 1913 }
1914 1914
1915 } // namespace chromeos 1915 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698