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

Side by Side Diff: chrome/browser/chromeos/background/desktop_background_observer.cc

Issue 9764012: Restore to user selected wallpaper after browser crash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to trunk Created 8 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 | 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/background/desktop_background_observer.h" 5 #include "chrome/browser/chromeos/background/desktop_background_observer.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/desktop_background/desktop_background_controller.h" 8 #include "ash/desktop_background/desktop_background_controller.h"
9 #include "ash/desktop_background/desktop_background_resources.h" 9 #include "ash/desktop_background/desktop_background_resources.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chrome/browser/chromeos/login/user_manager.h" 11 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
14 14
15 namespace chromeos { 15 namespace chromeos {
16 16
17 namespace {
18
19 class UserWallpaperDelegate: public ash::UserWallpaperDelegate {
20 public:
21 explicit UserWallpaperDelegate() {
flackr 2012/03/22 03:19:10 Only use explicit for single argument constructors
bshe 2012/03/22 05:21:16 Done.
22 }
23
24 virtual ~UserWallpaperDelegate() {
25 }
26
27 virtual const int GetUserWallpaperIndex() OVERRIDE{
Ben Goodger (Google) 2012/03/22 03:23:16 nit: space before {
bshe 2012/03/22 05:21:16 Done.
28 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
29 // If at login screen or logged in as a guest/incognito user, then use the
30 // default wallpaper.
31 if (user_manager->IsLoggedInAsGuest() || !user_manager->IsUserLoggedIn())
32 return ash::GetDefaultWallpaperIndex();
33
34 const chromeos::User& user = user_manager->GetLoggedInUser();
35 DCHECK(!user.email().empty());
36 int index = user_manager->GetUserWallpaper(user.email());
37 DCHECK(index >=0 && index < ash::GetWallpaperCount());
38 return index;
39 }
40 };
Ben Goodger (Google) 2012/03/22 03:23:16 private: DISALLOW_COPY_AND...
bshe 2012/03/22 05:21:16 Done.
41
42 } // namespace
43
44 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
45 return new chromeos::UserWallpaperDelegate();
46 }
47
17 DesktopBackgroundObserver::DesktopBackgroundObserver() { 48 DesktopBackgroundObserver::DesktopBackgroundObserver() {
18 registrar_.Add( 49 registrar_.Add(
19 this, 50 this,
20 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 51 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
21 content::NotificationService::AllSources()); 52 content::NotificationService::AllSources());
22 } 53 }
23 54
24 DesktopBackgroundObserver::~DesktopBackgroundObserver() { 55 DesktopBackgroundObserver::~DesktopBackgroundObserver() {
25 } 56 }
26 57
27 int DesktopBackgroundObserver::GetUserWallpaperIndex() {
28 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
29 // Guest/incognito user do not have an email address.
30 if (user_manager->IsLoggedInAsGuest())
31 return ash::GetDefaultWallpaperIndex();
32 const chromeos::User& user = user_manager->GetLoggedInUser();
33 DCHECK(!user.email().empty());
34 int index = user_manager->GetUserWallpaper(user.email());
35 DCHECK(index >=0 && index < ash::GetWallpaperCount());
36 return index;
37 }
38
39 void DesktopBackgroundObserver::Observe(int type, 58 void DesktopBackgroundObserver::Observe(int type,
40 const content::NotificationSource& source, 59 const content::NotificationSource& source,
41 const content::NotificationDetails& details) { 60 const content::NotificationDetails& details) {
42 switch (type) { 61 switch (type) {
43 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { 62 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
44 ash::Shell::GetInstance()->desktop_background_controller()-> 63 ash::Shell::GetInstance()->desktop_background_controller()->
45 OnDesktopBackgroundChanged(GetUserWallpaperIndex()); 64 OnDesktopBackgroundChanged();
46 break; 65 break;
47 } 66 }
48 default: 67 default:
49 NOTREACHED(); 68 NOTREACHED();
50 } 69 }
51 } 70 }
52 71
53 } // namespace chromeos 72 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/background/desktop_background_observer.h ('k') | chrome/browser/chromeos/login/user_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698