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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/change_picture_handler.cc

Issue 2480603003: [MD Settings][People] Fixes take picture button disappearing on page refresh (Closed)
Patch Set: Addressed comment Created 4 years, 1 month 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
« no previous file with comments | « no previous file | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/settings/chromeos/change_picture_handler.h" 5 #include "chrome/browser/ui/webui/settings/chromeos/change_picture_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 base::Unretained(this))); 115 base::Unretained(this)));
116 } 116 }
117 117
118 void ChangePictureHandler::OnJavascriptAllowed() { 118 void ChangePictureHandler::OnJavascriptAllowed() {
119 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, 119 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED,
120 content::NotificationService::AllSources()); 120 content::NotificationService::AllSources());
121 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, 121 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED,
122 content::NotificationService::AllSources()); 122 content::NotificationService::AllSources());
123 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, 123 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
124 content::NotificationService::AllSources()); 124 content::NotificationService::AllSources());
125
126 camera_observer_.Add(CameraPresenceNotifier::GetInstance());
125 } 127 }
126 128
127 void ChangePictureHandler::OnJavascriptDisallowed() { 129 void ChangePictureHandler::OnJavascriptDisallowed() {
128 registrar_.RemoveAll(); 130 registrar_.RemoveAll();
131
132 camera_observer_.Remove(CameraPresenceNotifier::GetInstance());
129 } 133 }
130 134
131 void ChangePictureHandler::SendDefaultImages() { 135 void ChangePictureHandler::SendDefaultImages() {
132 base::ListValue image_urls; 136 base::ListValue image_urls;
133 for (int i = default_user_image::kFirstDefaultImageIndex; 137 for (int i = default_user_image::kFirstDefaultImageIndex;
134 i < default_user_image::kDefaultImagesCount; ++i) { 138 i < default_user_image::kDefaultImagesCount; ++i) {
135 std::unique_ptr<base::DictionaryValue> image_data( 139 std::unique_ptr<base::DictionaryValue> image_data(
136 new base::DictionaryValue); 140 new base::DictionaryValue);
137 image_data->SetString("url", default_user_image::GetDefaultImageUrl(i)); 141 image_data->SetString("url", default_user_image::GetDefaultImageUrl(i));
138 image_data->SetString("author", 142 image_data->SetString("author",
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 201
198 ImageDecoder::Cancel(this); 202 ImageDecoder::Cancel(this);
199 ImageDecoder::Start(this, raw_data); 203 ImageDecoder::Start(this, raw_data);
200 } 204 }
201 205
202 void ChangePictureHandler::HandlePageInitialized(const base::ListValue* args) { 206 void ChangePictureHandler::HandlePageInitialized(const base::ListValue* args) {
203 DCHECK(args && args->empty()); 207 DCHECK(args && args->empty());
204 208
205 AllowJavascript(); 209 AllowJavascript();
206 210
207 CameraPresenceNotifier* camera = CameraPresenceNotifier::GetInstance();
208 if (!camera_observer_.IsObserving(camera))
209 camera_observer_.Add(camera);
210
211 SendDefaultImages(); 211 SendDefaultImages();
212 SendSelectedImage(); 212 SendSelectedImage();
213 UpdateProfileImage(); 213 UpdateProfileImage();
214 } 214 }
215 215
216 void ChangePictureHandler::SendSelectedImage() { 216 void ChangePictureHandler::SendSelectedImage() {
217 const user_manager::User* user = GetUser(); 217 const user_manager::User* user = GetUser();
218 DCHECK(user->GetAccountId().is_valid()); 218 DCHECK(user->GetAccountId().is_valid());
219 219
220 previous_image_index_ = user->image_index(); 220 previous_image_index_ = user->image_index();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 Profile* profile = Profile::FromWebUI(web_ui()); 414 Profile* profile = Profile::FromWebUI(web_ui());
415 const user_manager::User* user = 415 const user_manager::User* user =
416 ProfileHelper::Get()->GetUserByProfile(profile); 416 ProfileHelper::Get()->GetUserByProfile(profile);
417 if (!user) 417 if (!user)
418 return user_manager::UserManager::Get()->GetActiveUser(); 418 return user_manager::UserManager::Get()->GetActiveUser();
419 return user; 419 return user;
420 } 420 }
421 421
422 } // namespace settings 422 } // namespace settings
423 } // namespace chromeos 423 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698