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

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

Issue 11415015: Remove use of index in wallpaper picker code and some refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser tests Created 8 years, 1 month 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 <vector> 7 #include <vector>
8 8
9 #include "ash/desktop_background/desktop_background_controller.h"
10 #include "ash/desktop_background/desktop_background_resources.h"
11 #include "ash/shell.h" 9 #include "ash/shell.h"
12 #include "base/command_line.h" 10 #include "base/command_line.h"
13 #include "base/logging.h" 11 #include "base/logging.h"
14 #include "base/file_path.h" 12 #include "base/file_path.h"
15 #include "base/file_util.h" 13 #include "base/file_util.h"
16 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
17 #include "base/path_service.h" 15 #include "base/path_service.h"
18 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
19 #include "base/string_util.h" 17 #include "base/string_util.h"
20 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
(...skipping 28 matching lines...) Expand all
49 47
50 // A dictionary pref that maps usernames to file paths to their wallpapers. 48 // A dictionary pref that maps usernames to file paths to their wallpapers.
51 // Deprecated. Will remove this const char after done migration. 49 // Deprecated. Will remove this const char after done migration.
52 const char kUserWallpapers[] = "UserWallpapers"; 50 const char kUserWallpapers[] = "UserWallpapers";
53 51
54 const int kThumbnailWidth = 128; 52 const int kThumbnailWidth = 128;
55 const int kThumbnailHeight = 80; 53 const int kThumbnailHeight = 80;
56 54
57 const int kCacheWallpaperDelayMs = 500; 55 const int kCacheWallpaperDelayMs = 500;
58 56
59 // Default wallpaper index used in OOBE (first boot).
60 // Defined here because Chromium default index differs.
61 // Also see ash::WallpaperInfo kDefaultWallpapers in
62 // desktop_background_resources.cc
63 #if defined(GOOGLE_CHROME_BUILD)
64 const int kDefaultOOBEWallpaperIndex = 1; // IDR_AURA_WALLPAPERS_2_LANDSCAPE8
65 #else
66 const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_5_GRADIENT5
67 #endif
68
69 // A dictionary pref that maps usernames to wallpaper properties. 57 // A dictionary pref that maps usernames to wallpaper properties.
70 const char kUserWallpapersProperties[] = "UserWallpapersProperties"; 58 const char kUserWallpapersProperties[] = "UserWallpapersProperties";
71 59
72 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| 60 // Names of nodes with info about wallpaper in |kUserWallpapersProperties|
73 // dictionary. 61 // dictionary.
74 const char kNewWallpaperDateNodeName[] = "date"; 62 const char kNewWallpaperDateNodeName[] = "date";
75 const char kNewWallpaperLayoutNodeName[] = "layout"; 63 const char kNewWallpaperLayoutNodeName[] = "layout";
76 const char kNewWallpaperFileNodeName[] = "file"; 64 const char kNewWallpaperFileNodeName[] = "file";
77 const char kNewWallpaperTypeNodeName[] = "type"; 65 const char kNewWallpaperTypeNodeName[] = "type";
78 66
(...skipping 28 matching lines...) Expand all
107 95
108 // static 96 // static
109 WallpaperManager* WallpaperManager::Get() { 97 WallpaperManager* WallpaperManager::Get() {
110 if (!g_wallpaper_manager) 98 if (!g_wallpaper_manager)
111 g_wallpaper_manager = new WallpaperManager(); 99 g_wallpaper_manager = new WallpaperManager();
112 return g_wallpaper_manager; 100 return g_wallpaper_manager;
113 } 101 }
114 102
115 WallpaperManager::WallpaperManager() 103 WallpaperManager::WallpaperManager()
116 : loaded_wallpapers_(0), 104 : loaded_wallpapers_(0),
117 ALLOW_THIS_IN_INITIALIZER_LIST(current_default_wallpaper_index_(
118 ash::GetInvalidWallpaperIndex())),
119 ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_( 105 ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(
120 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))), 106 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))),
121 should_cache_wallpaper_(false), 107 should_cache_wallpaper_(false),
122 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 108 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
123 RestartTimer(); 109 RestartTimer();
124 registrar_.Add(this, 110 registrar_.Add(this,
125 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 111 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
126 content::NotificationService::AllSources()); 112 content::NotificationService::AllSources());
127 registrar_.Add(this, 113 registrar_.Add(this,
128 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE, 114 chrome::NOTIFICATION_LOGIN_WEBUI_VISIBLE,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return (*it).second; 191 return (*it).second;
206 else 192 else
207 return gfx::ImageSkia(); 193 return gfx::ImageSkia();
208 } 194 }
209 195
210 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) { 196 bool WallpaperManager::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
212 198
213 if (UserManager::Get()->IsLoggedInAsStub()) { 199 if (UserManager::Get()->IsLoggedInAsStub()) {
214 info->file = current_user_wallpaper_info_.file = ""; 200 info->file = current_user_wallpaper_info_.file = "";
215 info->layout = current_user_wallpaper_info_.layout = ash::CENTER_CROPPED; 201 info->layout = current_user_wallpaper_info_.layout =
202 ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
216 info->type = current_user_wallpaper_info_.type = User::DEFAULT; 203 info->type = current_user_wallpaper_info_.type = User::DEFAULT;
217 return true; 204 return true;
218 } 205 }
219 206
220 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), 207 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(),
221 info); 208 info);
222 } 209 }
223 210
224 void WallpaperManager::InitializeWallpaper() { 211 void WallpaperManager::InitializeWallpaper() {
225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 11 matching lines...) Expand all
237 } 224 }
238 225
239 bool disable_new_oobe = CommandLine::ForCurrentProcess()-> 226 bool disable_new_oobe = CommandLine::ForCurrentProcess()->
240 HasSwitch(switches::kDisableNewOobe); 227 HasSwitch(switches::kDisableNewOobe);
241 bool disable_boot_animation = CommandLine::ForCurrentProcess()-> 228 bool disable_boot_animation = CommandLine::ForCurrentProcess()->
242 HasSwitch(switches::kDisableBootAnimation); 229 HasSwitch(switches::kDisableBootAnimation);
243 230
244 if (!user_manager->IsUserLoggedIn()) { 231 if (!user_manager->IsUserLoggedIn()) {
245 if (!disable_new_oobe) { 232 if (!disable_new_oobe) {
246 if (!WizardController::IsDeviceRegistered()) { 233 if (!WizardController::IsDeviceRegistered()) {
247 SetDefaultWallpaper(kDefaultOOBEWallpaperIndex); 234 SetDefaultWallpaper();
248 } else { 235 } else {
249 bool show_users = true; 236 bool show_users = true;
250 bool result = CrosSettings::Get()->GetBoolean( 237 bool result = CrosSettings::Get()->GetBoolean(
251 kAccountsPrefShowUserNamesOnSignIn, &show_users); 238 kAccountsPrefShowUserNamesOnSignIn, &show_users);
252 DCHECK(result) << "Unable to fetch setting " 239 DCHECK(result) << "Unable to fetch setting "
253 << kAccountsPrefShowUserNamesOnSignIn; 240 << kAccountsPrefShowUserNamesOnSignIn;
254 const chromeos::UserList& users = user_manager->GetUsers(); 241 const chromeos::UserList& users = user_manager->GetUsers();
255 if (!show_users || users.empty()) { 242 if (!show_users || users.empty()) {
256 // Boot into sign in form, preload default wallpaper. 243 // Boot into sign in form, preload default wallpaper.
257 SetDefaultWallpaper(kDefaultOOBEWallpaperIndex); 244 SetDefaultWallpaper();
258 return; 245 return;
259 } 246 }
260 247
261 if (!disable_boot_animation) { 248 if (!disable_boot_animation) {
262 // Normal boot, load user wallpaper. 249 // Normal boot, load user wallpaper.
263 // If normal boot animation is disabled wallpaper would be set 250 // If normal boot animation is disabled wallpaper would be set
264 // asynchronously once user pods are loaded. 251 // asynchronously once user pods are loaded.
265 SetUserWallpaper(users[0]->email()); 252 SetUserWallpaper(users[0]->email());
266 } 253 }
267 } 254 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 const FilePath& path, 309 const FilePath& path,
323 ash::WallpaperLayout layout, 310 ash::WallpaperLayout layout,
324 int preferred_width, 311 int preferred_width,
325 int preferred_height) { 312 int preferred_height) {
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
327 int width = wallpaper.image().width(); 314 int width = wallpaper.image().width();
328 int height = wallpaper.image().height(); 315 int height = wallpaper.image().height();
329 int resized_width; 316 int resized_width;
330 int resized_height; 317 int resized_height;
331 318
332 if (layout == ash::CENTER_CROPPED) { 319 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) {
333 // Do not resize custom wallpaper if it is smaller than preferred size. 320 // Do not resize custom wallpaper if it is smaller than preferred size.
334 if (!(width > preferred_width && height > preferred_height)) 321 if (!(width > preferred_width && height > preferred_height))
335 return; 322 return;
336 323
337 double horizontal_ratio = static_cast<double>(preferred_width) / width; 324 double horizontal_ratio = static_cast<double>(preferred_width) / width;
338 double vertical_ratio = static_cast<double>(preferred_height) / height; 325 double vertical_ratio = static_cast<double>(preferred_height) / height;
339 if (vertical_ratio > horizontal_ratio) { 326 if (vertical_ratio > horizontal_ratio) {
340 resized_width = 327 resized_width =
341 RoundPositive(static_cast<double>(width) * vertical_ratio); 328 RoundPositive(static_cast<double>(width) * vertical_ratio);
342 resized_height = preferred_height; 329 resized_height = preferred_height;
343 } else { 330 } else {
344 resized_width = preferred_width; 331 resized_width = preferred_width;
345 resized_height = 332 resized_height =
346 RoundPositive(static_cast<double>(height) * horizontal_ratio); 333 RoundPositive(static_cast<double>(height) * horizontal_ratio);
347 } 334 }
348 } else if (layout == ash::STRETCH) { 335 } else if (layout == ash::WALLPAPER_LAYOUT_STRETCH) {
349 resized_width = preferred_width; 336 resized_width = preferred_width;
350 resized_height = preferred_height; 337 resized_height = preferred_height;
351 } else { 338 } else {
352 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. 339 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
353 if (file_util::PathExists(path)) 340 if (file_util::PathExists(path))
354 file_util::Delete(path, false); 341 file_util::Delete(path, false);
355 return; 342 return;
356 } 343 }
357 344
358 gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage( 345 gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 User::WallpaperType type, 386 User::WallpaperType type,
400 const UserImage& wallpaper) { 387 const UserImage& wallpaper) {
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
402 389
403 std::string wallpaper_path = 390 std::string wallpaper_path =
404 GetOriginalWallpaperPathForUser(username).value(); 391 GetOriginalWallpaperPathForUser(username).value();
405 392
406 // If decoded wallpaper is empty, we are probably failed to decode the file. 393 // If decoded wallpaper is empty, we are probably failed to decode the file.
407 // Use default wallpaper in this case. 394 // Use default wallpaper in this case.
408 if (wallpaper.image().isNull()) { 395 if (wallpaper.image().isNull()) {
409 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); 396 SetDefaultWallpaper();
410 return; 397 return;
411 } 398 }
412 399
413 bool is_persistent = ShouldPersistDataForUser(username); 400 bool is_persistent = ShouldPersistDataForUser(username);
414 401
415 wallpaper.image().EnsureRepsForSupportedScaleFactors(); 402 wallpaper.image().EnsureRepsForSupportedScaleFactors();
416 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); 403 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy());
417 404
418 WallpaperInfo wallpaper_info = { 405 WallpaperInfo wallpaper_info = {
419 wallpaper_path, 406 wallpaper_path,
(...skipping 21 matching lines...) Expand all
441 // DUMMY as file name here. 428 // DUMMY as file name here.
442 WallpaperInfo info = { 429 WallpaperInfo info = {
443 "DUMMY", 430 "DUMMY",
444 layout, 431 layout,
445 User::CUSTOMIZED, 432 User::CUSTOMIZED,
446 base::Time::Now().LocalMidnight() 433 base::Time::Now().LocalMidnight()
447 }; 434 };
448 SetUserWallpaperInfo(username, info, is_persistent); 435 SetUserWallpaperInfo(username, info, is_persistent);
449 } 436 }
450 437
451 void WallpaperManager::SetDefaultWallpaper(int index) { 438 void WallpaperManager::SetDefaultWallpaper() {
439 ash::DesktopBackgroundController* controller =
440 ash::Shell::GetInstance()->desktop_background_controller();
441 ash::WallpaperResolution resolution = controller->GetAppropriateResolution();
442 ash::WallpaperInfo info;
443 if (UserManager::Get()->IsLoggedInAsGuest()) {
444 info = (resolution == ash::WALLPAPER_RESOLUTION_LARGE) ?
445 ash::kGuestLargeWallpaper : ash::kGuestSmallWallpaper;
446 } else {
447 info = (resolution == ash::WALLPAPER_RESOLUTION_LARGE) ?
448 ash::kDefaultLargeWallpaper : ash::kDefaultSmallWallpaper;
449 }
450
452 // Prevents loading of the same wallpaper as the currently loading/loaded one. 451 // Prevents loading of the same wallpaper as the currently loading/loaded one.
453 if (current_default_wallpaper_index_ == index) 452 if (controller->GetWallpaperIDR() == info.idr)
454 return; 453 return;
455 current_default_wallpaper_index_ = index; 454
456 current_wallpaper_path_ = FilePath(""); 455 current_wallpaper_path_ = FilePath("");
457 loaded_wallpapers_++; 456 loaded_wallpapers_++;
458 ash::Shell::GetInstance()->desktop_background_controller()-> 457 controller->SetDefaultWallpaper(info);
459 SetDefaultWallpaper(index);
460 } 458 }
461 459
462 void WallpaperManager::SetInitialUserWallpaper(const std::string& username, 460 void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
463 bool is_persistent) { 461 bool is_persistent) {
464 current_user_wallpaper_info_.file = ""; 462 current_user_wallpaper_info_.file = "";
465 current_user_wallpaper_info_.layout = ash::CENTER_CROPPED; 463 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
466 current_user_wallpaper_info_.type = User::DEFAULT; 464 current_user_wallpaper_info_.type = User::DEFAULT;
467 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); 465 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight();
468 466
469 WallpaperInfo info = current_user_wallpaper_info_; 467 WallpaperInfo info = current_user_wallpaper_info_;
470 SetUserWallpaperInfo(username, info, is_persistent); 468 SetUserWallpaperInfo(username, info, is_persistent);
471 469
472 // Some browser tests do not have shell instance. And it is not necessary to 470 // Some browser tests do not have shell instance. And it is not necessary to
473 // create a wallpaper for these tests. Add HasInstance check to prevent tests 471 // create a wallpaper for these tests. Add HasInstance check to prevent tests
474 // crash and speed up the tests by avoid loading wallpaper. 472 // crash and speed up the tests by avoid loading wallpaper.
475 if (ash::Shell::HasInstance()) { 473 if (ash::Shell::HasInstance())
476 if (username == kGuestUser) 474 SetDefaultWallpaper();
477 SetDefaultWallpaper(ash::GetGuestWallpaperIndex());
478 else
479 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
480 }
481 } 475 }
482 476
483 void WallpaperManager::SetUserWallpaperInfo(const std::string& username, 477 void WallpaperManager::SetUserWallpaperInfo(const std::string& username,
484 const WallpaperInfo& info, 478 const WallpaperInfo& info,
485 bool is_persistent) { 479 bool is_persistent) {
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
487 current_user_wallpaper_info_ = info; 481 current_user_wallpaper_info_ = info;
488 if (!is_persistent) 482 if (!is_persistent)
489 return; 483 return;
490 484
(...skipping 11 matching lines...) Expand all
502 } 496 }
503 497
504 void WallpaperManager::SetLastSelectedUser( 498 void WallpaperManager::SetLastSelectedUser(
505 const std::string& last_selected_user) { 499 const std::string& last_selected_user) {
506 last_selected_user_ = last_selected_user; 500 last_selected_user_ = last_selected_user;
507 } 501 }
508 502
509 void WallpaperManager::SetUserWallpaper(const std::string& email) { 503 void WallpaperManager::SetUserWallpaper(const std::string& email) {
510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
511 if (email == kGuestUser) { 505 if (email == kGuestUser) {
512 SetDefaultWallpaper(ash::GetGuestWallpaperIndex()); 506 SetDefaultWallpaper();
513 return; 507 return;
514 } 508 }
515 509
516 if (!UserManager::Get()->IsKnownUser(email)) 510 if (!UserManager::Get()->IsKnownUser(email))
517 return; 511 return;
518 512
519 SetLastSelectedUser(email); 513 SetLastSelectedUser(email);
520 514
521 WallpaperInfo info; 515 WallpaperInfo info;
522 516
523 if (GetUserWallpaperInfo(email, &info)) { 517 if (GetUserWallpaperInfo(email, &info)) {
524 gfx::ImageSkia user_wallpaper; 518 gfx::ImageSkia user_wallpaper;
525 if (GetWallpaperFromCache(email, &user_wallpaper)) { 519 if (GetWallpaperFromCache(email, &user_wallpaper)) {
526 ash::Shell::GetInstance()->desktop_background_controller()-> 520 ash::Shell::GetInstance()->desktop_background_controller()->
527 SetCustomWallpaper(user_wallpaper, info.layout); 521 SetCustomWallpaper(user_wallpaper, info.layout);
528 } else { 522 } else {
529 if (info.type == User::CUSTOMIZED) { 523 if (info.type == User::CUSTOMIZED) {
530 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 524 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
531 desktop_background_controller()->GetAppropriateResolution(); 525 desktop_background_controller()->GetAppropriateResolution();
532 bool is_small = (resolution == ash::SMALL); 526 bool is_small = (resolution == ash::WALLPAPER_RESOLUTION_SMALL);
533 FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small); 527 FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small);
534 if (current_wallpaper_path_ == wallpaper_path) 528 if (current_wallpaper_path_ == wallpaper_path)
535 return; 529 return;
536 current_wallpaper_path_ = wallpaper_path; 530 current_wallpaper_path_ = wallpaper_path;
537 current_default_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
538 loaded_wallpapers_++; 531 loaded_wallpapers_++;
539 532
540 BrowserThread::PostTask( 533 BrowserThread::PostTask(
541 BrowserThread::FILE, FROM_HERE, 534 BrowserThread::FILE, FROM_HERE,
542 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 535 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
543 base::Unretained(this), email, info, wallpaper_path, 536 base::Unretained(this), email, info, wallpaper_path,
544 true /* update wallpaper */)); 537 true /* update wallpaper */));
545 return; 538 return;
546 } 539 }
547 540
548 if (info.file.empty()) { 541 if (info.file.empty()) {
549 // Uses default built-in wallpaper when file is empty. Eventually, we 542 // Uses default built-in wallpaper when file is empty. Eventually, we
550 // will only ship one built-in wallpaper in ChromeOS image. 543 // will only ship one built-in wallpaper in ChromeOS image.
551 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); 544 SetDefaultWallpaper();
552 return; 545 return;
553 } 546 }
554 547
555 // Load downloaded ONLINE or converted DEFAULT wallpapers. 548 // Load downloaded ONLINE or converted DEFAULT wallpapers.
556 LoadWallpaper(email, info, true /* update wallpaper */); 549 LoadWallpaper(email, info, true /* update wallpaper */);
557 } 550 }
558 } else { 551 } else {
559 SetInitialUserWallpaper(email, true); 552 SetInitialUserWallpaper(email, true);
560 } 553 }
561 } 554 }
562 555
563 void WallpaperManager::SetSigninWallpaper() {
564 SetDefaultWallpaper(kDefaultOOBEWallpaperIndex);
565 }
566
567 void WallpaperManager::SetWallpaperFromImageSkia( 556 void WallpaperManager::SetWallpaperFromImageSkia(
568 const gfx::ImageSkia& wallpaper, 557 const gfx::ImageSkia& wallpaper,
569 ash::WallpaperLayout layout) { 558 ash::WallpaperLayout layout) {
570 ash::Shell::GetInstance()->desktop_background_controller()-> 559 ash::Shell::GetInstance()->desktop_background_controller()->
571 SetCustomWallpaper(wallpaper, layout); 560 SetCustomWallpaper(wallpaper, layout);
572 } 561 }
573 562
574 void WallpaperManager::UpdateWallpaper() { 563 void WallpaperManager::UpdateWallpaper() {
575 ClearWallpaperCache(); 564 ClearWallpaperCache();
576 SetUserWallpaper(last_selected_user_); 565 SetUserWallpaper(last_selected_user_);
(...skipping 30 matching lines...) Expand all
607 void WallpaperManager::CacheUserWallpaper(const std::string& email) { 596 void WallpaperManager::CacheUserWallpaper(const std::string& email) {
608 if (wallpaper_cache_.find(email) == wallpaper_cache_.end()) 597 if (wallpaper_cache_.find(email) == wallpaper_cache_.end())
609 return; 598 return;
610 WallpaperInfo info; 599 WallpaperInfo info;
611 if (GetUserWallpaperInfo(email, &info)) { 600 if (GetUserWallpaperInfo(email, &info)) {
612 FilePath wallpaper_dir; 601 FilePath wallpaper_dir;
613 FilePath wallpaper_path; 602 FilePath wallpaper_path;
614 if (info.type == User::CUSTOMIZED) { 603 if (info.type == User::CUSTOMIZED) {
615 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 604 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
616 desktop_background_controller()->GetAppropriateResolution(); 605 desktop_background_controller()->GetAppropriateResolution();
617 bool is_small = (resolution == ash::SMALL); 606 bool is_small = (resolution == ash::WALLPAPER_RESOLUTION_SMALL);
618 FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small); 607 FilePath wallpaper_path = GetWallpaperPathForUser(email, is_small);
619 BrowserThread::PostTask( 608 BrowserThread::PostTask(
620 BrowserThread::FILE, FROM_HERE, 609 BrowserThread::FILE, FROM_HERE,
621 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, 610 base::Bind(&WallpaperManager::GetCustomWallpaperInternal,
622 base::Unretained(this), email, info, wallpaper_path, 611 base::Unretained(this), email, info, wallpaper_path,
623 false /* do not update wallpaper */)); 612 false /* do not update wallpaper */));
624 return; 613 return;
625 } 614 }
626 LoadWallpaper(email, info, false /* do not update wallpaper */); 615 LoadWallpaper(email, info, false /* do not update wallpaper */);
627 } 616 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 const WallpaperInfo& info, 673 const WallpaperInfo& info,
685 bool update_wallpaper) { 674 bool update_wallpaper) {
686 FilePath wallpaper_dir; 675 FilePath wallpaper_dir;
687 FilePath wallpaper_path; 676 FilePath wallpaper_path;
688 if (info.type == User::ONLINE) { 677 if (info.type == User::ONLINE) {
689 std::string file_name = GURL(info.file).ExtractFileName(); 678 std::string file_name = GURL(info.file).ExtractFileName();
690 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> 679 ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
691 desktop_background_controller()->GetAppropriateResolution(); 680 desktop_background_controller()->GetAppropriateResolution();
692 // Only solid color wallpapers have stretch layout and they have only one 681 // Only solid color wallpapers have stretch layout and they have only one
693 // resolution. 682 // resolution.
694 if (info.layout != ash::STRETCH && resolution == ash::SMALL) { 683 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH &&
684 resolution == ash::WALLPAPER_RESOLUTION_SMALL) {
695 file_name = FilePath(file_name).InsertBeforeExtension( 685 file_name = FilePath(file_name).InsertBeforeExtension(
696 kSmallWallpaperSuffix).value(); 686 kSmallWallpaperSuffix).value();
697 } 687 }
698 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 688 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
699 wallpaper_path = wallpaper_dir.Append(file_name); 689 wallpaper_path = wallpaper_dir.Append(file_name);
700 if (current_wallpaper_path_ == wallpaper_path) 690 if (current_wallpaper_path_ == wallpaper_path)
701 return; 691 return;
702 if (update_wallpaper) { 692 if (update_wallpaper)
703 current_wallpaper_path_ = wallpaper_path; 693 current_wallpaper_path_ = wallpaper_path;
704 current_default_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
705 }
706 loaded_wallpapers_++; 694 loaded_wallpapers_++;
707 StartLoad(email, info, update_wallpaper, wallpaper_path); 695 StartLoad(email, info, update_wallpaper, wallpaper_path);
708 } else { 696 } else {
709 // For custom wallpapers, we have increment |loaded_wallpapers_| in 697 // For custom wallpapers, we have increment |loaded_wallpapers_| in
710 // SetUserWallpaper(). We should not increment it again here. 698 // SetUserWallpaper(). We should not increment it again here.
711 FilePath user_data_dir; 699 FilePath user_data_dir;
712 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 700 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
713 wallpaper_path = user_data_dir.Append(info.file); 701 wallpaper_path = user_data_dir.Append(info.file);
714 base::WorkerPool::PostTask( 702 base::WorkerPool::PostTask(
715 FROM_HERE, 703 FROM_HERE,
(...skipping 19 matching lines...) Expand all
735 // wallpaper info from memory. Returns true. 723 // wallpaper info from memory. Returns true.
736 return true; 724 return true;
737 } 725 }
738 726
739 const DictionaryValue* user_wallpapers = g_browser_process->local_state()-> 727 const DictionaryValue* user_wallpapers = g_browser_process->local_state()->
740 GetDictionary(prefs::kUsersWallpaperInfo); 728 GetDictionary(prefs::kUsersWallpaperInfo);
741 const base::DictionaryValue* wallpaper_info_dict; 729 const base::DictionaryValue* wallpaper_info_dict;
742 if (user_wallpapers->GetDictionaryWithoutPathExpansion( 730 if (user_wallpapers->GetDictionaryWithoutPathExpansion(
743 email, &wallpaper_info_dict)) { 731 email, &wallpaper_info_dict)) {
744 info->file = ""; 732 info->file = "";
745 info->layout = ash::CENTER_CROPPED; 733 info->layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
746 info->type = User::UNKNOWN; 734 info->type = User::UNKNOWN;
747 info->date = base::Time::Now().LocalMidnight(); 735 info->date = base::Time::Now().LocalMidnight();
748 wallpaper_info_dict->GetString(kNewWallpaperFileNodeName, &(info->file)); 736 wallpaper_info_dict->GetString(kNewWallpaperFileNodeName, &(info->file));
749 int temp; 737 int temp;
750 wallpaper_info_dict->GetInteger(kNewWallpaperLayoutNodeName, &temp); 738 wallpaper_info_dict->GetInteger(kNewWallpaperLayoutNodeName, &temp);
751 info->layout = static_cast<ash::WallpaperLayout>(temp); 739 info->layout = static_cast<ash::WallpaperLayout>(temp);
752 wallpaper_info_dict->GetInteger(kNewWallpaperTypeNodeName, &temp); 740 wallpaper_info_dict->GetInteger(kNewWallpaperTypeNodeName, &temp);
753 info->type = static_cast<User::WallpaperType>(temp); 741 info->type = static_cast<User::WallpaperType>(temp);
754 std::string date_string; 742 std::string date_string;
755 int64 val; 743 int64 val;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 bool update_wallpaper, 797 bool update_wallpaper,
810 const UserImage& wallpaper) { 798 const UserImage& wallpaper) {
811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 799 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
812 800
813 // If decoded wallpaper is empty, we are probably failed to decode the file. 801 // If decoded wallpaper is empty, we are probably failed to decode the file.
814 // Use default wallpaper in this case. 802 // Use default wallpaper in this case.
815 if (wallpaper.image().isNull()) { 803 if (wallpaper.image().isNull()) {
816 // Updates user pref to default wallpaper. 804 // Updates user pref to default wallpaper.
817 WallpaperInfo info = { 805 WallpaperInfo info = {
818 "", 806 "",
819 ash::CENTER_CROPPED, 807 ash::WALLPAPER_LAYOUT_CENTER_CROPPED,
820 User::DEFAULT, 808 User::DEFAULT,
821 base::Time::Now().LocalMidnight() 809 base::Time::Now().LocalMidnight()
822 }; 810 };
823 SetUserWallpaperInfo(email, info, true); 811 SetUserWallpaperInfo(email, info, true);
824 812
825 if (update_wallpaper) { 813 if (update_wallpaper)
826 SetDefaultWallpaper(ash::GetDefaultWallpaperIndex()); 814 SetDefaultWallpaper();
827 } else {
828 ash::Shell::GetInstance()->desktop_background_controller()->
829 CacheDefaultWallpaper(ash::GetDefaultWallpaperIndex());
830 }
831 return; 815 return;
832 } 816 }
833 // Generate all reps before passing to another thread. 817 // Generate all reps before passing to another thread.
834 wallpaper.image().EnsureRepsForSupportedScaleFactors(); 818 wallpaper.image().EnsureRepsForSupportedScaleFactors();
835 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); 819 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy());
836 820
837 BrowserThread::PostTask( 821 BrowserThread::PostTask(
838 BrowserThread::FILE, 822 BrowserThread::FILE,
839 FROM_HERE, 823 FROM_HERE,
840 base::Bind(&WallpaperManager::CacheThumbnail, 824 base::Bind(&WallpaperManager::CacheThumbnail,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 ash::kSmallWallpaperMaxWidth, 875 ash::kSmallWallpaperMaxWidth,
892 ash::kSmallWallpaperMaxHeight); 876 ash::kSmallWallpaperMaxHeight);
893 ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout, 877 ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout,
894 ash::kLargeWallpaperMaxWidth, 878 ash::kLargeWallpaperMaxWidth,
895 ash::kLargeWallpaperMaxHeight); 879 ash::kLargeWallpaperMaxHeight);
896 } 880 }
897 881
898 void WallpaperManager::RecordUma(User::WallpaperType type, int index) { 882 void WallpaperManager::RecordUma(User::WallpaperType type, int index) {
899 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, 883 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type,
900 User::WALLPAPER_TYPE_COUNT); 884 User::WALLPAPER_TYPE_COUNT);
901 if (type == User::DEFAULT) {
902 if (index >= 0) {
903 // TODO(sschmitz): Remove "if" when the index for new UI is available.
904 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.DefaultIndex", index,
905 ash::GetWallpaperCount());
906 }
907 }
908 } 885 }
909 886
910 void WallpaperManager::SaveWallpaperInternal(const FilePath& path, 887 void WallpaperManager::SaveWallpaperInternal(const FilePath& path,
911 const char* data, 888 const char* data,
912 int size) { 889 int size) {
913 int written_bytes = file_util::WriteFile(path, data, size); 890 int written_bytes = file_util::WriteFile(path, data, size);
914 DCHECK(written_bytes == size); 891 DCHECK(written_bytes == size);
915 } 892 }
916 893
917 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) { 894 bool WallpaperManager::ShouldPersistDataForUser(const std::string& email) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 FROM_HERE, 935 FROM_HERE,
959 base::Bind(&WallpaperManager::StartLoad, 936 base::Bind(&WallpaperManager::StartLoad,
960 base::Unretained(this), 937 base::Unretained(this),
961 email, 938 email,
962 info, 939 info,
963 update_wallpaper, 940 update_wallpaper,
964 valid_path)); 941 valid_path));
965 } 942 }
966 943
967 } // chromeos 944 } // chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698