| 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 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 void CancelPreviousFetch() { | 81 void CancelPreviousFetch() { |
| 82 if (url_fetcher_.get()) { | 82 if (url_fetcher_.get()) { |
| 83 callback_.Run(false, wallpaper_api_util::kCancelWallpaperMessage); | 83 callback_.Run(false, wallpaper_api_util::kCancelWallpaperMessage); |
| 84 callback_.Reset(); | 84 callback_.Reset(); |
| 85 url_fetcher_.reset(); | 85 url_fetcher_.reset(); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 scoped_ptr<net::URLFetcher> url_fetcher_; | 89 std::unique_ptr<net::URLFetcher> url_fetcher_; |
| 90 FetchCallback callback_; | 90 FetchCallback callback_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 base::LazyInstance<WallpaperFetcher> g_wallpaper_fetcher = | 93 base::LazyInstance<WallpaperFetcher> g_wallpaper_fetcher = |
| 94 LAZY_INSTANCE_INITIALIZER; | 94 LAZY_INSTANCE_INITIALIZER; |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { | 98 WallpaperSetWallpaperFunction::WallpaperSetWallpaperFunction() { |
| 99 } | 99 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 170 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 171 extension()->name()); | 171 extension()->name()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 if (!params_->details.thumbnail) | 174 if (!params_->details.thumbnail) |
| 175 SendResponse(true); | 175 SendResponse(true); |
| 176 | 176 |
| 177 // We need to generate thumbnail image anyway to make the current third party | 177 // We need to generate thumbnail image anyway to make the current third party |
| 178 // wallpaper syncable through different devices. | 178 // wallpaper syncable through different devices. |
| 179 image.EnsureRepsForSupportedScales(); | 179 image.EnsureRepsForSupportedScales(); |
| 180 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); | 180 std::unique_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
| 181 // Generates thumbnail before call api function callback. We can then | 181 // Generates thumbnail before call api function callback. We can then |
| 182 // request thumbnail in the javascript callback. | 182 // request thumbnail in the javascript callback. |
| 183 task_runner->PostTask( | 183 task_runner->PostTask( |
| 184 FROM_HERE, | 184 FROM_HERE, |
| 185 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this, | 185 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, this, |
| 186 thumbnail_path, base::Passed(std::move(deep_copy)))); | 186 thumbnail_path, base::Passed(std::move(deep_copy)))); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void WallpaperSetWallpaperFunction::GenerateThumbnail( | 189 void WallpaperSetWallpaperFunction::GenerateThumbnail( |
| 190 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { | 190 const base::FilePath& thumbnail_path, |
| 191 std::unique_ptr<gfx::ImageSkia> image) { |
| 191 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 192 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 192 sequence_token_)); | 193 sequence_token_)); |
| 193 if (!base::PathExists(thumbnail_path.DirName())) | 194 if (!base::PathExists(thumbnail_path.DirName())) |
| 194 base::CreateDirectory(thumbnail_path.DirName()); | 195 base::CreateDirectory(thumbnail_path.DirName()); |
| 195 | 196 |
| 196 scoped_refptr<base::RefCountedBytes> original_data; | 197 scoped_refptr<base::RefCountedBytes> original_data; |
| 197 scoped_refptr<base::RefCountedBytes> thumbnail_data; | 198 scoped_refptr<base::RefCountedBytes> thumbnail_data; |
| 198 chromeos::WallpaperManager::Get()->ResizeImage( | 199 chromeos::WallpaperManager::Get()->ResizeImage( |
| 199 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, image->width(), | 200 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, image->width(), |
| 200 image->height(), &original_data, NULL); | 201 image->height(), &original_data, NULL); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 223 SetResult(thumbnail_result); | 224 SetResult(thumbnail_result); |
| 224 SendResponse(true); | 225 SendResponse(true); |
| 225 } | 226 } |
| 226 | 227 |
| 227 // Inform the native Wallpaper Picker Application that the current wallpaper | 228 // Inform the native Wallpaper Picker Application that the current wallpaper |
| 228 // has been modified by a third party application. | 229 // has been modified by a third party application. |
| 229 if (extension()->id() != extension_misc::kWallpaperManagerId) { | 230 if (extension()->id() != extension_misc::kWallpaperManagerId) { |
| 230 Profile* profile = Profile::FromBrowserContext(browser_context()); | 231 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 231 extensions::EventRouter* event_router = | 232 extensions::EventRouter* event_router = |
| 232 extensions::EventRouter::Get(profile); | 233 extensions::EventRouter::Get(profile); |
| 233 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | 234 std::unique_ptr<base::ListValue> event_args(new base::ListValue()); |
| 234 event_args->Append(original_result); | 235 event_args->Append(original_result); |
| 235 event_args->Append(thumbnail_result); | 236 event_args->Append(thumbnail_result); |
| 236 event_args->Append(new base::StringValue( | 237 event_args->Append(new base::StringValue( |
| 237 extensions::api::wallpaper::ToString(params_->details.layout))); | 238 extensions::api::wallpaper::ToString(params_->details.layout))); |
| 238 event_args->Append(new base::StringValue(extension()->name())); | 239 event_args->Append(new base::StringValue(extension()->name())); |
| 239 scoped_ptr<extensions::Event> event(new extensions::Event( | 240 std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 240 extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY, | 241 extensions::events::WALLPAPER_PRIVATE_ON_WALLPAPER_CHANGED_BY_3RD_PARTY, |
| 241 extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty:: | 242 extensions::api::wallpaper_private::OnWallpaperChangedBy3rdParty:: |
| 242 kEventName, | 243 kEventName, |
| 243 std::move(event_args))); | 244 std::move(event_args))); |
| 244 event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId, | 245 event_router->DispatchEventToExtension(extension_misc::kWallpaperManagerId, |
| 245 std::move(event)); | 246 std::move(event)); |
| 246 } | 247 } |
| 247 } | 248 } |
| 248 | 249 |
| 249 void WallpaperSetWallpaperFunction::OnWallpaperFetched( | 250 void WallpaperSetWallpaperFunction::OnWallpaperFetched( |
| 250 bool success, | 251 bool success, |
| 251 const std::string& response) { | 252 const std::string& response) { |
| 252 if (success) { | 253 if (success) { |
| 253 params_->details.data.reset( | 254 params_->details.data.reset( |
| 254 new std::vector<char>(response.begin(), response.end())); | 255 new std::vector<char>(response.begin(), response.end())); |
| 255 StartDecode(*params_->details.data); | 256 StartDecode(*params_->details.data); |
| 256 } else { | 257 } else { |
| 257 SetError(response); | 258 SetError(response); |
| 258 SendResponse(false); | 259 SendResponse(false); |
| 259 } | 260 } |
| 260 } | 261 } |
| OLD | NEW |