OLD | NEW |
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 UserWallpaperDelegate() { |
| 22 } |
| 23 |
| 24 virtual ~UserWallpaperDelegate() { |
| 25 } |
| 26 |
| 27 virtual const int GetUserWallpaperIndex() OVERRIDE { |
| 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 |
| 41 private: |
| 42 DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate); |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() { |
| 48 return new chromeos::UserWallpaperDelegate(); |
| 49 } |
| 50 |
17 DesktopBackgroundObserver::DesktopBackgroundObserver() { | 51 DesktopBackgroundObserver::DesktopBackgroundObserver() { |
18 registrar_.Add( | 52 registrar_.Add( |
19 this, | 53 this, |
20 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 54 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
21 content::NotificationService::AllSources()); | 55 content::NotificationService::AllSources()); |
22 } | 56 } |
23 | 57 |
24 DesktopBackgroundObserver::~DesktopBackgroundObserver() { | 58 DesktopBackgroundObserver::~DesktopBackgroundObserver() { |
25 } | 59 } |
26 | 60 |
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, | 61 void DesktopBackgroundObserver::Observe(int type, |
40 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
41 const content::NotificationDetails& details) { | 63 const content::NotificationDetails& details) { |
42 switch (type) { | 64 switch (type) { |
43 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | 65 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
44 ash::Shell::GetInstance()->desktop_background_controller()-> | 66 ash::Shell::GetInstance()->desktop_background_controller()-> |
45 OnDesktopBackgroundChanged(GetUserWallpaperIndex()); | 67 OnDesktopBackgroundChanged(); |
46 break; | 68 break; |
47 } | 69 } |
48 default: | 70 default: |
49 NOTREACHED(); | 71 NOTREACHED(); |
50 } | 72 } |
51 } | 73 } |
52 | 74 |
53 } // namespace chromeos | 75 } // namespace chromeos |
OLD | NEW |