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

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

Issue 10890038: Hook up custom wallpaper code path to new wallpaper picker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reviews Created 8 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
6 6
7 #include "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/desktop_background/desktop_background_resources.h" 8 #include "ash/desktop_background/desktop_background_resources.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 BatchUpdateWallpaper(); 354 BatchUpdateWallpaper();
355 } else { 355 } else {
356 // Set up a one shot timer which will batch update wallpaper at midnight. 356 // Set up a one shot timer which will batch update wallpaper at midnight.
357 timer_.Start(FROM_HERE, 357 timer_.Start(FROM_HERE,
358 base::TimeDelta::FromSeconds(remaining_seconds), 358 base::TimeDelta::FromSeconds(remaining_seconds),
359 this, 359 this,
360 &WallpaperManager::BatchUpdateWallpaper); 360 &WallpaperManager::BatchUpdateWallpaper);
361 } 361 }
362 } 362 }
363 363
364 void WallpaperManager::SetCustomWallpaper(const std::string& username,
365 ash::WallpaperLayout layout,
366 User::WallpaperType type,
367 base::WeakPtr<WallpaperDelegate> delegate,
368 const UserImage& wallpaper) {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
370
371 std::string wallpaper_path =
372 GetOriginalWallpaperPathForUser(username).value();
373
374 bool is_persistent = ShouldPersistDataForUser(username);
375
376 BrowserThread::PostTask(
377 BrowserThread::FILE,
378 FROM_HERE,
379 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail,
380 base::Unretained(this), username, type, delegate,
381 wallpaper.image()));
382
383 if (is_persistent) {
384 BrowserThread::PostTask(
385 BrowserThread::FILE,
386 FROM_HERE,
387 base::Bind(&WallpaperManager::SaveCustomWallpaper,
388 base::Unretained(this),
389 username,
390 FilePath(wallpaper_path),
391 layout,
392 wallpaper));
393 }
394
395 ash::Shell::GetInstance()->desktop_background_controller()->
396 SetCustomWallpaper(wallpaper.image(), layout);
397 bool new_wallpaper_ui_enabled = CommandLine::ForCurrentProcess()->
398 HasSwitch(switches::kEnableNewWallpaperUI);
399 if (new_wallpaper_ui_enabled) {
400 // User's custom wallpaper path is determined by username/email and the
401 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use
402 // DUMMY as file name here.
403 WallpaperInfo info = {
404 "DUMMY",
405 layout,
406 User::CUSTOMIZED,
407 base::Time::Now().LocalMidnight()
408 };
409 SetUserWallpaperInfo(username, info, is_persistent);
410 }
411 SetUserWallpaperProperties(username, type, layout, is_persistent);
412 }
413
414 void WallpaperManager::SetUserWallpaperFromFile(
415 const std::string& username,
416 const FilePath& path,
417 ash::WallpaperLayout layout,
418 base::WeakPtr<WallpaperDelegate> delegate) {
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
420
421 // For wallpapers, save the image without resizing.
422 wallpaper_loader_->Start(
423 path.value(), 0,
424 base::Bind(&WallpaperManager::SetCustomWallpaper,
425 base::Unretained(this), username, layout, User::CUSTOMIZED,
426 delegate));
427 }
428
364 void WallpaperManager::SetUserWallpaperProperties(const std::string& email, 429 void WallpaperManager::SetUserWallpaperProperties(const std::string& email,
365 User::WallpaperType type, 430 User::WallpaperType type,
366 int index, 431 int index,
367 bool is_persistent) { 432 bool is_persistent) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
369 434
370 current_user_wallpaper_type_ = type; 435 current_user_wallpaper_type_ = type;
371 current_user_wallpaper_index_ = index; 436 current_user_wallpaper_index_ = index;
372 if (!is_persistent) 437 if (!is_persistent)
373 return; 438 return;
374 439
375 PrefService* local_state = g_browser_process->local_state(); 440 PrefService* local_state = g_browser_process->local_state();
376 DictionaryPrefUpdate wallpaper_update(local_state, 441 DictionaryPrefUpdate wallpaper_update(local_state,
377 UserManager::kUserWallpapersProperties); 442 UserManager::kUserWallpapersProperties);
378 443
379 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); 444 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
380 wallpaper_properties->Set(kWallpaperTypeNodeName, 445 wallpaper_properties->Set(kWallpaperTypeNodeName,
381 new base::FundamentalValue(type)); 446 new base::FundamentalValue(type));
382 wallpaper_properties->Set(kWallpaperIndexNodeName, 447 wallpaper_properties->Set(kWallpaperIndexNodeName,
383 new base::FundamentalValue(index)); 448 new base::FundamentalValue(index));
384 wallpaper_properties->SetString(kWallpaperDateNodeName, 449 wallpaper_properties->SetString(kWallpaperDateNodeName,
385 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue())); 450 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue()));
386 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties); 451 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties);
387 } 452 }
388 453
389 void WallpaperManager::SetUserWallpaperFromFile(
390 const std::string& username,
391 const FilePath& path,
392 ash::WallpaperLayout layout,
393 base::WeakPtr<WallpaperDelegate> delegate) {
394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
395
396 // For wallpapers, save the image without resizing.
397 wallpaper_loader_->Start(
398 path.value(), 0,
399 base::Bind(&WallpaperManager::SetCustomWallpaper,
400 base::Unretained(this), username, layout, User::CUSTOMIZED,
401 delegate));
402 }
403
404 void WallpaperManager::SetInitialUserWallpaper(const std::string& username, 454 void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
405 bool is_persistent) { 455 bool is_persistent) {
406 current_user_wallpaper_type_ = User::DEFAULT; 456 current_user_wallpaper_type_ = User::DEFAULT;
407 if (username == kGuestUser) 457 if (username == kGuestUser)
408 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); 458 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
409 else 459 else
410 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); 460 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
411 461
412 bool new_wallpaper_ui_enabled = CommandLine::ForCurrentProcess()-> 462 bool new_wallpaper_ui_enabled = CommandLine::ForCurrentProcess()->
413 HasSwitch(switches::kEnableNewWallpaperUI); 463 HasSwitch(switches::kEnableNewWallpaperUI);
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 path)); 1032 path));
983 } 1033 }
984 1034
985 void WallpaperManager::SaveWallpaperInternal(const FilePath& path, 1035 void WallpaperManager::SaveWallpaperInternal(const FilePath& path,
986 const char* data, 1036 const char* data,
987 int size) { 1037 int size) {
988 int written_bytes = file_util::WriteFile(path, data, size); 1038 int written_bytes = file_util::WriteFile(path, data, size);
989 DCHECK(written_bytes == size); 1039 DCHECK(written_bytes == size);
990 } 1040 }
991 1041
992 void WallpaperManager::SetCustomWallpaper(const std::string& username,
993 ash::WallpaperLayout layout,
994 User::WallpaperType type,
995 base::WeakPtr<WallpaperDelegate> delegate,
996 const UserImage& wallpaper) {
997 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
998
999 std::string wallpaper_path =
1000 GetOriginalWallpaperPathForUser(username).value();
1001
1002 bool is_persistent = ShouldPersistDataForUser(username);
1003
1004 BrowserThread::PostTask(
1005 BrowserThread::FILE,
1006 FROM_HERE,
1007 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail,
1008 base::Unretained(this), username, type, delegate,
1009 wallpaper.image()));
1010
1011 if (is_persistent) {
1012 BrowserThread::PostTask(
1013 BrowserThread::FILE,
1014 FROM_HERE,
1015 base::Bind(&WallpaperManager::SaveCustomWallpaper,
1016 base::Unretained(this),
1017 username,
1018 FilePath(wallpaper_path),
1019 layout,
1020 wallpaper));
1021 }
1022
1023 ash::Shell::GetInstance()->desktop_background_controller()->
1024 SetCustomWallpaper(wallpaper.image(), layout);
1025 SetUserWallpaperProperties(username, type, layout, is_persistent);
1026 }
1027
1028 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) { 1042 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) {
1029 UserManager* user_manager = UserManager::Get(); 1043 UserManager* user_manager = UserManager::Get();
1030 // |email| is from user list in local state. We should persist data in this 1044 // |email| is from user list in local state. We should persist data in this
1031 // case. 1045 // case.
1032 if (!user_manager->IsUserLoggedIn()) 1046 if (!user_manager->IsUserLoggedIn())
1033 return true; 1047 return true;
1034 return !(email == user_manager->GetLoggedInUser().email() && 1048 return !(email == user_manager->GetLoggedInUser().email() &&
1035 user_manager->IsCurrentUserEphemeral()); 1049 user_manager->IsCurrentUserEphemeral());
1036 } 1050 }
1037 1051
1038 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, 1052 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout,
1039 const UserImage& user_image) { 1053 const UserImage& user_image) {
1040 SetWallpaperFromImageSkia(user_image.image(), layout); 1054 SetWallpaperFromImageSkia(user_image.image(), layout);
1041 } 1055 }
1042 1056
1043 void WallpaperManager::SystemResumed() { 1057 void WallpaperManager::SystemResumed() {
1044 BatchUpdateWallpaper(); 1058 BatchUpdateWallpaper();
1045 } 1059 }
1046 1060
1047 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { 1061 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) {
1048 RestartTimer(); 1062 RestartTimer();
1049 } 1063 }
1050 1064
1051 } // chromeos 1065 } // chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698