OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/desktop_background/desktop_background_controller.h" | |
6 | |
7 #include "ash/desktop_background/desktop_background_resources.h" | |
8 #include "ash/shell.h" | |
9 #include "base/logging.h" | |
10 #include "chrome/browser/chromeos/login/user_manager.h" | |
11 #include "chrome/common/chrome_notification_types.h" | |
12 #include "content/public/browser/notification_service.h" | |
13 #include "grit/ui_resources.h" | |
14 #include "ui/gfx/image/image.h" | |
15 #include "ui/base/resource/resource_bundle.h" | |
16 | |
17 namespace ash { | |
18 | |
19 DesktopBackgroundController::DesktopBackgroundController(){ | |
20 registrar_.Add( | |
21 this, | |
22 chrome::NOTIFICATION_DESKTOP_BACKGROUND_CHANGED, | |
23 content::NotificationService::AllSources()); | |
24 registrar_.Add( | |
25 this, | |
26 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | |
27 content::NotificationService::AllSources()); | |
28 } | |
29 | |
30 DesktopBackgroundController::~DesktopBackgroundController() { | |
31 } | |
32 | |
33 void DesktopBackgroundController::OnDesktopBackgroundChange( | |
34 const SkBitmap& wallpaper) { | |
35 Shell::GetInstance()->SetDesktopBackgroundWallpaper( | |
36 wallpaper); | |
flackr
2012/03/07 20:50:28
Does this fit on the previous line?
bshe
2012/03/07 23:48:35
Done.
| |
37 } | |
38 | |
39 const SkBitmap& DesktopBackgroundController::GetPresetWallpaper() { | |
40 return GetDefaultWallpaper(kPresetWallpaperIndex); | |
41 } | |
42 | |
43 const SkBitmap& DesktopBackgroundController::GetUserWallpaper() { | |
44 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | |
45 const chromeos::User& user = user_manager->logged_in_user(); | |
46 int index = user_manager->GetUserWallpaper(user.email()); | |
47 DCHECK(index >=0 && index < kDefaultWallpaperCount); | |
48 return GetDefaultWallpaper(index); | |
49 } | |
50 | |
51 void DesktopBackgroundController::Observe(int type, | |
52 const content::NotificationSource& source, | |
53 const content::NotificationDetails& details) { | |
54 switch (type) { | |
55 case chrome::NOTIFICATION_DESKTOP_BACKGROUND_CHANGED: { | |
56 int index = *content::Details<int>(details).ptr(); | |
57 OnDesktopBackgroundChange(GetDefaultWallpaper(index)); | |
58 break; | |
59 } | |
60 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { | |
61 OnDesktopBackgroundChange(GetUserWallpaper()); | |
62 break; | |
63 } | |
64 default: | |
65 NOTREACHED(); | |
66 } | |
67 } | |
68 | |
69 } // namespace ash | |
OLD | NEW |