Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/options2/chromeos/wallpaper_thumbnail_source.h " | 5 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source.h " |
| 6 | 6 |
| 7 #include "ash/desktop_background/desktop_background_resources.h" | 7 #include "ash/desktop_background/desktop_background_resources.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_piece.h" | 11 #include "base/string_piece.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/synchronization/cancellation_flag.h" | 14 #include "base/synchronization/cancellation_flag.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" | 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 18 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 19 #include "chrome/browser/io_thread.h" | 19 #include "chrome/browser/io_thread.h" |
| 20 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 20 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 21 #include "chrome/browser/ui/webui/web_ui_util.h" | |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "grit/ui_resources.h" | 24 #include "grit/ui_resources.h" |
| 24 #include "net/base/mime_util.h" | 25 #include "net/base/mime_util.h" |
| 25 #include "ui/base/layout.h" | 26 #include "ui/base/layout.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
| 28 | 29 |
| 29 namespace chromeos { | 30 namespace chromeos { |
| 30 namespace options2 { | 31 namespace options2 { |
| 31 | 32 |
| 32 class WallpaperThumbnailSource::ThumbnailEncodingOperation | 33 class WallpaperThumbnailSource::ThumbnailEncodingOperation |
| 33 : public base::RefCountedThreadSafe< | 34 : public base::RefCountedThreadSafe< |
| 34 WallpaperThumbnailSource::ThumbnailEncodingOperation> { | 35 WallpaperThumbnailSource::ThumbnailEncodingOperation> { |
| 35 public: | 36 public: |
| 36 ThumbnailEncodingOperation(int request_id, | 37 ThumbnailEncodingOperation(int request_id, |
| 37 const chromeos::User* user, | 38 const chromeos::User* user, |
| 39 ui::ScaleFactor scale_factor, | |
| 38 scoped_refptr<base::RefCountedBytes> data) | 40 scoped_refptr<base::RefCountedBytes> data) |
| 39 : request_id_(request_id), | 41 : request_id_(request_id), |
| 40 user_(user), | 42 user_(user), |
| 43 scale_factor_(scale_factor), | |
| 41 data_(data) { | 44 data_(data) { |
| 42 } | 45 } |
| 43 | 46 |
| 44 int request_id() { | 47 int request_id() { |
| 45 return request_id_; | 48 return request_id_; |
| 46 } | 49 } |
| 47 | 50 |
| 48 static void Run(scoped_refptr<ThumbnailEncodingOperation> teo) { | 51 static void Run(scoped_refptr<ThumbnailEncodingOperation> teo) { |
| 49 teo->EncodeThumbnail(); | 52 teo->EncodeThumbnail(); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void EncodeThumbnail() { | 55 void EncodeThumbnail() { |
| 53 if (cancel_flag_.IsSet()) | 56 if (cancel_flag_.IsSet()) |
| 54 return; | 57 return; |
| 58 gfx::ImageSkia image = | |
| 59 WallpaperManager::Get()->GetCustomWallpaperThumbnail(user_->email()); | |
| 55 gfx::PNGCodec::EncodeBGRASkBitmap( | 60 gfx::PNGCodec::EncodeBGRASkBitmap( |
| 56 WallpaperManager::Get()->GetCustomWallpaperThumbnail(user_->email()), | 61 image.GetRepresentation(scale_factor_).sk_bitmap(), |
| 57 false, &data_->data()); | 62 false, &data_->data()); |
| 58 } | 63 } |
| 59 | 64 |
| 60 void Cancel() { | 65 void Cancel() { |
| 61 cancel_flag_.Set(); | 66 cancel_flag_.Set(); |
| 62 } | 67 } |
| 63 | 68 |
| 64 private: | 69 private: |
| 65 friend class base::RefCountedThreadSafe< | 70 friend class base::RefCountedThreadSafe< |
| 66 WallpaperThumbnailSource::ThumbnailEncodingOperation>; | 71 WallpaperThumbnailSource::ThumbnailEncodingOperation>; |
| 67 | 72 |
| 68 ~ThumbnailEncodingOperation() {} | 73 ~ThumbnailEncodingOperation() {} |
| 69 | 74 |
| 70 base::CancellationFlag cancel_flag_; | 75 base::CancellationFlag cancel_flag_; |
| 71 | 76 |
| 72 int request_id_; | 77 int request_id_; |
| 73 | 78 |
| 74 const chromeos::User* user_; | 79 const chromeos::User* user_; |
| 75 | 80 |
| 81 ui::ScaleFactor scale_factor_; | |
| 82 | |
| 76 scoped_refptr<base::RefCountedBytes> data_; | 83 scoped_refptr<base::RefCountedBytes> data_; |
| 77 | 84 |
| 78 DISALLOW_COPY_AND_ASSIGN(ThumbnailEncodingOperation); | 85 DISALLOW_COPY_AND_ASSIGN(ThumbnailEncodingOperation); |
| 79 }; | 86 }; |
| 80 | 87 |
| 81 namespace { | 88 namespace { |
| 82 | 89 |
| 83 const char kDefaultWallpaperPrefix[] = "default_"; | 90 const char kDefaultWallpaperPrefix[] = "default_"; |
| 84 const char kCustomWallpaperPrefix[] = "custom_"; | 91 const char kCustomWallpaperPrefix[] = "custom_"; |
| 85 | 92 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 144 |
| 138 WallpaperThumbnailSource::WallpaperThumbnailSource() | 145 WallpaperThumbnailSource::WallpaperThumbnailSource() |
| 139 : DataSource(chrome::kChromeUIWallpaperThumbnailHost, NULL), | 146 : DataSource(chrome::kChromeUIWallpaperThumbnailHost, NULL), |
| 140 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 147 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 141 } | 148 } |
| 142 | 149 |
| 143 std::string WallpaperThumbnailSource::GetMimeType(const std::string&) const { | 150 std::string WallpaperThumbnailSource::GetMimeType(const std::string&) const { |
| 144 return "images/png"; | 151 return "images/png"; |
| 145 } | 152 } |
| 146 | 153 |
| 147 void WallpaperThumbnailSource::StartDataRequest(const std::string& path, | 154 void WallpaperThumbnailSource::StartDataRequest(const std::string& full_path, |
| 148 bool is_incognito, | 155 bool is_incognito, |
| 149 int request_id) { | 156 int request_id) { |
| 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 157 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 158 GURL url(chrome::kChromeUIWallpaperThumbnailURL + full_path); | |
| 159 std::string path; | |
| 160 ui::ScaleFactor scale_factor; | |
|
Ivan Korotkov
2012/08/15 20:36:03
Does the URL ever include username@domain? In that
sadrul
2012/08/15 20:53:28
Good point! I discussed with bshe@, and username@d
sadrul
2012/08/15 22:28:53
I have also submitted http://codereview.chromium.o
Ivan Korotkov
2012/08/16 08:44:17
Thanks! With CL 10837270 submitted it should be sa
| |
| 161 web_ui_util::ParsePathAndScale(url, &path, &scale_factor); | |
| 162 | |
| 151 CancelPendingCustomThumbnailEncodingOperation(); | 163 CancelPendingCustomThumbnailEncodingOperation(); |
| 152 content::BrowserThread::PostTask( | 164 content::BrowserThread::PostTask( |
| 153 content::BrowserThread::UI, | 165 content::BrowserThread::UI, |
| 154 FROM_HERE, | 166 FROM_HERE, |
| 155 base::Bind(&WallpaperThumbnailSource::GetCurrentUserThumbnail, | 167 base::Bind(&WallpaperThumbnailSource::GetCurrentUserThumbnail, |
| 156 this, path, request_id)); | 168 this, path, scale_factor, request_id)); |
| 157 } | 169 } |
| 158 | 170 |
| 159 WallpaperThumbnailSource::~WallpaperThumbnailSource() { | 171 WallpaperThumbnailSource::~WallpaperThumbnailSource() { |
| 160 } | 172 } |
| 161 | 173 |
| 162 void WallpaperThumbnailSource::GetCurrentUserThumbnail( | 174 void WallpaperThumbnailSource::GetCurrentUserThumbnail( |
| 163 const std::string& path, | 175 const std::string& path, |
| 176 ui::ScaleFactor scale_factor, | |
| 164 int request_id) { | 177 int request_id) { |
| 165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 178 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 166 std::string email; | 179 std::string email; |
| 167 if (IsCustomWallpaperPath(path, &email)) { | 180 if (IsCustomWallpaperPath(path, &email)) { |
| 168 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); | 181 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(email); |
| 169 if (!user) { | 182 if (!user) { |
| 170 content::BrowserThread::PostTask( | 183 content::BrowserThread::PostTask( |
| 171 content::BrowserThread::IO, | 184 content::BrowserThread::IO, |
| 172 FROM_HERE, | 185 FROM_HERE, |
| 173 base::Bind(&WallpaperThumbnailSource::SendCurrentUserNullThumbnail, | 186 base::Bind(&WallpaperThumbnailSource::SendCurrentUserNullThumbnail, |
| 174 this, request_id)); | 187 this, request_id)); |
| 175 return; | 188 return; |
| 176 } | 189 } |
| 177 content::BrowserThread::PostTask( | 190 content::BrowserThread::PostTask( |
| 178 content::BrowserThread::IO, | 191 content::BrowserThread::IO, |
| 179 FROM_HERE, | 192 FROM_HERE, |
| 180 base::Bind( | 193 base::Bind( |
| 181 &WallpaperThumbnailSource::StartCustomThumbnailEncodingOperation, | 194 &WallpaperThumbnailSource::StartCustomThumbnailEncodingOperation, |
| 182 this, user, request_id)); | 195 this, user, scale_factor, request_id)); |
| 183 return; | 196 return; |
| 184 } | 197 } |
| 185 content::BrowserThread::PostTask( | 198 content::BrowserThread::PostTask( |
| 186 content::BrowserThread::IO, | 199 content::BrowserThread::IO, |
| 187 FROM_HERE, | 200 FROM_HERE, |
| 188 base::Bind(&WallpaperThumbnailSource::SendCurrentUserDefaultThumbnail, | 201 base::Bind(&WallpaperThumbnailSource::SendCurrentUserDefaultThumbnail, |
| 189 this, path, request_id)); | 202 this, path, scale_factor, request_id)); |
| 190 } | 203 } |
| 191 | 204 |
| 192 void WallpaperThumbnailSource::StartCustomThumbnailEncodingOperation( | 205 void WallpaperThumbnailSource::StartCustomThumbnailEncodingOperation( |
| 193 const chromeos::User* user, | 206 const chromeos::User* user, |
| 207 ui::ScaleFactor scale_factor, | |
| 194 int request_id) { | 208 int request_id) { |
| 195 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 209 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 196 CancelPendingCustomThumbnailEncodingOperation(); | 210 CancelPendingCustomThumbnailEncodingOperation(); |
| 197 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); | 211 scoped_refptr<base::RefCountedBytes> data = new base::RefCountedBytes(); |
| 198 thumbnail_encoding_op_ = new ThumbnailEncodingOperation(request_id, | 212 thumbnail_encoding_op_ = new ThumbnailEncodingOperation(request_id, |
| 199 user, | 213 user, |
| 214 scale_factor, | |
| 200 data); | 215 data); |
| 201 base::WorkerPool::PostTaskAndReply( | 216 base::WorkerPool::PostTaskAndReply( |
| 202 FROM_HERE, | 217 FROM_HERE, |
| 203 base::Bind(&ThumbnailEncodingOperation::Run, thumbnail_encoding_op_), | 218 base::Bind(&ThumbnailEncodingOperation::Run, thumbnail_encoding_op_), |
| 204 base::Bind(&WallpaperThumbnailSource::SendCurrentUserCustomThumbnail, | 219 base::Bind(&WallpaperThumbnailSource::SendCurrentUserCustomThumbnail, |
| 205 weak_ptr_factory_.GetWeakPtr(), data, request_id), | 220 weak_ptr_factory_.GetWeakPtr(), data, request_id), |
| 206 true /* task_is_slow */); | 221 true /* task_is_slow */); |
| 207 } | 222 } |
| 208 | 223 |
| 209 void WallpaperThumbnailSource::CancelPendingCustomThumbnailEncodingOperation() { | 224 void WallpaperThumbnailSource::CancelPendingCustomThumbnailEncodingOperation() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 222 | 237 |
| 223 void WallpaperThumbnailSource::SendCurrentUserCustomThumbnail( | 238 void WallpaperThumbnailSource::SendCurrentUserCustomThumbnail( |
| 224 scoped_refptr<base::RefCountedBytes> data, | 239 scoped_refptr<base::RefCountedBytes> data, |
| 225 int request_id) { | 240 int request_id) { |
| 226 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 241 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 227 SendResponse(request_id, data); | 242 SendResponse(request_id, data); |
| 228 } | 243 } |
| 229 | 244 |
| 230 void WallpaperThumbnailSource::SendCurrentUserDefaultThumbnail( | 245 void WallpaperThumbnailSource::SendCurrentUserDefaultThumbnail( |
| 231 const std::string& path, | 246 const std::string& path, |
| 247 ui::ScaleFactor scale_factor, | |
| 232 int request_id) { | 248 int request_id) { |
| 233 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 249 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 234 int idr = PathToIDR(path); | 250 int idr = PathToIDR(path); |
| 235 if (idr == -1) { | 251 if (idr == -1) { |
| 236 SendResponse(request_id, NULL); | 252 SendResponse(request_id, NULL); |
| 237 return; | 253 return; |
| 238 } | 254 } |
| 239 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 255 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 240 SendResponse(request_id, | 256 SendResponse(request_id, |
| 241 rb.LoadDataResourceBytes(idr, ui::SCALE_FACTOR_100P)); | 257 rb.LoadDataResourceBytes(idr, scale_factor)); |
| 242 } | 258 } |
| 243 | 259 |
| 244 } // namespace options2 | 260 } // namespace options2 |
| 245 } // namespace chromeos | 261 } // namespace chromeos |
| OLD | NEW |