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

Side by Side Diff: chrome/browser/chromeos/login/user_image_manager_impl.cc

Issue 13088002: Use only IJG decoding path to decode profile pictures on login screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months 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/chromeos/login/user_image_manager_browsertest.cc ('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) 2013 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/chromeos/login/user_image_manager_impl.h" 5 #include "chrome/browser/chromeos/login/user_image_manager_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // download will be scheduled for |kProfileDataDownloadDelayMs| 231 // download will be scheduled for |kProfileDataDownloadDelayMs|
232 // after user logs in). 232 // after user logs in).
233 DCHECK(!image_path.empty() || image_index == User::kProfileImageIndex); 233 DCHECK(!image_path.empty() || image_index == User::kProfileImageIndex);
234 std::string image_url; 234 std::string image_url;
235 image_properties->GetString(kImageURLNodeName, &image_url); 235 image_properties->GetString(kImageURLNodeName, &image_url);
236 GURL image_gurl(image_url); 236 GURL image_gurl(image_url);
237 // Until image has been loaded, use the stub image (gray avatar). 237 // Until image has been loaded, use the stub image (gray avatar).
238 user->SetStubImage(image_index, true); 238 user->SetStubImage(image_index, true);
239 user->SetImageURL(image_gurl); 239 user->SetImageURL(image_gurl);
240 if (!image_path.empty()) { 240 if (!image_path.empty()) {
241 // Load user image asynchronously. 241 if (needs_migration) {
242 UserImageLoader* loader = 242 // Non-JPG image will be migrated once user logs in.
243 safe_source ? image_loader_.get() : unsafe_image_loader_.get(); 243 // Stub image will be used for now.
244 loader->Start( 244 return;
245 }
246 DCHECK(safe_source);
247 if (!safe_source)
248 return;
249
250 // Load user image asynchronously - at this point we are able to use
251 // JPEG image loaded since image comes from safe pref source
252 // i.e. converted to JPEG.
253 image_loader_->Start(
245 image_path, 0 /* no resize */, 254 image_path, 0 /* no resize */,
246 base::Bind(&UserImageManagerImpl::SetUserImage, 255 base::Bind(&UserImageManagerImpl::SetUserImage,
247 base::Unretained(this), 256 base::Unretained(this),
248 user->email(), image_index, image_gurl)); 257 user->email(), image_index, image_gurl));
249 } 258 }
250 } else { 259 } else {
251 NOTREACHED(); 260 NOTREACHED();
252 } 261 }
253 } 262 }
254 } 263 }
255 } 264 }
256 265
257 void UserImageManagerImpl::UserLoggedIn(const std::string& email, 266 void UserImageManagerImpl::UserLoggedIn(const std::string& email,
258 bool user_is_new, 267 bool user_is_new,
259 bool user_is_local) { 268 bool user_is_local) {
260 if (user_is_new) { 269 if (user_is_new) {
261 SetInitialUserImage(email); 270 SetInitialUserImage(email);
262 } else { 271 } else {
263 int image_index = UserManager::Get()->GetLoggedInUser()->image_index(); 272 User* user = UserManager::Get()->GetLoggedInUser();
264 273
265 if (!user_is_local) { 274 if (!user_is_local) {
266 // If current user image is profile image, it needs to be refreshed. 275 // If current user image is profile image, it needs to be refreshed.
267 bool download_profile_image = image_index == User::kProfileImageIndex; 276 bool download_profile_image =
277 user->image_index() == User::kProfileImageIndex;
268 if (download_profile_image) 278 if (download_profile_image)
269 InitDownloadedProfileImage(); 279 InitDownloadedProfileImage();
270 280
271 // Download user's profile data (full name and optionally image) to see if 281 // Download user's profile data (full name and optionally image) to see if
272 // it has changed. 282 // it has changed.
273 BrowserThread::PostDelayedTask( 283 BrowserThread::PostDelayedTask(
274 BrowserThread::UI, 284 BrowserThread::UI,
275 FROM_HERE, 285 FROM_HERE,
276 base::Bind(&UserImageManagerImpl::DownloadProfileData, 286 base::Bind(&UserImageManagerImpl::DownloadProfileData,
277 base::Unretained(this), 287 base::Unretained(this),
278 kProfileDownloadReasonLoggedIn, 288 kProfileDownloadReasonLoggedIn,
279 download_profile_image), 289 download_profile_image),
280 base::TimeDelta::FromSeconds(kProfileDataDownloadDelaySec)); 290 base::TimeDelta::FromSeconds(kProfileDataDownloadDelaySec));
281 } 291 }
282 292
283 UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn", 293 UMA_HISTOGRAM_ENUMERATION("UserImage.LoggedIn",
284 ImageIndexToHistogramIndex(image_index), 294 ImageIndexToHistogramIndex(user->image_index()),
285 kHistogramImagesCount); 295 kHistogramImagesCount);
286 296
287 if (users_to_migrate_.count(email)) { 297 if (users_to_migrate_.count(email)) {
288 // User needs image format migration. 298 const DictionaryValue* prefs_images_unsafe =
289 BrowserThread::PostDelayedTask( 299 g_browser_process->local_state()->GetDictionary(kUserImages);
290 BrowserThread::UI, 300 const base::DictionaryValue* image_properties = NULL;
291 FROM_HERE, 301 if (prefs_images_unsafe->GetDictionaryWithoutPathExpansion(
292 base::Bind(&UserImageManagerImpl::MigrateUserImage, 302 user->email(), &image_properties)) {
293 base::Unretained(this)), 303 std::string image_path;
294 base::TimeDelta::FromSeconds(user_image_migration_delay_sec)); 304 image_properties->GetString(kImagePathNodeName, &image_path);
305 if (!image_path.empty()) {
306 // User needs image format migration but
307 // first we need to load and decode that image.
308 LOG(INFO) << "Waiting for user image to load before migration";
309 migrate_current_user_on_load_ = true;
310 unsafe_image_loader_->Start(
311 image_path, 0 /* no resize */,
312 base::Bind(&UserImageManagerImpl::SetUserImage,
313 base::Unretained(this),
314 user->email(),
315 user->image_index(),
316 user->image_url()));
317 } else {
318 // Otherwise migrate user image properties right away.
319 BrowserThread::PostDelayedTask(
320 BrowserThread::UI,
321 FROM_HERE,
322 base::Bind(&UserImageManagerImpl::MigrateUserImage,
323 base::Unretained(this)),
324 base::TimeDelta::FromSeconds(user_image_migration_delay_sec));
325 }
326 }
295 } 327 }
296 } 328 }
297 329
298 if (!user_is_local) { 330 if (!user_is_local) {
299 // Set up a repeating timer for refreshing the profile data. 331 // Set up a repeating timer for refreshing the profile data.
300 profile_download_timer_.Start( 332 profile_download_timer_.Start(
301 FROM_HERE, base::TimeDelta::FromSeconds(kProfileRefreshIntervalSec), 333 FROM_HERE, base::TimeDelta::FromSeconds(kProfileRefreshIntervalSec),
302 this, &UserImageManagerImpl::DownloadProfileDataScheduled); 334 this, &UserImageManagerImpl::DownloadProfileDataScheduled);
303 } 335 }
304 } 336 }
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 if (prefs_images_update->GetDictionaryWithoutPathExpansion( 773 if (prefs_images_update->GetDictionaryWithoutPathExpansion(
742 username, &image_properties)) { 774 username, &image_properties)) {
743 std::string image_path; 775 std::string image_path;
744 image_properties->GetString(kImagePathNodeName, &image_path); 776 image_properties->GetString(kImagePathNodeName, &image_path);
745 prefs_images_update->RemoveWithoutPathExpansion(username, NULL); 777 prefs_images_update->RemoveWithoutPathExpansion(username, NULL);
746 DeleteImageFile(image_path); 778 DeleteImageFile(image_path);
747 } 779 }
748 } 780 }
749 781
750 } // namespace chromeos 782 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_image_manager_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698