| 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/files/file_util.h" | 8 #include "base/files/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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 bool WallpaperSetWallpaperFunction::RunAsync() { | 97 bool WallpaperSetWallpaperFunction::RunAsync() { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 99 params_ = set_wallpaper::Params::Create(*args_); | 99 params_ = set_wallpaper::Params::Create(*args_); |
| 100 EXTENSION_FUNCTION_VALIDATE(params_); | 100 EXTENSION_FUNCTION_VALIDATE(params_); |
| 101 | 101 |
| 102 // Gets email address and username hash while at UI thread. | 102 // Gets email address and username hash while at UI thread. |
| 103 user_id_ = user_manager::UserManager::Get()->GetLoggedInUser()->email(); | 103 user_id_ = user_manager::UserManager::Get()->GetLoggedInUser()->email(); |
| 104 user_id_hash_ = | 104 user_id_hash_ = |
| 105 user_manager::UserManager::Get()->GetLoggedInUser()->username_hash(); | 105 user_manager::UserManager::Get()->GetLoggedInUser()->username_hash(); |
| 106 | 106 |
| 107 if (params_->details.wallpaper_data) { | 107 if (params_->details.data) { |
| 108 StartDecode(*params_->details.wallpaper_data); | 108 StartDecode(*params_->details.data); |
| 109 } else { | 109 } else { |
| 110 GURL wallpaper_url(*params_->details.url); | 110 GURL wallpaper_url(*params_->details.url); |
| 111 if (wallpaper_url.is_valid()) { | 111 if (wallpaper_url.is_valid()) { |
| 112 g_wallpaper_fetcher.Get().FetchWallpaper( | 112 g_wallpaper_fetcher.Get().FetchWallpaper( |
| 113 wallpaper_url, | 113 wallpaper_url, |
| 114 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); | 114 base::Bind(&WallpaperSetWallpaperFunction::OnWallpaperFetched, this)); |
| 115 } else { | 115 } else { |
| 116 SetError("URL is invalid."); | 116 SetError("URL is invalid."); |
| 117 SendResponse(false); | 117 SendResponse(false); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 return true; | 120 return true; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( | 123 void WallpaperSetWallpaperFunction::OnWallpaperDecoded( |
| 124 const gfx::ImageSkia& image) { | 124 const gfx::ImageSkia& image) { |
| 125 chromeos::WallpaperManager* wallpaper_manager = | 125 chromeos::WallpaperManager* wallpaper_manager = |
| 126 chromeos::WallpaperManager::Get(); | 126 chromeos::WallpaperManager::Get(); |
| 127 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( | 127 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( |
| 128 chromeos::kThumbnailWallpaperSubDir, | 128 chromeos::kThumbnailWallpaperSubDir, |
| 129 user_id_hash_, | 129 user_id_hash_, |
| 130 params_->details.name); | 130 params_->details.filename); |
| 131 | 131 |
| 132 sequence_token_ = BrowserThread::GetBlockingPool()-> | 132 sequence_token_ = BrowserThread::GetBlockingPool()-> |
| 133 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); | 133 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); |
| 134 scoped_refptr<base::SequencedTaskRunner> task_runner = | 134 scoped_refptr<base::SequencedTaskRunner> task_runner = |
| 135 BrowserThread::GetBlockingPool()-> | 135 BrowserThread::GetBlockingPool()-> |
| 136 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 136 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, |
| 137 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 137 base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
| 138 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 138 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
| 139 set_wallpaper::Params::Details::ToString(params_->details.layout)); | 139 set_wallpaper::Params::Details::ToString(params_->details.layout)); |
| 140 bool update_wallpaper = | 140 bool update_wallpaper = |
| 141 user_id_ == user_manager::UserManager::Get()->GetActiveUser()->email(); | 141 user_id_ == user_manager::UserManager::Get()->GetActiveUser()->email(); |
| 142 wallpaper_manager->SetCustomWallpaper(user_id_, | 142 wallpaper_manager->SetCustomWallpaper(user_id_, |
| 143 user_id_hash_, | 143 user_id_hash_, |
| 144 params_->details.name, | 144 params_->details.filename, |
| 145 layout, | 145 layout, |
| 146 user_manager::User::CUSTOMIZED, | 146 user_manager::User::CUSTOMIZED, |
| 147 image, | 147 image, |
| 148 update_wallpaper); | 148 update_wallpaper); |
| 149 unsafe_wallpaper_decoder_ = NULL; | 149 unsafe_wallpaper_decoder_ = NULL; |
| 150 | 150 |
| 151 if (params_->details.thumbnail) { | 151 if (params_->details.thumbnail) { |
| 152 image.EnsureRepsForSupportedScales(); | 152 image.EnsureRepsForSupportedScales(); |
| 153 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); | 153 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
| 154 // Generates thumbnail before call api function callback. We can then | 154 // Generates thumbnail before call api function callback. We can then |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( | 202 BinaryValue* result = BinaryValue::CreateWithCopiedBuffer( |
| 203 reinterpret_cast<const char*>(data->front()), data->size()); | 203 reinterpret_cast<const char*>(data->front()), data->size()); |
| 204 SetResult(result); | 204 SetResult(result); |
| 205 SendResponse(true); | 205 SendResponse(true); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void WallpaperSetWallpaperFunction::OnWallpaperFetched( | 208 void WallpaperSetWallpaperFunction::OnWallpaperFetched( |
| 209 bool success, | 209 bool success, |
| 210 const std::string& response) { | 210 const std::string& response) { |
| 211 if (success) { | 211 if (success) { |
| 212 params_->details.wallpaper_data.reset(new std::string(response)); | 212 params_->details.data.reset(new std::string(response)); |
| 213 StartDecode(*params_->details.wallpaper_data); | 213 StartDecode(*params_->details.data); |
| 214 } else { | 214 } else { |
| 215 SetError(response); | 215 SetError(response); |
| 216 SendResponse(false); | 216 SendResponse(false); |
| 217 } | 217 } |
| 218 } | 218 } |
| OLD | NEW |