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

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: Merge to trunk 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
398 bool new_wallpaper_ui_disabled = CommandLine::ForCurrentProcess()->
399 HasSwitch(switches::kDisableNewWallpaperUI);
400 if (!new_wallpaper_ui_disabled) {
401 // User's custom wallpaper path is determined by username/email and the
402 // appropriate wallpaper resolution in GetCustomWallpaperInternal. So use
403 // DUMMY as file name here.
404 WallpaperInfo info = {
405 "DUMMY",
406 layout,
407 User::CUSTOMIZED,
408 base::Time::Now().LocalMidnight()
409 };
410 SetUserWallpaperInfo(username, info, is_persistent);
411 }
412 SetUserWallpaperProperties(username, type, layout, is_persistent);
413 }
414
415 void WallpaperManager::SetUserWallpaperFromFile(
416 const std::string& username,
417 const FilePath& path,
418 ash::WallpaperLayout layout,
419 base::WeakPtr<WallpaperDelegate> delegate) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
421
422 // For wallpapers, save the image without resizing.
423 wallpaper_loader_->Start(
424 path.value(), 0,
425 base::Bind(&WallpaperManager::SetCustomWallpaper,
426 base::Unretained(this), username, layout, User::CUSTOMIZED,
427 delegate));
428 }
429
364 void WallpaperManager::SetUserWallpaperProperties(const std::string& email, 430 void WallpaperManager::SetUserWallpaperProperties(const std::string& email,
365 User::WallpaperType type, 431 User::WallpaperType type,
366 int index, 432 int index,
367 bool is_persistent) { 433 bool is_persistent) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
369 435
370 current_user_wallpaper_type_ = type; 436 current_user_wallpaper_type_ = type;
371 current_user_wallpaper_index_ = index; 437 current_user_wallpaper_index_ = index;
372 if (!is_persistent) 438 if (!is_persistent)
373 return; 439 return;
374 440
375 PrefService* local_state = g_browser_process->local_state(); 441 PrefService* local_state = g_browser_process->local_state();
376 DictionaryPrefUpdate wallpaper_update(local_state, 442 DictionaryPrefUpdate wallpaper_update(local_state,
377 UserManager::kUserWallpapersProperties); 443 UserManager::kUserWallpapersProperties);
378 444
379 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); 445 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
380 wallpaper_properties->Set(kWallpaperTypeNodeName, 446 wallpaper_properties->Set(kWallpaperTypeNodeName,
381 new base::FundamentalValue(type)); 447 new base::FundamentalValue(type));
382 wallpaper_properties->Set(kWallpaperIndexNodeName, 448 wallpaper_properties->Set(kWallpaperIndexNodeName,
383 new base::FundamentalValue(index)); 449 new base::FundamentalValue(index));
384 wallpaper_properties->SetString(kWallpaperDateNodeName, 450 wallpaper_properties->SetString(kWallpaperDateNodeName,
385 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue())); 451 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue()));
386 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties); 452 wallpaper_update->SetWithoutPathExpansion(email, wallpaper_properties);
387 } 453 }
388 454
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, 455 void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
405 bool is_persistent) { 456 bool is_persistent) {
406 current_user_wallpaper_type_ = User::DEFAULT; 457 current_user_wallpaper_type_ = User::DEFAULT;
407 if (username == kGuestUser) 458 if (username == kGuestUser)
408 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex(); 459 current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
409 else 460 else
410 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex(); 461 current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
411 462
412 bool new_wallpaper_ui_disabled = CommandLine::ForCurrentProcess()-> 463 bool new_wallpaper_ui_disabled = CommandLine::ForCurrentProcess()->
413 HasSwitch(switches::kDisableNewWallpaperUI); 464 HasSwitch(switches::kDisableNewWallpaperUI);
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 path)); 1033 path));
983 } 1034 }
984 1035
985 void WallpaperManager::SaveWallpaperInternal(const FilePath& path, 1036 void WallpaperManager::SaveWallpaperInternal(const FilePath& path,
986 const char* data, 1037 const char* data,
987 int size) { 1038 int size) {
988 int written_bytes = file_util::WriteFile(path, data, size); 1039 int written_bytes = file_util::WriteFile(path, data, size);
989 DCHECK(written_bytes == size); 1040 DCHECK(written_bytes == size);
990 } 1041 }
991 1042
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) { 1043 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) {
1029 UserManager* user_manager = UserManager::Get(); 1044 UserManager* user_manager = UserManager::Get();
1030 // |email| is from user list in local state. We should persist data in this 1045 // |email| is from user list in local state. We should persist data in this
1031 // case. 1046 // case.
1032 if (!user_manager->IsUserLoggedIn()) 1047 if (!user_manager->IsUserLoggedIn())
1033 return true; 1048 return true;
1034 return !(email == user_manager->GetLoggedInUser().email() && 1049 return !(email == user_manager->GetLoggedInUser().email() &&
1035 user_manager->IsCurrentUserEphemeral()); 1050 user_manager->IsCurrentUserEphemeral());
1036 } 1051 }
1037 1052
1038 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, 1053 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout,
1039 const UserImage& user_image) { 1054 const UserImage& user_image) {
1040 SetWallpaperFromImageSkia(user_image.image(), layout); 1055 SetWallpaperFromImageSkia(user_image.image(), layout);
1041 } 1056 }
1042 1057
1043 void WallpaperManager::SystemResumed() { 1058 void WallpaperManager::SystemResumed() {
1044 BatchUpdateWallpaper(); 1059 BatchUpdateWallpaper();
1045 } 1060 }
1046 1061
1047 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { 1062 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) {
1048 RestartTimer(); 1063 RestartTimer();
1049 } 1064 }
1050 1065
1051 } // chromeos 1066 } // chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | chrome/browser/extensions/extension_function_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698