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

Side by Side Diff: chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler.cc

Issue 10832019: Speed up custom wallpaper switching time and wallpaper manager code refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ivan's review Created 8 years, 4 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/ui/webui/options2/chromeos/set_wallpaper_options_handle r.h" 5 #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle r.h"
6 6
7 #include "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
17 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/chrome_select_file_policy.h" 20 #include "chrome/browser/ui/chrome_select_file_policy.h"
20 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source.h " 21 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source.h "
21 #include "chrome/browser/ui/webui/web_ui_util.h" 22 #include "chrome/browser/ui/webui/web_ui_util.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "content/public/browser/web_ui.h" 24 #include "content/public/browser/web_ui.h"
24 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void SetWallpaperOptionsHandler::SetCustomWallpaperThumbnail() { 95 void SetWallpaperOptionsHandler::SetCustomWallpaperThumbnail() {
95 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage"); 96 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage");
96 } 97 }
97 98
98 void SetWallpaperOptionsHandler::FileSelected(const FilePath& path, 99 void SetWallpaperOptionsHandler::FileSelected(const FilePath& path,
99 int index, 100 int index,
100 void* params) { 101 void* params) {
101 UserManager* user_manager = UserManager::Get(); 102 UserManager* user_manager = UserManager::Get();
102 103
103 // Default wallpaper layout is CENTER_CROPPED. 104 // Default wallpaper layout is CENTER_CROPPED.
104 user_manager->SaveUserWallpaperFromFile( 105 WallpaperManager::Get()->SetUserWallpaperFromFile(
105 user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED, 106 user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED,
106 weak_factory_.GetWeakPtr()); 107 weak_factory_.GetWeakPtr());
107 web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile"); 108 web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile");
108 } 109 }
109 110
110 void SetWallpaperOptionsHandler::SendDefaultImages() { 111 void SetWallpaperOptionsHandler::SendDefaultImages() {
111 ListValue images; 112 ListValue images;
112 DictionaryValue* image_detail; 113 DictionaryValue* image_detail;
113 ash::WallpaperInfo image_info; 114 ash::WallpaperInfo image_info;
114 115
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 DCHECK(args && args->empty()); 155 DCHECK(args && args->empty());
155 156
156 SendDefaultImages(); 157 SendDefaultImages();
157 } 158 }
158 159
159 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { 160 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) {
160 DCHECK(args && args->empty()); 161 DCHECK(args && args->empty());
161 User::WallpaperType type; 162 User::WallpaperType type;
162 int index; 163 int index;
163 base::Time date; 164 base::Time date;
164 UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); 165 WallpaperManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index,
Ivan Korotkov 2012/07/31 21:18:16 Maybe move all arguments to the next line?
bshe 2012/08/01 15:07:35 Done.
166 &date);
165 if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { 167 if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) {
166 index = ash::GetNextWallpaperIndex(index); 168 index = ash::GetNextWallpaperIndex(index);
167 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, 169 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY,
168 index); 170 index);
169 ash::Shell::GetInstance()->user_wallpaper_delegate()-> 171 ash::Shell::GetInstance()->user_wallpaper_delegate()->
170 InitializeWallpaper(); 172 InitializeWallpaper();
171 } 173 }
172 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); 174 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index));
173 base::FundamentalValue is_daily(type == User::DAILY); 175 base::FundamentalValue is_daily(type == User::DAILY);
174 if (type == User::CUSTOMIZED) { 176 if (type == User::CUSTOMIZED) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DEFAULT, 230 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DEFAULT,
229 user_image_index); 231 user_image_index);
230 ash::Shell::GetInstance()->user_wallpaper_delegate()->InitializeWallpaper(); 232 ash::Shell::GetInstance()->user_wallpaper_delegate()->InitializeWallpaper();
231 } 233 }
232 } 234 }
233 235
234 void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) { 236 void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) {
235 User::WallpaperType type; 237 User::WallpaperType type;
236 int index; 238 int index;
237 base::Time date; 239 base::Time date;
238 UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); 240 WallpaperManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index,
241 &date);
Ivan Korotkov 2012/07/31 21:18:16 Ditto
bshe 2012/08/01 15:07:35 Done.
239 if (date != base::Time::Now().LocalMidnight()) 242 if (date != base::Time::Now().LocalMidnight())
240 index = ash::GetNextWallpaperIndex(index); 243 index = ash::GetNextWallpaperIndex(index);
241 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index); 244 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index);
242 ash::Shell::GetInstance()->desktop_background_controller()-> 245 ash::Shell::GetInstance()->desktop_background_controller()->
243 SetDefaultWallpaper(index); 246 SetDefaultWallpaper(index);
244 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); 247 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index));
245 base::FundamentalValue is_daily(true); 248 base::FundamentalValue is_daily(true);
246 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", 249 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage",
247 image_url, is_daily); 250 image_url, is_daily);
248 } 251 }
249 252
250 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { 253 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const {
251 Browser* browser = 254 Browser* browser =
252 browser::FindBrowserWithWebContents(web_ui()->GetWebContents()); 255 browser::FindBrowserWithWebContents(web_ui()->GetWebContents());
253 return browser->window()->GetNativeWindow(); 256 return browser->window()->GetNativeWindow();
254 } 257 }
255 258
256 } // namespace options2 259 } // namespace options2
257 } // namespace chromeos 260 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698