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

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: reviews 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 ImageDecoder::ROBUST_JPEG_CODEC); 69 ImageDecoder::ROBUST_JPEG_CODEC);
67 image_decoder_->Start(); 70 image_decoder_->Start();
68 } 71 }
69 72
70 void Cancel() { 73 void Cancel() {
(...skipping 10 matching lines...) Expand all
81 } 84 }
82 function_->OnWallpaperDecoded(final_image); 85 function_->OnWallpaperDecoded(final_image);
83 delete this; 86 delete this;
84 } 87 }
85 88
86 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE { 89 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE {
87 if (cancel_flag_.IsSet()) { 90 if (cancel_flag_.IsSet()) {
88 delete this; 91 delete this;
89 return; 92 return;
90 } 93 }
91 function_->OnFail(); 94 function_->OnFailure();
92 // TODO(bshe): Dispatches an encoding error event. 95 // TODO(bshe): Dispatches an encoding error event.
93 delete this; 96 delete this;
94 } 97 }
95 98
96 private: 99 private:
97 scoped_refptr<WallpaperSetWallpaperFunction> function_; 100 scoped_refptr<WallpaperFunctionBase> function_;
98 scoped_refptr<ImageDecoder> image_decoder_; 101 scoped_refptr<ImageDecoder> image_decoder_;
99 base::CancellationFlag cancel_flag_; 102 base::CancellationFlag cancel_flag_;
100 103
101 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder); 104 DISALLOW_COPY_AND_ASSIGN(WallpaperDecoder);
102 }; 105 };
103 106
104 WallpaperSetWallpaperFunction::WallpaperDecoder* 107 WallpaperFunctionBase::WallpaperDecoder*
105 WallpaperSetWallpaperFunction::wallpaper_decoder_; 108 WallpaperFunctionBase::wallpaper_decoder_;
109
110 WallpaperFunctionBase::WallpaperFunctionBase() {
111 }
112
113 WallpaperFunctionBase::~WallpaperFunctionBase() {
114 }
115
116 bool WallpaperFunctionBase::RunImpl() {
Mihai Parparita -not on Chrome 2012/09/05 18:20:14 You can just leave this as unimplemented.
bshe 2012/09/05 22:39:46 Done.
117 return true;
118 }
106 119
107 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { 120 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() {
108 } 121 }
109 122
110 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { 123 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() {
111 } 124 }
112 125
113 bool WallpaperSetWallpaperFunction::RunImpl() { 126 bool WallpaperSetWallpaperFunction::RunImpl() {
114 BinaryValue* input = NULL; 127 BinaryValue* input = NULL;
115 if (args_ == NULL || !args_->GetBinary(0, &input)) { 128 if (args_ == NULL || !args_->GetBinary(0, &input)) {
(...skipping 24 matching lines...) Expand all
140 153
141 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( 154 void WallpaperSetWallpaperFunction::OnWallpaperDecoded(
142 const gfx::ImageSkia& wallpaper) { 155 const gfx::ImageSkia& wallpaper) {
143 wallpaper_ = wallpaper; 156 wallpaper_ = wallpaper;
144 BrowserThread::PostTask( 157 BrowserThread::PostTask(
145 BrowserThread::FILE, FROM_HERE, 158 BrowserThread::FILE, FROM_HERE,
146 base::Bind(&WallpaperSetWallpaperFunction::SaveToFile, 159 base::Bind(&WallpaperSetWallpaperFunction::SaveToFile,
147 this)); 160 this));
148 } 161 }
149 162
150 void WallpaperSetWallpaperFunction::OnFail() { 163 void WallpaperSetWallpaperFunction::OnFailure() {
151 wallpaper_decoder_ = NULL; 164 wallpaper_decoder_ = NULL;
152 SendResponse(false); 165 SendResponse(false);
153 } 166 }
154 167
155 void WallpaperSetWallpaperFunction::SaveToFile() { 168 void WallpaperSetWallpaperFunction::SaveToFile() {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
157 FilePath wallpaper_dir; 170 FilePath wallpaper_dir;
158 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); 171 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir));
159 if (!file_util::DirectoryExists(wallpaper_dir) && 172 if (!file_util::DirectoryExists(wallpaper_dir) &&
160 !file_util::CreateDirectory(wallpaper_dir)) { 173 !file_util::CreateDirectory(wallpaper_dir)) {
161 BrowserThread::PostTask( 174 BrowserThread::PostTask(
162 BrowserThread::UI, FROM_HERE, 175 BrowserThread::UI, FROM_HERE,
163 base::Bind(&WallpaperSetWallpaperFunction::OnFail, 176 base::Bind(&WallpaperSetWallpaperFunction::OnFailure,
164 this)); 177 this));
165 return; 178 return;
166 } 179 }
167 FilePath file_path = wallpaper_dir.Append(file_name_); 180 FilePath file_path = wallpaper_dir.Append(file_name_);
168 if (file_util::PathExists(file_path) || 181 if (file_util::PathExists(file_path) ||
169 file_util::WriteFile(file_path, image_data_.c_str(), 182 file_util::WriteFile(file_path, image_data_.c_str(),
170 image_data_.size()) != -1 ) { 183 image_data_.size()) != -1 ) {
171 BrowserThread::PostTask( 184 BrowserThread::PostTask(
172 BrowserThread::UI, FROM_HERE, 185 BrowserThread::UI, FROM_HERE,
173 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper, 186 base::Bind(&WallpaperSetWallpaperFunction::SetDecodedWallpaper,
174 this)); 187 this));
175 } else { 188 } else {
176 BrowserThread::PostTask( 189 BrowserThread::PostTask(
177 BrowserThread::UI, FROM_HERE, 190 BrowserThread::UI, FROM_HERE,
178 base::Bind(&WallpaperSetWallpaperFunction::OnFail, 191 base::Bind(&WallpaperSetWallpaperFunction::OnFailure,
179 this)); 192 this));
180 } 193 }
181 } 194 }
182 195
183 void WallpaperSetWallpaperFunction::SetDecodedWallpaper() { 196 void WallpaperSetWallpaperFunction::SetDecodedWallpaper() {
184 chromeos::WallpaperManager* wallpaper_manager = 197 chromeos::WallpaperManager* wallpaper_manager =
185 chromeos::WallpaperManager::Get(); 198 chromeos::WallpaperManager::Get();
186 wallpaper_manager->SetWallpaperFromImageSkia(wallpaper_, layout_); 199 wallpaper_manager->SetWallpaperFromImageSkia(wallpaper_, layout_);
187 bool is_persistent = 200 bool is_persistent =
188 !chromeos::UserManager::Get()->IsCurrentUserEphemeral(); 201 !chromeos::UserManager::Get()->IsCurrentUserEphemeral();
189 chromeos::WallpaperInfo info = { 202 chromeos::WallpaperInfo info = {
190 file_name_, 203 file_name_,
191 layout_, 204 layout_,
192 chromeos::User::ONLINE, 205 chromeos::User::ONLINE,
193 base::Time::Now().LocalMidnight() 206 base::Time::Now().LocalMidnight()
194 }; 207 };
195 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent); 208 wallpaper_manager->SetUserWallpaperInfo(email_, info, is_persistent);
196 wallpaper_decoder_ = NULL; 209 wallpaper_decoder_ = NULL;
197 SendResponse(true); 210 SendResponse(true);
198 } 211 }
212
213 WallpaperSetCustomWallpaperFunction::WallpaperSetCustomWallpaperFunction() {
214 }
215
216 WallpaperSetCustomWallpaperFunction::~WallpaperSetCustomWallpaperFunction() {
217 }
218
219 bool WallpaperSetCustomWallpaperFunction::RunImpl() {
220 BinaryValue* input = NULL;
221 if (args_ == NULL || !args_->GetBinary(0, &input)) {
222 return false;
223 }
224 std::string layout_string;
225 if (!args_->GetString(1, &layout_string) || layout_string.empty()) {
226 return false;
227 }
228 layout_ = ash::GetLayoutEnum(layout_string);
229
230 // Gets email address while at UI thread.
231 email_ = chromeos::UserManager::Get()->GetLoggedInUser().email();
232
233 image_data_.assign(input->GetBuffer(), input->GetSize());
234 if (wallpaper_decoder_)
235 wallpaper_decoder_->Cancel();
236 wallpaper_decoder_ = new WallpaperDecoder(this);
237 wallpaper_decoder_->Start(image_data_);
238
239 return true;
240 }
241
242 void WallpaperSetCustomWallpaperFunction::OnWallpaperDecoded(
243 const gfx::ImageSkia& wallpaper) {
244 chromeos::UserImage::RawImage raw_image(image_data_.begin(),
245 image_data_.end());
246 chromeos::UserImage image(wallpaper, raw_image);
247 // In the new wallpaper picker UI, we do not depend on WallpaperDelegate
248 // to refresh thumbnail. Uses a null delegate here.
249 chromeos::WallpaperManager::Get()->SetCustomWallpaper(
250 email_, layout_, chromeos::User::CUSTOMIZED,
251 base::WeakPtr<chromeos::WallpaperDelegate>(), image);
252 wallpaper_decoder_ = NULL;
253 SendResponse(true);
254 }
255
256 void WallpaperSetCustomWallpaperFunction::OnFailure() {
257 wallpaper_decoder_ = NULL;
258 SendResponse(false);
259 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698