| 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/options/chromeos/wallpaper_source.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/wallpaper_source.h" |
| 6 | 6 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/synchronization/cancellation_flag.h" | 10 #include "base/synchronization/cancellation_flag.h" |
| 11 #include "base/threading/worker_pool.h" | 11 #include "base/threading/worker_pool.h" |
| 12 #include "chrome/browser/chromeos/login/user_manager.h" | 12 #include "chrome/browser/chromeos/login/user_manager.h" |
| 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "grit/ui_resources.h" | 16 #include "grit/ui_resources.h" |
| 16 #include "net/base/mime_util.h" | 17 #include "net/base/mime_util.h" |
| 17 #include "ui/gfx/codec/png_codec.h" | 18 #include "ui/gfx/codec/png_codec.h" |
| 18 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
| 19 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 20 | 21 |
| 21 extern "C" { | 22 extern "C" { |
| 22 #include "third_party/zlib/zlib.h" | 23 #include "third_party/zlib/zlib.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 int request_id_; | 88 int request_id_; |
| 88 // Buffer to store encoded image. | 89 // Buffer to store encoded image. |
| 89 scoped_refptr<base::RefCountedBytes> data_; | 90 scoped_refptr<base::RefCountedBytes> data_; |
| 90 // Original image to encode. | 91 // Original image to encode. |
| 91 SkBitmap image_; | 92 SkBitmap image_; |
| 92 | 93 |
| 93 DISALLOW_COPY_AND_ASSIGN(WallpaperEncodingOperation); | 94 DISALLOW_COPY_AND_ASSIGN(WallpaperEncodingOperation); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 WallpaperImageSource::WallpaperImageSource() | 97 WallpaperImageSource::WallpaperImageSource() |
| 97 : DataSource(chrome::kChromeUIWallpaperImageHost, NULL), | 98 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 98 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
| 99 } | 99 } |
| 100 | 100 |
| 101 WallpaperImageSource::~WallpaperImageSource() { | 101 WallpaperImageSource::~WallpaperImageSource() { |
| 102 } | 102 } |
| 103 | 103 |
| 104 std::string WallpaperImageSource::GetSource() { |
| 105 return chrome::kChromeUIWallpaperImageHost; |
| 106 } |
| 107 |
| 104 void WallpaperImageSource::StartDataRequest(const std::string& email, | 108 void WallpaperImageSource::StartDataRequest(const std::string& email, |
| 105 bool is_incognito, | 109 bool is_incognito, |
| 106 int request_id) { | 110 int request_id) { |
| 107 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 108 TRACE_EVENT_ASYNC_BEGIN0("SCREEN_LOCK", "GetUserWallpaperDataRequest", | 112 TRACE_EVENT_ASYNC_BEGIN0("SCREEN_LOCK", "GetUserWallpaperDataRequest", |
| 109 request_id); | 113 request_id); |
| 110 CancelPendingEncodingOperation(); | 114 CancelPendingEncodingOperation(); |
| 111 content::BrowserThread::PostTask( | 115 content::BrowserThread::PostTask( |
| 112 content::BrowserThread::UI, | 116 content::BrowserThread::UI, |
| 113 FROM_HERE, | 117 FROM_HERE, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 base::Bind(&WallpaperImageSource::SendCurrentUserWallpaper, | 160 base::Bind(&WallpaperImageSource::SendCurrentUserWallpaper, |
| 157 weak_ptr_factory_.GetWeakPtr(), request_id, data), | 161 weak_ptr_factory_.GetWeakPtr(), request_id, data), |
| 158 true /* task_is_slow */); | 162 true /* task_is_slow */); |
| 159 }; | 163 }; |
| 160 | 164 |
| 161 void WallpaperImageSource::CancelPendingEncodingOperation() { | 165 void WallpaperImageSource::CancelPendingEncodingOperation() { |
| 162 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 166 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 163 // Set canceled flag of previous request to skip unneeded encoding. | 167 // Set canceled flag of previous request to skip unneeded encoding. |
| 164 if (wallpaper_encoding_op_.get()) { | 168 if (wallpaper_encoding_op_.get()) { |
| 165 wallpaper_encoding_op_->Cancel(); | 169 wallpaper_encoding_op_->Cancel(); |
| 166 SendResponse(wallpaper_encoding_op_->request_id(), NULL); | 170 url_data_source()->SendResponse(wallpaper_encoding_op_->request_id(), NULL); |
| 167 TRACE_EVENT_ASYNC_END0("SCREEN_LOCK", "GetUserWallpaper", | 171 TRACE_EVENT_ASYNC_END0("SCREEN_LOCK", "GetUserWallpaper", |
| 168 wallpaper_encoding_op_->request_id()); | 172 wallpaper_encoding_op_->request_id()); |
| 169 } | 173 } |
| 170 | 174 |
| 171 // Cancel reply callback for previous request. | 175 // Cancel reply callback for previous request. |
| 172 weak_ptr_factory_.InvalidateWeakPtrs(); | 176 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 173 } | 177 } |
| 174 | 178 |
| 175 void WallpaperImageSource::SendCurrentUserWallpaper(int request_id, | 179 void WallpaperImageSource::SendCurrentUserWallpaper(int request_id, |
| 176 scoped_refptr<base::RefCountedBytes> data) { | 180 scoped_refptr<base::RefCountedBytes> data) { |
| 177 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 178 SendResponse(request_id, data); | 182 url_data_source()->SendResponse(request_id, data); |
| 179 TRACE_EVENT_ASYNC_END0("SCREEN_LOCK", "GetUserWallpaper", request_id); | 183 TRACE_EVENT_ASYNC_END0("SCREEN_LOCK", "GetUserWallpaper", request_id); |
| 180 } | 184 } |
| 181 | 185 |
| 182 } // namespace options | 186 } // namespace options |
| 183 } // namespace chromeos | 187 } // namespace chromeos |
| OLD | NEW |