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

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: 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 BatchUpdateWallpaper(); 366 BatchUpdateWallpaper();
367 } else { 367 } else {
368 // Set up a one shot timer which will batch update wallpaper at midnight. 368 // Set up a one shot timer which will batch update wallpaper at midnight.
369 timer_.Start(FROM_HERE, 369 timer_.Start(FROM_HERE,
370 base::TimeDelta::FromSeconds(remaining_seconds), 370 base::TimeDelta::FromSeconds(remaining_seconds),
371 this, 371 this,
372 &WallpaperManager::BatchUpdateWallpaper); 372 &WallpaperManager::BatchUpdateWallpaper);
373 } 373 }
374 } 374 }
375 375
376 void WallpaperManager::SetCustomWallpaper(const std::string& username,
377 ash::WallpaperLayout layout,
378 User::WallpaperType type,
379 base::WeakPtr<WallpaperDelegate> delegate,
380 const UserImage& wallpaper) {
381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
382
383 std::string wallpaper_path =
384 GetOriginalWallpaperPathForUser(username).value();
385
386 bool is_persistent = ShouldPersistDataForUser(username);
387
388 BrowserThread::PostTask(
389 BrowserThread::FILE,
390 FROM_HERE,
391 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail,
392 base::Unretained(this), username, type, delegate,
393 wallpaper.image()));
394
395 if (is_persistent) {
396 BrowserThread::PostTask(
397 BrowserThread::FILE,
398 FROM_HERE,
399 base::Bind(&WallpaperManager::SaveCustomWallpaper,
400 base::Unretained(this),
401 username,
402 FilePath(wallpaper_path),
403 layout,
404 wallpaper));
405 }
406
407 ash::Shell::GetInstance()->desktop_background_controller()->
408 SetCustomWallpaper(wallpaper.image(), layout);
409 bool new_wallpaper_ui_enabled = CommandLine::ForCurrentProcess()->
410 HasSwitch(switches::kEnableNewWallpaperUI);
411 if (new_wallpaper_ui_enabled) {
412 // User's custom wallpaper path is determined by username/email and the
413 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use
414 // DUMMY as file name here.
415 WallpaperInfo info = {
416 "DUMMY",
417 layout,
418 User::CUSTOMIZED,
419 base::Time::Now().LocalMidnight()
420 };
421 SetUserWallpaperInfo(username, info, is_persistent);
422 }
423 SetUserWallpaperProperties(username, type, layout, is_persistent);
424 }
425
426 void WallpaperManager::SetUserWallpaperFromFile(
427 const std::string& username,
428 const FilePath& path,
429 ash::WallpaperLayout layout,
430 base::WeakPtr<WallpaperDelegate> delegate) {
431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
432
433 // For wallpapers, save the image without resizing.
434 wallpaper_loader_->Start(
435 path.value(), 0,
436 base::Bind(&WallpaperManager::SetCustomWallpaper,
437 base::Unretained(this), username, layout, User::CUSTOMIZED,
438 delegate));
439 }
440
376 void WallpaperManager::SetUserWallpaperProperties(const std::string& email, 441 void WallpaperManager::SetUserWallpaperProperties(const std::string& email,
377 User::WallpaperType type, 442 User::WallpaperType type,
378 int index, 443 int index,
379 bool is_persistent) { 444 bool is_persistent) {
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
381 446
382 current_user_wallpaper_type_ = type; 447 current_user_wallpaper_type_ = type;
383 current_user_wallpaper_index_ = index; 448 current_user_wallpaper_index_ = index;
384 if (!is_persistent) 449 if (!is_persistent)
385 return; 450 return;
386 451
387 PrefService* local_state = g_browser_process->local_state(); 452 PrefService* local_state = g_browser_process->local_state();
388 DictionaryPrefUpdate wallpaper_update(local_state, 453 DictionaryPrefUpdate wallpaper_update(local_state,
389 UserManager::kUserWallpapersProperties); 454 UserManager::kUserWallpapersProperties);
390 455
391 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); 456 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
392 wallpaper_properties->Set(kWallpaperTypeNodeName, 457 wallpaper_properties->Set(kWallpaperTypeNodeName,
393 new base::FundamentalValue(type)); 458 new base::FundamentalValue(type));
394 wallpaper_properties->Set(kWallpaperIndexNodeName, 459 wallpaper_properties->Set(kWallpaperIndexNodeName,
395 new base::FundamentalValue(index)); 460 new base::FundamentalValue(index));
396 wallpaper_properties->SetString(kWallpaperDateNodeName, 461 wallpaper_properties->SetString(kWallpaperDateNodeName,
397 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue())); 462 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue()));
398 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties); 463 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties);
399 } 464 }
400 465
401 void WallpaperManager::SetUserWallpaperFromFile(
402 const std::string& username,
403 const FilePath& path,
404 ash::WallpaperLayout layout,
405 base::WeakPtr<WallpaperDelegate> delegate) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
407
408 // For wallpapers, save the image without resizing.
409 wallpaper_loader_->Start(
410 path.value(), 0,
411 base::Bind(&WallpaperManager::SetCustomWallpaper,
412 base::Unretained(this), username, layout, User::CUSTOMIZED,
413 delegate));
414 }
415
416 void WallpaperManager::SetInitialUserWallpaper(const std::string& username, 466 void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
417 bool is_persistent) { 467 bool is_persistent) {
418 current_user_wallpaper_type_ = User::DEFAULT; 468 current_user_wallpaper_type_ = User::DEFAULT;
419 if (username == kGuestUser) 469 if (username == kGuestUser)
420 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); 470 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
421 else 471 else
422 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); 472 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
423 473
424 bool new_wallpaper_ui_enabled = CommandLine::ForCurrentProcess()-> 474 bool new_wallpaper_ui_enabled = CommandLine::ForCurrentProcess()->
425 HasSwitch(switches::kEnableNewWallpaperUI); 475 HasSwitch(switches::kEnableNewWallpaperUI);
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 path)); 1052 path));
1003 } 1053 }
1004 1054
1005 void WallpaperManager::SaveWallpaperInternal(const FilePath& path, 1055 void WallpaperManager::SaveWallpaperInternal(const FilePath& path,
1006 const char* data, 1056 const char* data,
1007 int size) { 1057 int size) {
1008 int written_bytes = file_util::WriteFile(path, data, size); 1058 int written_bytes = file_util::WriteFile(path, data, size);
1009 DCHECK(written_bytes == size); 1059 DCHECK(written_bytes == size);
1010 } 1060 }
1011 1061
1012 void WallpaperManager::SetCustomWallpaper(const std::string& username,
1013 ash::WallpaperLayout layout,
1014 User::WallpaperType type,
1015 base::WeakPtr<WallpaperDelegate> delegate,
1016 const UserImage& wallpaper) {
1017 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1018
1019 std::string wallpaper_path =
1020 GetOriginalWallpaperPathForUser(username).value();
1021
1022 bool is_persistent = ShouldPersistDataForUser(username);
1023
1024 BrowserThread::PostTask(
1025 BrowserThread::FILE,
1026 FROM_HERE,
1027 base::Bind(&WallpaperManager::GenerateUserWallpaperThumbnail,
1028 base::Unretained(this), username, type, delegate,
1029 wallpaper.image()));
1030
1031 if (is_persistent) {
1032 BrowserThread::PostTask(
1033 BrowserThread::FILE,
1034 FROM_HERE,
1035 base::Bind(&WallpaperManager::SaveCustomWallpaper,
1036 base::Unretained(this),
1037 username,
1038 FilePath(wallpaper_path),
1039 layout,
1040 wallpaper));
1041 }
1042
1043 ash::Shell::GetInstance()->desktop_background_controller()->
1044 SetCustomWallpaper(wallpaper.image(), layout);
1045 SetUserWallpaperProperties(username, type, layout, is_persistent);
1046 }
1047
1048 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) { 1062 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) {
1049 UserManager* user_manager = UserManager::Get(); 1063 UserManager* user_manager = UserManager::Get();
1050 // |email| is from user list in local state. We should persist data in this 1064 // |email| is from user list in local state. We should persist data in this
1051 // case. 1065 // case.
1052 if (!user_manager->IsUserLoggedIn()) 1066 if (!user_manager->IsUserLoggedIn())
1053 return true; 1067 return true;
1054 return !(email == user_manager->GetLoggedInUser().email() && 1068 return !(email == user_manager->GetLoggedInUser().email() &&
1055 user_manager->IsCurrentUserEphemeral()); 1069 user_manager->IsCurrentUserEphemeral());
1056 } 1070 }
1057 1071
1058 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, 1072 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout,
1059 const UserImage& user_image) { 1073 const UserImage& user_image) {
1060 SetWallpaperFromImageSkia(user_image.image(), layout); 1074 SetWallpaperFromImageSkia(user_image.image(), layout);
1061 } 1075 }
1062 1076
1063 void WallpaperManager::SystemResumed() { 1077 void WallpaperManager::SystemResumed() {
1064 BatchUpdateWallpaper(); 1078 BatchUpdateWallpaper();
1065 } 1079 }
1066 1080
1067 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { 1081 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) {
1068 RestartTimer(); 1082 RestartTimer();
1069 } 1083 }
1070 1084
1071 } // chromeos 1085 } // chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698