| 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/ui/webui/options2/chromeos/set_wallpaper_options_handle
r2.h" | 5 #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle
r2.h" |
| 6 | 6 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" |
| 7 #include "ash/desktop_background/desktop_background_resources.h" | 8 #include "ash/desktop_background/desktop_background_resources.h" |
| 9 #include "ash/shell.h" |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 10 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 12 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" | 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 81 |
| 80 void SetWallpaperOptionsHandler::HandlePageInitialized( | 82 void SetWallpaperOptionsHandler::HandlePageInitialized( |
| 81 const base::ListValue* args) { | 83 const base::ListValue* args) { |
| 82 DCHECK(args && args->empty()); | 84 DCHECK(args && args->empty()); |
| 83 | 85 |
| 84 SendDefaultImages(); | 86 SendDefaultImages(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { | 89 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { |
| 88 DCHECK(args && args->empty()); | 90 DCHECK(args && args->empty()); |
| 89 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 91 int index = chromeos::UserManager::Get()->GetUserWallpaperIndex(); |
| 90 const chromeos::User& user = user_manager->GetLoggedInUser(); | |
| 91 DCHECK(!user.email().empty()); | |
| 92 int index = user_manager->GetUserWallpaper(user.email()); | |
| 93 DCHECK(index >=0 && index < ash::GetWallpaperCount()); | |
| 94 base::FundamentalValue index_value(index); | 92 base::FundamentalValue index_value(index); |
| 95 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", | 93 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", |
| 96 index_value); | 94 index_value); |
| 97 } | 95 } |
| 98 | 96 |
| 99 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) { | 97 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) { |
| 100 std::string image_index_string; | 98 std::string image_index_string; |
| 101 int image_index; | 99 int image_index; |
| 102 if (!args || | 100 if (!args || |
| 103 args->GetSize() != 1 || | 101 args->GetSize() != 1 || |
| 104 !args->GetString(0, &image_index_string) || | 102 !args->GetString(0, &image_index_string) || |
| 105 !base::StringToInt(image_index_string, &image_index) || | 103 !base::StringToInt(image_index_string, &image_index) || |
| 106 image_index < 0 || image_index >= ash::GetWallpaperCount()) | 104 image_index < 0 || image_index >= ash::GetWallpaperCount()) |
| 107 NOTREACHED(); | 105 NOTREACHED(); |
| 108 | 106 |
| 109 UserManager* user_manager = UserManager::Get(); | 107 UserManager::Get()->SaveUserWallpaperIndex(image_index); |
| 110 const User& user = user_manager->GetLoggedInUser(); | 108 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 111 DCHECK(!user.email().empty()); | 109 OnDesktopBackgroundChanged(); |
| 112 user_manager->SaveWallpaperDefaultIndex(user.email(), image_index); | |
| 113 } | 110 } |
| 114 | 111 |
| 115 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { | 112 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { |
| 116 Browser* browser = | 113 Browser* browser = |
| 117 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); | 114 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); |
| 118 if (!browser) | 115 if (!browser) |
| 119 return NULL; | 116 return NULL; |
| 120 return browser->window()->GetNativeHandle(); | 117 return browser->window()->GetNativeHandle(); |
| 121 } | 118 } |
| 122 | 119 |
| 123 } // namespace options2 | 120 } // namespace options2 |
| 124 } // namespace chromeos | 121 } // namespace chromeos |
| OLD | NEW |