OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/ui/webui/options/chromeos/change_picture_options_handle
r.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/change_picture_options_handle
r.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/chromeos/camera_detector.h" | 15 #include "chrome/browser/chromeos/camera_detector.h" |
16 #include "chrome/browser/chromeos/login/default_user_images.h" | 16 #include "chrome/browser/chromeos/login/default_user_images.h" |
17 #include "chrome/browser/chromeos/login/user_image.h" | 17 #include "chrome/browser/chromeos/login/user_image.h" |
18 #include "chrome/browser/chromeos/login/user_image_manager.h" | 18 #include "chrome/browser/chromeos/login/user_image_manager.h" |
19 #include "chrome/browser/chromeos/login/user_manager.h" | 19 #include "chrome/browser/chromeos/login/user_manager.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/chrome_select_file_policy.h" | 22 #include "chrome/browser/ui/chrome_select_file_policy.h" |
23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 27 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
29 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
30 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
32 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
33 #include "net/base/data_url.h" | 34 #include "net/base/data_url.h" |
34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
35 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
36 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
37 #include "ui/webui/web_ui_util.h" | 38 #include "ui/webui/web_ui_util.h" |
38 | 39 |
| 40 using content::BrowserThread; |
| 41 |
39 namespace chromeos { | 42 namespace chromeos { |
40 namespace options { | 43 namespace options { |
41 | 44 |
42 namespace { | 45 namespace { |
43 | 46 |
44 // Returns info about extensions for files we support as user images. | 47 // Returns info about extensions for files we support as user images. |
45 ui::SelectFileDialog::FileTypeInfo GetUserImageFileTypeInfo() { | 48 ui::SelectFileDialog::FileTypeInfo GetUserImageFileTypeInfo() { |
46 ui::SelectFileDialog::FileTypeInfo file_type_info; | 49 ui::SelectFileDialog::FileTypeInfo file_type_info; |
47 file_type_info.extensions.resize(1); | 50 file_type_info.extensions.resize(1); |
48 | 51 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 downloads_path, | 174 downloads_path, |
172 &file_type_info, | 175 &file_type_info, |
173 0, | 176 0, |
174 FILE_PATH_LITERAL(""), | 177 FILE_PATH_LITERAL(""), |
175 GetBrowserWindow(), | 178 GetBrowserWindow(), |
176 NULL); | 179 NULL); |
177 } | 180 } |
178 | 181 |
179 void ChangePictureOptionsHandler::HandlePhotoTaken( | 182 void ChangePictureOptionsHandler::HandlePhotoTaken( |
180 const base::ListValue* args) { | 183 const base::ListValue* args) { |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
181 std::string image_url; | 185 std::string image_url; |
182 if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url)) | 186 if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url)) |
183 NOTREACHED(); | 187 NOTREACHED(); |
184 DCHECK(!image_url.empty()); | 188 DCHECK(!image_url.empty()); |
185 | 189 |
186 std::string mime_type, charset, raw_data; | 190 std::string mime_type, charset, raw_data; |
187 if (!net::DataURL::Parse(GURL(image_url), &mime_type, &charset, &raw_data)) | 191 if (!net::DataURL::Parse(GURL(image_url), &mime_type, &charset, &raw_data)) |
188 NOTREACHED(); | 192 NOTREACHED(); |
189 DCHECK_EQ("image/png", mime_type); | 193 DCHECK_EQ("image/png", mime_type); |
190 | 194 |
191 user_photo_ = gfx::ImageSkia(); | 195 user_photo_ = gfx::ImageSkia(); |
192 user_photo_data_url_ = image_url; | 196 user_photo_data_url_ = image_url; |
193 | 197 |
194 if (image_decoder_.get()) | 198 if (image_decoder_.get()) |
195 image_decoder_->set_delegate(NULL); | 199 image_decoder_->set_delegate(NULL); |
196 image_decoder_ = new ImageDecoder(this, raw_data, | 200 image_decoder_ = new ImageDecoder(this, raw_data, |
197 ImageDecoder::DEFAULT_CODEC); | 201 ImageDecoder::DEFAULT_CODEC); |
198 image_decoder_->Start(); | 202 scoped_refptr<base::MessageLoopProxy> task_runner = |
| 203 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 204 image_decoder_->Start(task_runner); |
199 } | 205 } |
200 | 206 |
201 void ChangePictureOptionsHandler::HandleCheckCameraPresence( | 207 void ChangePictureOptionsHandler::HandleCheckCameraPresence( |
202 const base::ListValue* args) { | 208 const base::ListValue* args) { |
203 DCHECK(args->empty()); | 209 DCHECK(args->empty()); |
204 CheckCameraPresence(); | 210 CheckCameraPresence(); |
205 } | 211 } |
206 | 212 |
207 void ChangePictureOptionsHandler::HandlePageInitialized( | 213 void ChangePictureOptionsHandler::HandlePageInitialized( |
208 const base::ListValue* args) { | 214 const base::ListValue* args) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 SetImageFromCamera(user_photo_); | 430 SetImageFromCamera(user_photo_); |
425 } | 431 } |
426 | 432 |
427 void ChangePictureOptionsHandler::OnDecodeImageFailed( | 433 void ChangePictureOptionsHandler::OnDecodeImageFailed( |
428 const ImageDecoder* decoder) { | 434 const ImageDecoder* decoder) { |
429 NOTREACHED() << "Failed to decode PNG image from WebUI"; | 435 NOTREACHED() << "Failed to decode PNG image from WebUI"; |
430 } | 436 } |
431 | 437 |
432 } // namespace options | 438 } // namespace options |
433 } // namespace chromeos | 439 } // namespace chromeos |
OLD | NEW |