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

Side by Side Diff: chrome/browser/chromeos/extensions/wallpaper_private_api.cc

Issue 11415015: Remove use of index in wallpaper picker code and some refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser tests Created 8 years, 1 month 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/chromeos/extensions/wallpaper_private_api.h" 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/desktop_background/desktop_background_controller.h"
10 #include "ash/shell.h" 9 #include "ash/shell.h"
11 #include "ash/wm/window_cycle_controller.h" 10 #include "ash/wm/window_cycle_controller.h"
12 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
13 #include "base/file_util.h" 12 #include "base/file_util.h"
14 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
15 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
16 #include "base/path_service.h" 15 #include "base/path_service.h"
17 #include "base/synchronization/cancellation_flag.h" 16 #include "base/synchronization/cancellation_flag.h"
18 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/login/user.h" 18 #include "chrome/browser/chromeos/login/user.h"
(...skipping 12 matching lines...) Expand all
32 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
33 #include "grit/platform_locale_settings.h" 32 #include "grit/platform_locale_settings.h"
34 #include "ui/aura/window_observer.h" 33 #include "ui/aura/window_observer.h"
35 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
36 35
37 using base::BinaryValue; 36 using base::BinaryValue;
38 using content::BrowserThread; 37 using content::BrowserThread;
39 38
40 namespace { 39 namespace {
41 40
41 // Keeps in sync (same order) with WallpaperLayout enum in header file.
42 const char* kWallpaperLayoutArrays[] = {
43 "CENTER",
44 "CENTER_CROPPED",
45 "STRETCH",
46 "TILE"
47 };
48
49 const int kWallpaperLayoutCount = arraysize(kWallpaperLayoutArrays);
50
51 ash::WallpaperLayout GetLayoutEnum(const std::string& layout) {
52 for (int i = 0; i < kWallpaperLayoutCount; i++) {
53 if (layout.compare(kWallpaperLayoutArrays[i]) == 0)
54 return static_cast<ash::WallpaperLayout>(i);
55 }
56 // Default to use CENTER layout.
57 return ash::WALLPAPER_LAYOUT_CENTER;
58 }
59
42 class WindowStateManager; 60 class WindowStateManager;
43 61
44 // static 62 // static
45 WindowStateManager* g_window_state_manager = NULL; 63 WindowStateManager* g_window_state_manager = NULL;
46 64
47 // WindowStateManager remembers which windows have been minimized in order to 65 // WindowStateManager remembers which windows have been minimized in order to
48 // restore them when the wallpaper viewer is hidden. 66 // restore them when the wallpaper viewer is hidden.
49 class WindowStateManager : public aura::WindowObserver { 67 class WindowStateManager : public aura::WindowObserver {
50 public: 68 public:
51 69
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 253
236 bool WallpaperSetWallpaperFunction::RunImpl() { 254 bool WallpaperSetWallpaperFunction::RunImpl() {
237 BinaryValue* input = NULL; 255 BinaryValue* input = NULL;
238 if (args_ == NULL || !args_->GetBinary(0, &input)) { 256 if (args_ == NULL || !args_->GetBinary(0, &input)) {
239 return false; 257 return false;
240 } 258 }
241 std::string layout_string; 259 std::string layout_string;
242 if (!args_->GetString(1, &layout_string) || layout_string.empty()) { 260 if (!args_->GetString(1, &layout_string) || layout_string.empty()) {
243 return false; 261 return false;
244 } 262 }
245 layout_ = ash::GetLayoutEnum(layout_string); 263 layout_ = GetLayoutEnum(layout_string);
246 if (!args_->GetString(2, &url_) || url_.empty()) 264 if (!args_->GetString(2, &url_) || url_.empty())
247 return false; 265 return false;
248 266
249 // Gets email address while at UI thread. 267 // Gets email address while at UI thread.
250 email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email(); 268 email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email();
251 269
252 image_data_.assign(input->GetBuffer(), input->GetSize()); 270 image_data_.assign(input->GetBuffer(), input->GetSize());
253 if (wallpaper_decoder_) 271 if (wallpaper_decoder_)
254 wallpaper_decoder_->Cancel(); 272 wallpaper_decoder_->Cancel();
255 wallpaper_decoder_ = new WallpaperDecoder(this); 273 wallpaper_decoder_ = new WallpaperDecoder(this);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 BrowserThread::UI, FROM_HERE, 313 BrowserThread::UI, FROM_HERE,
296 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper, 314 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper,
297 this, base::Passed(&deep_copy))); 315 this, base::Passed(&deep_copy)));
298 chromeos::UserImage wallpaper(wallpaper_); 316 chromeos::UserImage wallpaper(wallpaper_);
299 317
300 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to 318 // Generates and saves small resolution wallpaper. Uses CENTER_CROPPED to
301 // maintain the aspect ratio after resize. 319 // maintain the aspect ratio after resize.
302 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper( 320 chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
303 wallpaper, 321 wallpaper,
304 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix), 322 file_path.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix),
305 ash::CENTER_CROPPED, 323 ash::WALLPAPER_LAYOUT_CENTER_CROPPED,
306 ash::kSmallWallpaperMaxWidth, 324 ash::kSmallWallpaperMaxWidth,
307 ash::kSmallWallpaperMaxHeight); 325 ash::kSmallWallpaperMaxHeight);
308 } else { 326 } else {
309 BrowserThread::PostTask( 327 BrowserThread::PostTask(
310 BrowserThread::UI, FROM_HERE, 328 BrowserThread::UI, FROM_HERE,
311 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel, 329 base::Bind(&WallpaperSetWallpaperFunction::OnFailureOrCancel,
312 this, "")); 330 this, ""));
313 LOG(ERROR) << "Failed to save downloaded wallpaper."; 331 LOG(ERROR) << "Failed to save downloaded wallpaper.";
314 } 332 }
315 } 333 }
(...skipping 23 matching lines...) Expand all
339 357
340 bool WallpaperSetCustomWallpaperFunction::RunImpl() { 358 bool WallpaperSetCustomWallpaperFunction::RunImpl() {
341 BinaryValue* input = NULL; 359 BinaryValue* input = NULL;
342 if (args_ == NULL || !args_->GetBinary(0, &input)) { 360 if (args_ == NULL || !args_->GetBinary(0, &input)) {
343 return false; 361 return false;
344 } 362 }
345 std::string layout_string; 363 std::string layout_string;
346 if (!args_->GetString(1, &layout_string) || layout_string.empty()) { 364 if (!args_->GetString(1, &layout_string) || layout_string.empty()) {
347 return false; 365 return false;
348 } 366 }
349 layout_ = ash::GetLayoutEnum(layout_string); 367 layout_ = GetLayoutEnum(layout_string);
350 368
351 // Gets email address while at UI thread. 369 // Gets email address while at UI thread.
352 email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email(); 370 email_ = chromeos::UserManager::Get()->GetLoggedInUser()->email();
353 371
354 image_data_.assign(input->GetBuffer(), input->GetSize()); 372 image_data_.assign(input->GetBuffer(), input->GetSize());
355 if (wallpaper_decoder_) 373 if (wallpaper_decoder_)
356 wallpaper_decoder_->Cancel(); 374 wallpaper_decoder_->Cancel();
357 wallpaper_decoder_ = new WallpaperDecoder(this); 375 wallpaper_decoder_ = new WallpaperDecoder(this);
358 wallpaper_decoder_->Start(image_data_); 376 wallpaper_decoder_->Start(image_data_);
359 377
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 409 }
392 410
393 WallpaperRestoreMinimizedWindowsFunction:: 411 WallpaperRestoreMinimizedWindowsFunction::
394 ~WallpaperRestoreMinimizedWindowsFunction() { 412 ~WallpaperRestoreMinimizedWindowsFunction() {
395 } 413 }
396 414
397 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() { 415 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() {
398 WindowStateManager::RestoreWindows(); 416 WindowStateManager::RestoreWindows();
399 return true; 417 return true;
400 } 418 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/wallpaper_private_api.h ('k') | chrome/browser/chromeos/login/user_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698