OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_api.h" |
6 | 6 |
7 #include "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); | 112 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); |
113 } else { | 113 } else { |
114 SetError("URL is invalid."); | 114 SetError("URL is invalid."); |
115 SendResponse(false); | 115 SendResponse(false); |
116 } | 116 } |
117 } | 117 } |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( | 121 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( |
122 const gfx::ImageSkia& wallpaper) { | 122 const gfx::ImageSkia& image) { |
123 chromeos::WallpaperManager* wallpaper_manager = | 123 chromeos::WallpaperManager* wallpaper_manager = |
124 chromeos::WallpaperManager::Get(); | 124 chromeos::WallpaperManager::Get(); |
125 chromeos::UserImage::RawImage raw_image( | |
126 params_->details.wallpaper_data->begin(), | |
127 params_->details.wallpaper_data->end()); | |
128 chromeos::UserImage image(wallpaper, raw_image); | |
129 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( | 125 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( |
130 chromeos::kThumbnailWallpaperSubDir, | 126 chromeos::kThumbnailWallpaperSubDir, |
131 user_id_hash_, | 127 user_id_hash_, |
132 params_->details.name); | 128 params_->details.name); |
133 | 129 |
134 sequence_token_ = BrowserThread::GetBlockingPool()-> | 130 sequence_token_ = BrowserThread::GetBlockingPool()-> |
135 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); | 131 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); |
136 scoped_refptr<base::SequencedTaskRunner> task_runner = | 132 scoped_refptr<base::SequencedTaskRunner> task_runner = |
137 BrowserThread::GetBlockingPool()-> | 133 BrowserThread::GetBlockingPool()-> |
138 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 134 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, |
139 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 135 base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
140 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 136 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
141 set_wallpaper::Params::Details::ToString(params_->details.layout)); | 137 set_wallpaper::Params::Details::ToString(params_->details.layout)); |
142 bool update_wallpaper = | 138 bool update_wallpaper = |
143 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); | 139 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); |
144 wallpaper_manager->SetCustomWallpaper(user_id_, | 140 wallpaper_manager->SetCustomWallpaper(user_id_, |
145 user_id_hash_, | 141 user_id_hash_, |
146 params_->details.name, | 142 params_->details.name, |
147 layout, | 143 layout, |
148 chromeos::User::CUSTOMIZED, | 144 chromeos::User::CUSTOMIZED, |
149 image, | 145 image, |
150 update_wallpaper); | 146 update_wallpaper); |
151 unsafe_wallpaper_decoder_ = NULL; | 147 unsafe_wallpaper_decoder_ = NULL; |
152 | 148 |
153 if (params_->details.thumbnail) { | 149 if (params_->details.thumbnail) { |
154 wallpaper.EnsureRepsForSupportedScales(); | 150 image.EnsureRepsForSupportedScales(); |
155 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.DeepCopy()); | 151 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
156 // Generates thumbnail before call api function callback. We can then | 152 // Generates thumbnail before call api function callback. We can then |
157 // request thumbnail in the javascript callback. | 153 // request thumbnail in the javascript callback. |
158 task_runner->PostTask(FROM_HERE, | 154 task_runner->PostTask( |
159 base::Bind( | 155 FROM_HERE, |
160 &WallpaperSetWallpaperFunction::GenerateThumbnail, | 156 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, |
161 this, thumbnail_path, base::Passed(&deep_copy))); | 157 this, |
| 158 thumbnail_path, |
| 159 base::Passed(deep_copy.Pass()))); |
162 } else { | 160 } else { |
163 SendResponse(true); | 161 SendResponse(true); |
164 } | 162 } |
165 } | 163 } |
166 | 164 |
167 void WallpaperSetWallpaperFunction::GenerateThumbnail( | 165 void WallpaperSetWallpaperFunction::GenerateThumbnail( |
168 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { | 166 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { |
169 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 167 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
170 sequence_token_)); | 168 sequence_token_)); |
171 chromeos::UserImage wallpaper(*image.get()); | |
172 if (!base::PathExists(thumbnail_path.DirName())) | 169 if (!base::PathExists(thumbnail_path.DirName())) |
173 base::CreateDirectory(thumbnail_path.DirName()); | 170 base::CreateDirectory(thumbnail_path.DirName()); |
174 | 171 |
175 scoped_refptr<base::RefCountedBytes> data; | 172 scoped_refptr<base::RefCountedBytes> data; |
176 chromeos::WallpaperManager::Get()->ResizeWallpaper( | 173 chromeos::WallpaperManager::Get()->ResizeImage( |
177 wallpaper, | 174 *image, |
178 ash::WALLPAPER_LAYOUT_STRETCH, | 175 ash::WALLPAPER_LAYOUT_STRETCH, |
179 chromeos::kWallpaperThumbnailWidth, | 176 chromeos::kWallpaperThumbnailWidth, |
180 chromeos::kWallpaperThumbnailHeight, | 177 chromeos::kWallpaperThumbnailHeight, |
181 &data, | 178 &data, |
182 NULL); | 179 NULL); |
183 BrowserThread::PostTask( | 180 BrowserThread::PostTask( |
184 BrowserThread::UI, FROM_HERE, | 181 BrowserThread::UI, FROM_HERE, |
185 base::Bind( | 182 base::Bind( |
186 &WallpaperSetWallpaperFunction::ThumbnailGenerated, | 183 &WallpaperSetWallpaperFunction::ThumbnailGenerated, |
187 this, data)); | 184 this, data)); |
(...skipping 11 matching lines...) Expand all Loading... |
199 bool success, | 196 bool success, |
200 const std::string& response) { | 197 const std::string& response) { |
201 if (success) { | 198 if (success) { |
202 params_->details.wallpaper_data.reset(new std::string(response)); | 199 params_->details.wallpaper_data.reset(new std::string(response)); |
203 StartDecode(*params_->details.wallpaper_data); | 200 StartDecode(*params_->details.wallpaper_data); |
204 } else { | 201 } else { |
205 SetError(response); | 202 SetError(response); |
206 SendResponse(false); | 203 SendResponse(false); |
207 } | 204 } |
208 } | 205 } |
OLD | NEW |