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

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

Issue 10890038: Hook up custom wallpaper code path to new wallpaper picker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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/chromeos/extensions/wallpaper_private_api.h" 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/synchronization/cancellation_flag.h" 13 #include "base/synchronization/cancellation_flag.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chromeos/login/user_image.h"
15 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/chromeos/login/wallpaper_manager.h" 17 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
17 #include "chrome/browser/extensions/event_router.h" 18 #include "chrome/browser/extensions/event_router.h"
18 #include "chrome/browser/image_decoder.h" 19 #include "chrome/browser/image_decoder.h"
19 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "net/url_request/url_fetcher.h" 22 #include "net/url_request/url_fetcher.h"
22 #include "net/url_request/url_fetcher_delegate.h" 23 #include "net/url_request/url_fetcher_delegate.h"
23 #include "net/url_request/url_request_status.h" 24 #include "net/url_request/url_request_status.h"
24 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
(...skipping 14 matching lines...) Expand all
39 SET_STRING("customCategoryLabel", 40 SET_STRING("customCategoryLabel",
40 IDS_WALLPAPER_MANAGER_CUSTOM_CATEGORY_LABEL); 41 IDS_WALLPAPER_MANAGER_CUSTOM_CATEGORY_LABEL);
41 SET_STRING("selectCustomLabel", 42 SET_STRING("selectCustomLabel",
42 IDS_WALLPAPER_MANAGER_SELECT_CUSTOM_LABEL); 43 IDS_WALLPAPER_MANAGER_SELECT_CUSTOM_LABEL);
43 SET_STRING("positionLabel", IDS_WALLPAPER_MANAGER_POSITION_LABEL); 44 SET_STRING("positionLabel", IDS_WALLPAPER_MANAGER_POSITION_LABEL);
44 SET_STRING("colorLabel", IDS_WALLPAPER_MANAGER_COLOR_LABEL); 45 SET_STRING("colorLabel", IDS_WALLPAPER_MANAGER_COLOR_LABEL);
45 SET_STRING("previewLabel", IDS_WALLPAPER_MANAGER_PREVIEW_LABEL); 46 SET_STRING("previewLabel", IDS_WALLPAPER_MANAGER_PREVIEW_LABEL);
46 SET_STRING("downloadingLabel", IDS_WALLPAPER_MANAGER_DOWNLOADING_LABEL); 47 SET_STRING("downloadingLabel", IDS_WALLPAPER_MANAGER_DOWNLOADING_LABEL);
47 SET_STRING("setWallpaperDaily", IDS_OPTIONS_SET_WALLPAPER_DAILY); 48 SET_STRING("setWallpaperDaily", IDS_OPTIONS_SET_WALLPAPER_DAILY);
48 SET_STRING("searchTextLabel", IDS_WALLPAPER_MANAGER_SEARCH_TEXT_LABEL); 49 SET_STRING("searchTextLabel", IDS_WALLPAPER_MANAGER_SEARCH_TEXT_LABEL);
50 SET_STRING("centerCroppedLayout",
51 IDS_OPTIONS_WALLPAPER_CENTER_CROPPED_LAYOUT);
52 SET_STRING("centerLayout", IDS_OPTIONS_WALLPAPER_CENTER_LAYOUT);
53 SET_STRING("stretchLayout", IDS_OPTIONS_WALLPAPER_STRETCH_LAYOUT);
49 #undef SET_STRING 54 #undef SET_STRING
50 55
51 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); 56 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict);
52 57
53 return true; 58 return true;
54 } 59 }
55 60
56 class WallpaperSetWallpaperFunction::WallpaperDecoder 61 class WallpaperFunctionBase::WallpaperDecoder : public ImageDecoder::Delegate {
57 : public ImageDecoder::Delegate {
58 public: 62 public:
59 explicit WallpaperDecoder( 63 explicit WallpaperDecoder(scoped_refptr<WallpaperFunctionBase> function)
60 scoped_refptr<WallpaperSetWallpaperFunction> function)
61 : function_(function) { 64 : function_(function) {
62 } 65 }
63 66
64 void Start(const std::string& image_data) { 67 void Start(const std::string& image_data) {
65 image_decoder_ = new ImageDecoder(this, image_data); 68 image_decoder_ = new ImageDecoder(this, image_data);
66 image_decoder_->Start(); 69 image_decoder_->Start();
67 } 70 }
68 71
69 void Cancel() { 72 void Cancel() {
70 cancel_flag_.Set(); 73 cancel_flag_.Set();
(...skipping 15 matching lines...) Expand all
86 if (cancel_flag_.IsSet()) { 89 if (cancel_flag_.IsSet()) {
87 delete this; 90 delete this;
88 return; 91 return;
89 } 92 }
90 function_->OnFail(); 93 function_->OnFail();
91 // TODO(bshe): Dispatches an encoding error event. 94 // TODO(bshe): Dispatches an encoding error event.
92 delete this; 95 delete this;
93 } 96 }
94 97
95 private: 98 private:
96 scoped_refptr<WallpaperSetWallpaperFunction> function_; 99 scoped_refptr<WallpaperFunctionBase> function_;
97 scoped_refptr<ImageDecoder> image_decoder_; 100 scoped_refptr<ImageDecoder> image_decoder_;
98 base::CancellationFlag cancel_flag_; 101 base::CancellationFlag cancel_flag_;
99 102
100 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder); 103 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder);
101 }; 104 };
102 105
103 WallpaperSetWallpaperFunction::WallpaperDecoder* 106 WallpaperFunctionBase::WallpaperDecoder*
104 WallpaperSetWallpaperFunction::wallpaper_decoder_; 107 WallpaperFunctionBase::wallpaper_decoder_;
108
109 WallpaperFunctionBase::WallpaperFunctionBase() {
110 }
111
112 WallpaperFunctionBase::~WallpaperFunctionBase() {
113 }
114
115 bool WallpaperFunctionBase::RunImpl() {
116 return true;
117 }
105 118
106 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { 119 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() {
107 } 120 }
108 121
109 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { 122 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() {
110 } 123 }
111 124
112 bool WallpaperSetWallpaperFunction::RunImpl() { 125 bool WallpaperSetWallpaperFunction::RunImpl() {
113 BinaryValue* input = NULL; 126 BinaryValue* input = NULL;
114 if (args_ == NULL || !args_->GetBinary(0, &input)) { 127 if (args_ == NULL || !args_->GetBinary(0, &input)) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 chromeos::WallpaperInfo info = { 201 chromeos::WallpaperInfo info = {
189 file_name_, 202 file_name_,
190 layout_, 203 layout_,
191 chromeos::User::ONLINE, 204 chromeos::User::ONLINE,
192 base::Time::Now().LocalMidnight() 205 base::Time::Now().LocalMidnight()
193 }; 206 };
194 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent); 207 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent);
195 wallpaper_decoder_ = NULL; 208 wallpaper_decoder_ = NULL;
196 SendResponse(true); 209 SendResponse(true);
197 } 210 }
211
212 WallpaperSetCustomWallpaperFunction::WallpaperSetCustomWallpaperFunction() {
213 }
214
215 WallpaperSetCustomWallpaperFunction::~WallpaperSetCustomWallpaperFunction() {
216 }
217
218 bool WallpaperSetCustomWallpaperFunction::RunImpl() {
219 BinaryValue* input = NULL;
220 if (args_ == NULL || !args_->GetBinary(0, &input)) {
221 return false;
222 }
223 std::string layout_string;
224 if (!args_->GetString(1, &layout_string) || layout_string.empty()) {
225 return false;
226 }
227 layout_ = ash::GetLayoutEnum(layout_string);
228
229 // Gets email address while at UI thread.
230 email_ = chromeos::UserManager::Get()->GetLoggedInUser().email();
231
232 image_data_.assign(input->GetBuffer(), input->GetSize());
233 if (wallpaper_decoder_)
234 wallpaper_decoder_->Cancel();
235 wallpaper_decoder_ = new WallpaperDecoder(this);
236 wallpaper_decoder_->Start(image_data_);
237
238 return true;
239 }
240
241 void WallpaperSetCustomWallpaperFunction::OnWallpaperDecoded(
242 const gfx::ImageSkia& wallpaper) {
243 chromeos::UserImage::RawImage raw_image(image_data_.begin(),
244 image_data_.end());
245 chromeos::UserImage image(wallpaper, raw_image);
246 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate
247 // to refresh thumbnail. Uses a null delegate here.
248 chromeos::WallpaperManager::Get()->SetCustomWallpaper(
249 email_, layout_, chromeos::User::CUSTOMIZED,
250 base::WeakPtr<chromeos::WallpaperDelegate>(), image);
251 wallpaper_decoder_ = NULL;
252 SendResponse(true);
253 }
254
255 void WallpaperSetCustomWallpaperFunction::OnFail() {
256 wallpaper_decoder_ = NULL;
257 SendResponse(false);
258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698