Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.cc

Issue 8879048: [cros] Change Picture prefs page: DOM initialization moved to separate handler from Initialize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 content::NotificationService::AllSources()); 66 content::NotificationService::AllSources());
67 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, 67 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
68 content::NotificationService::AllSources()); 68 content::NotificationService::AllSources());
69 } 69 }
70 70
71 ChangePictureOptionsHandler::~ChangePictureOptionsHandler() { 71 ChangePictureOptionsHandler::~ChangePictureOptionsHandler() {
72 if (select_file_dialog_.get()) 72 if (select_file_dialog_.get())
73 select_file_dialog_->ListenerDestroyed(); 73 select_file_dialog_->ListenerDestroyed();
74 } 74 }
75 75
76 void ChangePictureOptionsHandler::Initialize() {
77 // If no camera presence check has been performed in this session,
78 // start one now.
79 if (CameraDetector::camera_presence() ==
80 CameraDetector::kCameraPresenceUnknown)
81 CheckCameraPresence();
82
83 // While the check is in progress, use previous camera presence state and
84 // presume it is present if no check has been performed yet.
85 SetCameraPresent(CameraDetector::camera_presence() !=
86 CameraDetector::kCameraAbsent);
87
88 SendAvailableImages();
89 }
90
91 void ChangePictureOptionsHandler::GetLocalizedValues( 76 void ChangePictureOptionsHandler::GetLocalizedValues(
92 DictionaryValue* localized_strings) { 77 DictionaryValue* localized_strings) {
93 DCHECK(localized_strings); 78 DCHECK(localized_strings);
94 localized_strings->SetString("changePicturePage", 79 localized_strings->SetString("changePicturePage",
95 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TITLE)); 80 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TITLE));
96 localized_strings->SetString("changePicturePageDescription", 81 localized_strings->SetString("changePicturePageDescription",
97 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TEXT)); 82 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TEXT));
98 localized_strings->SetString("takePhoto", 83 localized_strings->SetString("takePhoto",
99 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_TAKE_PHOTO)); 84 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_TAKE_PHOTO));
100 localized_strings->SetString("chooseFile", 85 localized_strings->SetString("chooseFile",
101 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_CHOOSE_FILE)); 86 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_CHOOSE_FILE));
102 localized_strings->SetString("profilePhoto", 87 localized_strings->SetString("profilePhoto",
103 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_PROFILE_PHOTO)); 88 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_PROFILE_PHOTO));
104 localized_strings->SetString("profilePhotoLoading", 89 localized_strings->SetString("profilePhotoLoading",
105 l10n_util::GetStringUTF16( 90 l10n_util::GetStringUTF16(
106 IDS_OPTIONS_CHANGE_PICTURE_PROFILE_LOADING_PHOTO)); 91 IDS_OPTIONS_CHANGE_PICTURE_PROFILE_LOADING_PHOTO));
107 } 92 }
108 93
109 void ChangePictureOptionsHandler::RegisterMessages() { 94 void ChangePictureOptionsHandler::RegisterMessages() {
110 DCHECK(web_ui_); 95 DCHECK(web_ui_);
111 web_ui_->RegisterMessageCallback("chooseFile", 96 web_ui_->RegisterMessageCallback("chooseFile",
112 base::Bind(&ChangePictureOptionsHandler::HandleChooseFile, 97 base::Bind(&ChangePictureOptionsHandler::HandleChooseFile,
113 base::Unretained(this))); 98 base::Unretained(this)));
114 web_ui_->RegisterMessageCallback("takePhoto", 99 web_ui_->RegisterMessageCallback("takePhoto",
115 base::Bind(&ChangePictureOptionsHandler::HandleTakePhoto, 100 base::Bind(&ChangePictureOptionsHandler::HandleTakePhoto,
116 base::Unretained(this))); 101 base::Unretained(this)));
117 web_ui_->RegisterMessageCallback("onPageShown", 102 web_ui_->RegisterMessageCallback("onChangePicturePageShown",
118 base::Bind(&ChangePictureOptionsHandler::HandleOnPageShown, 103 base::Bind(&ChangePictureOptionsHandler::HandlePageShown,
104 base::Unretained(this)));
105 web_ui_->RegisterMessageCallback("onChangePicturePageInitialized",
106 base::Bind(&ChangePictureOptionsHandler::HandlePageInitialized,
119 base::Unretained(this))); 107 base::Unretained(this)));
120 web_ui_->RegisterMessageCallback("selectImage", 108 web_ui_->RegisterMessageCallback("selectImage",
121 base::Bind(&ChangePictureOptionsHandler::HandleSelectImage, 109 base::Bind(&ChangePictureOptionsHandler::HandleSelectImage,
122 base::Unretained(this))); 110 base::Unretained(this)));
123 } 111 }
124 112
125 void ChangePictureOptionsHandler::SendAvailableImages() { 113 void ChangePictureOptionsHandler::SendDefaultImages() {
126 ListValue image_urls; 114 ListValue image_urls;
127 for (int i = 0; i < kDefaultImagesCount; ++i) { 115 for (int i = 0; i < kDefaultImagesCount; ++i) {
128 image_urls.Append(new StringValue(GetDefaultImageUrl(i))); 116 image_urls.Append(new StringValue(GetDefaultImageUrl(i)));
129 } 117 }
130 web_ui_->CallJavascriptFunction("ChangePictureOptions.setUserImages", 118 web_ui_->CallJavascriptFunction("ChangePictureOptions.setDefaultImages",
131 image_urls); 119 image_urls);
132 } 120 }
133 121
134 void ChangePictureOptionsHandler::HandleChooseFile(const ListValue* args) { 122 void ChangePictureOptionsHandler::HandleChooseFile(const ListValue* args) {
135 DCHECK(args && args->empty()); 123 DCHECK(args && args->empty());
136 if (!select_file_dialog_.get()) 124 if (!select_file_dialog_.get())
137 select_file_dialog_ = SelectFileDialog::Create(this); 125 select_file_dialog_ = SelectFileDialog::Create(this);
138 126
139 FilePath downloads_path; 127 FilePath downloads_path;
140 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) { 128 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) {
(...skipping 20 matching lines...) Expand all
161 void ChangePictureOptionsHandler::HandleTakePhoto(const ListValue* args) { 149 void ChangePictureOptionsHandler::HandleTakePhoto(const ListValue* args) {
162 DCHECK(args && args->empty()); 150 DCHECK(args && args->empty());
163 views::Widget* window = browser::CreateViewsWindow( 151 views::Widget* window = browser::CreateViewsWindow(
164 GetBrowserWindow(), 152 GetBrowserWindow(),
165 new TakePhotoDialog(this), 153 new TakePhotoDialog(this),
166 STYLE_GENERIC); 154 STYLE_GENERIC);
167 window->SetAlwaysOnTop(true); 155 window->SetAlwaysOnTop(true);
168 window->Show(); 156 window->Show();
169 } 157 }
170 158
171 void ChangePictureOptionsHandler::HandleOnPageShown( 159 void ChangePictureOptionsHandler::HandlePageInitialized(
172 const base::ListValue* args) { 160 const base::ListValue* args) {
173 DCHECK(args && args->empty()); 161 DCHECK(args && args->empty());
162 // If no camera presence check has been performed in this session,
163 // start one now.
164 if (CameraDetector::camera_presence() ==
165 CameraDetector::kCameraPresenceUnknown) {
166 CheckCameraPresence();
167 }
168
169 // While the check is in progress, use previous camera presence state and
170 // presume it is present if no check has been performed yet.
171 SetCameraPresent(CameraDetector::camera_presence() !=
172 CameraDetector::kCameraAbsent);
173
174 SendDefaultImages();
175 }
176
177 void ChangePictureOptionsHandler::HandlePageShown(const base::ListValue* args) {
178 DCHECK(args && args->empty());
179 // TODO(ivankr): If user opens settings and goes to Change Picture page right
180 // after the check started |HandlePageInitialized| has been completed,
181 // |CheckCameraPresence| will be called twice, should be throttled.
174 CheckCameraPresence(); 182 CheckCameraPresence();
175 SendSelectedImage(); 183 SendSelectedImage();
176 UpdateProfileImage(); 184 UpdateProfileImage();
177 } 185 }
178 186
179 void ChangePictureOptionsHandler::SendSelectedImage() { 187 void ChangePictureOptionsHandler::SendSelectedImage() {
180 const User& user = UserManager::Get()->logged_in_user(); 188 const User& user = UserManager::Get()->logged_in_user();
181 DCHECK(!user.email().empty()); 189 DCHECK(!user.email().empty());
182 190
183 previous_image_index_ = user.image_index(); 191 previous_image_index_ = user.image_index();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 336
329 gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const { 337 gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const {
330 Browser* browser = 338 Browser* browser =
331 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui_)); 339 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui_));
332 if (!browser) 340 if (!browser)
333 return NULL; 341 return NULL;
334 return browser->window()->GetNativeHandle(); 342 return browser->window()->GetNativeHandle();
335 } 343 }
336 344
337 } // namespace chromeos 345 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698