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

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

Issue 1010443003: Make the lifetime of wallpaper manager more clear. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Oshima's comments. Created 5 years, 9 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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 using content::BrowserThread; 57 using content::BrowserThread;
58 using wallpaper::WallpaperManagerBase; 58 using wallpaper::WallpaperManagerBase;
59 using wallpaper::WallpaperInfo; 59 using wallpaper::WallpaperInfo;
60 using wallpaper::MovableOnDestroyCallback; 60 using wallpaper::MovableOnDestroyCallback;
61 using wallpaper::MovableOnDestroyCallbackHolder; 61 using wallpaper::MovableOnDestroyCallbackHolder;
62 62
63 namespace chromeos { 63 namespace chromeos {
64 64
65 namespace { 65 namespace {
66 66
67 WallpaperManager* wallpaper_manager = nullptr;
68
67 // The amount of delay before starts to move custom wallpapers to the new place. 69 // The amount of delay before starts to move custom wallpapers to the new place.
68 const int kMoveCustomWallpaperDelaySeconds = 30; 70 const int kMoveCustomWallpaperDelaySeconds = 30;
69 71
70 const int kCacheWallpaperDelayMs = 500; 72 const int kCacheWallpaperDelayMs = 500;
71 73
72 // Names of nodes with info about wallpaper in |kUserWallpapersProperties| 74 // Names of nodes with info about wallpaper in |kUserWallpapersProperties|
73 // dictionary. 75 // dictionary.
74 const char kNewWallpaperDateNodeName[] = "date"; 76 const char kNewWallpaperDateNodeName[] = "date";
75 const char kNewWallpaperLayoutNodeName[] = "layout"; 77 const char kNewWallpaperLayoutNodeName[] = "layout";
76 const char kNewWallpaperLocationNodeName[] = "file"; 78 const char kNewWallpaperLocationNodeName[] = "file";
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // image will be loaded. 266 // image will be loaded.
265 wallpaper::MovableOnDestroyCallbackHolder on_finish_; 267 wallpaper::MovableOnDestroyCallbackHolder on_finish_;
266 base::OneShotTimer<WallpaperManager::PendingWallpaper> timer; 268 base::OneShotTimer<WallpaperManager::PendingWallpaper> timer;
267 269
268 // Load start time to calculate duration. 270 // Load start time to calculate duration.
269 base::Time started_load_at_; 271 base::Time started_load_at_;
270 272
271 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper); 273 DISALLOW_COPY_AND_ASSIGN(PendingWallpaper);
272 }; 274 };
273 275
274 static WallpaperManager* g_wallpaper_manager = NULL;
275
276 // WallpaperManager, public: --------------------------------------------------- 276 // WallpaperManager, public: ---------------------------------------------------
277 277
278 // static
279 WallpaperManager* WallpaperManager::Get() {
280 if (!g_wallpaper_manager)
281 g_wallpaper_manager = new WallpaperManager();
282 return g_wallpaper_manager;
283 }
284
285 WallpaperManager::WallpaperManager()
286 : pending_inactive_(NULL), weak_factory_(this) {
287 wallpaper::WallpaperManagerBase::SetPathIds(
288 chrome::DIR_USER_DATA,
289 chrome::DIR_CHROMEOS_WALLPAPERS,
290 chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS);
291 SetDefaultWallpaperPathsFromCommandLine(
292 base::CommandLine::ForCurrentProcess());
293 registrar_.Add(this,
294 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
295 content::NotificationService::AllSources());
296 registrar_.Add(this,
297 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
298 content::NotificationService::AllSources());
299 registrar_.Add(this,
300 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
301 content::NotificationService::AllSources());
302 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
303 wallpaper::kWallpaperSequenceTokenName);
304 task_runner_ = BrowserThread::GetBlockingPool()->
305 GetSequencedTaskRunnerWithShutdownBehavior(
306 sequence_token_,
307 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
308 wallpaper_loader_ = new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC,
309 task_runner_);
310
311 user_manager::UserManager::Get()->AddSessionStateObserver(this);
312 }
313
314 WallpaperManager::~WallpaperManager() { 278 WallpaperManager::~WallpaperManager() {
315 // TODO(bshe): Lifetime of WallpaperManager needs more consideration. 279 show_user_name_on_signin_subscription_.reset();
bshe 2015/03/16 18:45:40 It looks like this reset call make the following D
316 // http://crbug.com/171694
317 DCHECK(!show_user_name_on_signin_subscription_); 280 DCHECK(!show_user_name_on_signin_subscription_);
318 281
319 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); 282 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
320 283
321 ClearObsoleteWallpaperPrefs(); 284 ClearObsoleteWallpaperPrefs();
322 weak_factory_.InvalidateWeakPtrs(); 285 weak_factory_.InvalidateWeakPtrs();
323 } 286 }
324 287
288 // static
289 void WallpaperManager::Initialize() {
290 CHECK(!wallpaper_manager);
291 wallpaper_manager = new WallpaperManager();
292 }
293
294 // static
295 WallpaperManager* WallpaperManager::Get() {
296 DCHECK(wallpaper_manager);
297 return wallpaper_manager;
298 }
299
300 // static
301 void WallpaperManager::Shutdown() {
302 CHECK(wallpaper_manager);
303 delete wallpaper_manager;
304 wallpaper_manager = nullptr;
305 }
306
325 WallpaperManager::WallpaperResolution 307 WallpaperManager::WallpaperResolution
326 WallpaperManager::GetAppropriateResolution() { 308 WallpaperManager::GetAppropriateResolution() {
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
328 gfx::Size size = 310 gfx::Size size =
329 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); 311 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative();
330 return (size.width() > wallpaper::kSmallWallpaperMaxWidth || 312 return (size.width() > wallpaper::kSmallWallpaperMaxWidth ||
331 size.height() > wallpaper::kSmallWallpaperMaxHeight) 313 size.height() > wallpaper::kSmallWallpaperMaxHeight)
332 ? WALLPAPER_RESOLUTION_LARGE 314 ? WALLPAPER_RESOLUTION_LARGE
333 : WALLPAPER_RESOLUTION_SMALL; 315 : WALLPAPER_RESOLUTION_SMALL;
334 } 316 }
335 317
336 void WallpaperManager::Shutdown() {
337 show_user_name_on_signin_subscription_.reset();
338 }
339
340 void WallpaperManager::AddObservers() { 318 void WallpaperManager::AddObservers() {
341 show_user_name_on_signin_subscription_ = 319 show_user_name_on_signin_subscription_ =
342 CrosSettings::Get()->AddSettingsObserver( 320 CrosSettings::Get()->AddSettingsObserver(
343 kAccountsPrefShowUserNamesOnSignIn, 321 kAccountsPrefShowUserNamesOnSignIn,
344 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper, 322 base::Bind(&WallpaperManager::InitializeRegisteredDeviceWallpaper,
345 weak_factory_.GetWeakPtr())); 323 weak_factory_.GetWeakPtr()));
346 } 324 }
347 325
348 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() { 326 void WallpaperManager::EnsureLoggedInUserWallpaperLoaded() {
349 // Some browser tests do not have a shell instance. As no wallpaper is needed 327 // Some browser tests do not have a shell instance. As no wallpaper is needed
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 717
740 if (update_wallpaper) { 718 if (update_wallpaper) {
741 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) 719 GetPendingWallpaper(last_selected_user_, false /* Not delayed */)
742 ->ResetSetWallpaperImage(image, info); 720 ->ResetSetWallpaperImage(image, info);
743 } 721 }
744 } 722 }
745 723
746 724
747 // WallpaperManager, private: -------------------------------------------------- 725 // WallpaperManager, private: --------------------------------------------------
748 726
727 WallpaperManager::WallpaperManager()
728 : pending_inactive_(NULL), weak_factory_(this) {
729 wallpaper::WallpaperManagerBase::SetPathIds(
730 chrome::DIR_USER_DATA, chrome::DIR_CHROMEOS_WALLPAPERS,
731 chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS);
732 SetDefaultWallpaperPathsFromCommandLine(
733 base::CommandLine::ForCurrentProcess());
734 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_CHANGED,
735 content::NotificationService::AllSources());
736 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
737 content::NotificationService::AllSources());
738 registrar_.Add(this, chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
739 content::NotificationService::AllSources());
740 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken(
741 wallpaper::kWallpaperSequenceTokenName);
742 task_runner_ =
743 BrowserThread::GetBlockingPool()
744 ->GetSequencedTaskRunnerWithShutdownBehavior(
745 sequence_token_, base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
746 wallpaper_loader_ =
747 new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC, task_runner_);
748
749 user_manager::UserManager::Get()->AddSessionStateObserver(this);
750 }
751
749 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( 752 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper(
750 const std::string& user_id, 753 const std::string& user_id,
751 bool delayed) { 754 bool delayed) {
752 if (!pending_inactive_) { 755 if (!pending_inactive_) {
753 loading_.push_back(new WallpaperManager::PendingWallpaper( 756 loading_.push_back(new WallpaperManager::PendingWallpaper(
754 (delayed ? GetWallpaperLoadDelay() 757 (delayed ? GetWallpaperLoadDelay()
755 : base::TimeDelta::FromMilliseconds(0)), 758 : base::TimeDelta::FromMilliseconds(0)),
756 user_id)); 759 user_id));
757 pending_inactive_ = loading_.back().get(); 760 pending_inactive_ = loading_.back().get();
758 } 761 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 } 1043 }
1041 } 1044 }
1042 1045
1043 if (need_update_screen) { 1046 if (need_update_screen) {
1044 DoSetDefaultWallpaper(std::string(), 1047 DoSetDefaultWallpaper(std::string(),
1045 MovableOnDestroyCallbackHolder().Pass()); 1048 MovableOnDestroyCallbackHolder().Pass());
1046 } 1049 }
1047 } 1050 }
1048 1051
1049 } // namespace chromeos 1052 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h ('k') | components/wallpaper/wallpaper_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698