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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 } | 97 } |
98 | 98 |
99 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { | 99 WallpaperSetWallpaperFunction::~WallpaperSetWallpaperFunction() { |
100 } | 100 } |
101 | 101 |
102 bool WallpaperSetWallpaperFunction::RunAsync() { | 102 bool WallpaperSetWallpaperFunction::RunAsync() { |
103 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 103 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
104 params_ = set_wallpaper::Params::Create(*args_); | 104 params_ = set_wallpaper::Params::Create(*args_); |
105 EXTENSION_FUNCTION_VALIDATE(params_); | 105 EXTENSION_FUNCTION_VALIDATE(params_); |
106 | 106 |
107 // Gets email address and username hash while at UI thread. | 107 // Gets account id and username hash while at UI thread. |
108 user_id_ = user_manager::UserManager::Get()->GetLoggedInUser()->email(); | 108 account_id_ = |
| 109 user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId(); |
109 user_id_hash_ = | 110 user_id_hash_ = |
110 user_manager::UserManager::Get()->GetLoggedInUser()->username_hash(); | 111 user_manager::UserManager::Get()->GetLoggedInUser()->username_hash(); |
111 | 112 |
112 if (params_->details.data) { | 113 if (params_->details.data) { |
113 StartDecode(*params_->details.data); | 114 StartDecode(*params_->details.data); |
114 } else { | 115 } else { |
115 GURL wallpaper_url(*params_->details.url); | 116 GURL wallpaper_url(*params_->details.url); |
116 if (wallpaper_url.is_valid()) { | 117 if (wallpaper_url.is_valid()) { |
117 g_wallpaper_fetcher.Get().FetchWallpaper( | 118 g_wallpaper_fetcher.Get().FetchWallpaper( |
118 wallpaper_url, | 119 wallpaper_url, |
(...skipping 18 matching lines...) Expand all Loading... |
137 wallpaper::kWallpaperSequenceTokenName); | 138 wallpaper::kWallpaperSequenceTokenName); |
138 scoped_refptr<base::SequencedTaskRunner> task_runner = | 139 scoped_refptr<base::SequencedTaskRunner> task_runner = |
139 BrowserThread::GetBlockingPool()-> | 140 BrowserThread::GetBlockingPool()-> |
140 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 141 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, |
141 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | 142 base::SequencedWorkerPool::BLOCK_SHUTDOWN); |
142 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 143 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
143 extensions::api::wallpaper::ToString(params_->details.layout)); | 144 extensions::api::wallpaper::ToString(params_->details.layout)); |
144 wallpaper_api_util::RecordCustomWallpaperLayout(layout); | 145 wallpaper_api_util::RecordCustomWallpaperLayout(layout); |
145 | 146 |
146 bool update_wallpaper = | 147 bool update_wallpaper = |
147 user_id_ == user_manager::UserManager::Get()->GetActiveUser()->email(); | 148 account_id_ == |
148 wallpaper_manager->SetCustomWallpaper(user_id_, | 149 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); |
149 user_id_hash_, | 150 wallpaper_manager->SetCustomWallpaper( |
150 params_->details.filename, | 151 account_id_, user_id_hash_, params_->details.filename, layout, |
151 layout, | 152 user_manager::User::CUSTOMIZED, image, update_wallpaper); |
152 user_manager::User::CUSTOMIZED, | |
153 image, | |
154 update_wallpaper); | |
155 unsafe_wallpaper_decoder_ = NULL; | 153 unsafe_wallpaper_decoder_ = NULL; |
156 | 154 |
157 if (params_->details.thumbnail) { | 155 if (params_->details.thumbnail) { |
158 image.EnsureRepsForSupportedScales(); | 156 image.EnsureRepsForSupportedScales(); |
159 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); | 157 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
160 // Generates thumbnail before call api function callback. We can then | 158 // Generates thumbnail before call api function callback. We can then |
161 // request thumbnail in the javascript callback. | 159 // request thumbnail in the javascript callback. |
162 task_runner->PostTask( | 160 task_runner->PostTask( |
163 FROM_HERE, | 161 FROM_HERE, |
164 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, | 162 base::Bind(&WallpaperSetWallpaperFunction::GenerateThumbnail, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 const std::string& response) { | 224 const std::string& response) { |
227 if (success) { | 225 if (success) { |
228 params_->details.data.reset( | 226 params_->details.data.reset( |
229 new std::vector<char>(response.begin(), response.end())); | 227 new std::vector<char>(response.begin(), response.end())); |
230 StartDecode(*params_->details.data); | 228 StartDecode(*params_->details.data); |
231 } else { | 229 } else { |
232 SetError(response); | 230 SetError(response); |
233 SendResponse(false); | 231 SendResponse(false); |
234 } | 232 } |
235 } | 233 } |
OLD | NEW |