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 <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | |
bshe
2016/09/14 13:33:07
nit: doesn't look like this header is needed?
fdoray
2016/09/14 14:04:03
yes, needed at line 65
| |
13 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 18 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
18 #include "chrome/browser/chromeos/file_manager/app_id.h" | 19 #include "chrome/browser/chromeos/file_manager/app_id.h" |
19 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 20 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 147 } |
147 | 148 |
148 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( | 149 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( |
149 const gfx::ImageSkia& image) { | 150 const gfx::ImageSkia& image) { |
150 chromeos::WallpaperManager* wallpaper_manager = | 151 chromeos::WallpaperManager* wallpaper_manager = |
151 chromeos::WallpaperManager::Get(); | 152 chromeos::WallpaperManager::Get(); |
152 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( | 153 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( |
153 wallpaper::kThumbnailWallpaperSubDir, wallpaper_files_id_, | 154 wallpaper::kThumbnailWallpaperSubDir, wallpaper_files_id_, |
154 params_->details.filename); | 155 params_->details.filename); |
155 | 156 |
156 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken( | |
157 wallpaper::kWallpaperSequenceTokenName); | |
158 scoped_refptr<base::SequencedTaskRunner> task_runner = | 157 scoped_refptr<base::SequencedTaskRunner> task_runner = |
159 BrowserThread::GetBlockingPool()-> | 158 BrowserThread::GetBlockingPool() |
160 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 159 ->GetSequencedTaskRunnerWithShutdownBehavior( |
160 BrowserThread::GetBlockingPool()->GetNamedSequenceToken( | |
161 wallpaper::kWallpaperSequenceTokenName), | |
161 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 162 base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
162 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 163 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
163 extensions::api::wallpaper::ToString(params_->details.layout)); | 164 extensions::api::wallpaper::ToString(params_->details.layout)); |
164 wallpaper_api_util::RecordCustomWallpaperLayout(layout); | 165 wallpaper_api_util::RecordCustomWallpaperLayout(layout); |
165 | 166 |
166 bool update_wallpaper = | 167 bool update_wallpaper = |
167 account_id_ == | 168 account_id_ == |
168 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); | 169 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); |
169 wallpaper_manager->SetCustomWallpaper( | 170 wallpaper_manager->SetCustomWallpaper( |
170 account_id_, wallpaper_files_id_, params_->details.filename, layout, | 171 account_id_, wallpaper_files_id_, params_->details.filename, layout, |
(...skipping 25 matching lines...) Expand all Loading... | |
196 // request thumbnail in the javascript callback. | 197 // request thumbnail in the javascript callback. |
197 task_runner->PostTask( | 198 task_runner->PostTask( |
198 FROM_HERE, | 199 FROM_HERE, |
199 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this, | 200 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this, |
200 thumbnail_path, base::Passed(std::move(deep_copy)))); | 201 thumbnail_path, base::Passed(std::move(deep_copy)))); |
201 } | 202 } |
202 | 203 |
203 void WallpaperSetWallpaperFunction::GenerateThumbnail( | 204 void WallpaperSetWallpaperFunction::GenerateThumbnail( |
204 const base::FilePath& thumbnail_path, | 205 const base::FilePath& thumbnail_path, |
205 std::unique_ptr<gfx::ImageSkia> image) { | 206 std::unique_ptr<gfx::ImageSkia> image) { |
206 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 207 wallpaper::AssertCalledOnWallpaperSequence(); |
207 sequence_token_)); | |
208 if (!base::PathExists(thumbnail_path.DirName())) | 208 if (!base::PathExists(thumbnail_path.DirName())) |
209 base::CreateDirectory(thumbnail_path.DirName()); | 209 base::CreateDirectory(thumbnail_path.DirName()); |
210 | 210 |
211 scoped_refptr<base::RefCountedBytes> original_data; | 211 scoped_refptr<base::RefCountedBytes> original_data; |
212 scoped_refptr<base::RefCountedBytes> thumbnail_data; | 212 scoped_refptr<base::RefCountedBytes> thumbnail_data; |
213 chromeos::WallpaperManager::Get()->ResizeImage( | 213 chromeos::WallpaperManager::Get()->ResizeImage( |
214 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, image->width(), | 214 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, image->width(), |
215 image->height(), &original_data, NULL); | 215 image->height(), &original_data, NULL); |
216 chromeos::WallpaperManager::Get()->ResizeImage( | 216 chromeos::WallpaperManager::Get()->ResizeImage( |
217 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, | 217 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 const std::string& response) { | 278 const std::string& response) { |
279 if (success) { | 279 if (success) { |
280 params_->details.data.reset( | 280 params_->details.data.reset( |
281 new std::vector<char>(response.begin(), response.end())); | 281 new std::vector<char>(response.begin(), response.end())); |
282 StartDecode(*params_->details.data); | 282 StartDecode(*params_->details.data); |
283 } else { | 283 } else { |
284 SetError(response); | 284 SetError(response); |
285 SendResponse(false); | 285 SendResponse(false); |
286 } | 286 } |
287 } | 287 } |
OLD | NEW |