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 explicit UserWallpaperDelegate() { |
| 22 } |
| 23 |
| 24 virtual ~UserWallpaperDelegate() { |
| 25 } |
| 26 |
| 27 virtual const int GetUserWallpaperIndex() OVERRIDE{ |
| 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 |
| 33 const chromeos::User& user = user_manager->GetLoggedInUser(); |
| 34 DCHECK(!user.email().empty()); |
| 35 int index = user_manager->GetUserWallpaper(user.email()); |
| 36 DCHECK(index >=0 && index < ash::GetWallpaperCount()); |
| 37 return index; |
| 38 } |
| 39 }; |
| 40 |
| 41 } // namespace |
| 42 |
| 43 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() { |
| 44 return new chromeos::UserWallpaperDelegate(); |
| 45 } |
| 46 |
17 DesktopBackgroundObserver::DesktopBackgroundObserver() { | 47 DesktopBackgroundObserver::DesktopBackgroundObserver() { |
18 registrar_.Add( | 48 registrar_.Add( |
19 this, | 49 this, |
20 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 50 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
21 content::NotificationService::AllSources()); | 51 content::NotificationService::AllSources()); |
22 } | 52 } |
23 | 53 |
24 DesktopBackgroundObserver::~DesktopBackgroundObserver() { | 54 DesktopBackgroundObserver::~DesktopBackgroundObserver() { |
25 } | 55 } |
26 | 56 |
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, | 57 void DesktopBackgroundObserver::Observe(int type, |
40 const content::NotificationSource& source, | 58 const content::NotificationSource& source, |
41 const content::NotificationDetails& details) { | 59 const content::NotificationDetails& details) { |
42 switch (type) { | 60 switch (type) { |
43 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | 61 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { |
44 ash::Shell::GetInstance()->desktop_background_controller()-> | 62 ash::Shell::GetInstance()->desktop_background_controller()-> |
45 OnDesktopBackgroundChanged(GetUserWallpaperIndex()); | 63 OnUserLoginOrSwitchToImageMode(); |
46 break; | 64 break; |
47 } | 65 } |
48 default: | 66 default: |
49 NOTREACHED(); | 67 NOTREACHED(); |
50 } | 68 } |
51 } | 69 } |
52 | 70 |
53 } // namespace chromeos | 71 } // namespace chromeos |
OLD | NEW |