| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/avatar/user_image_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 16 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 17 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 18 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
| 19 #include "base/task_runner_util.h" | 21 #include "base/task_runner_util.h" |
| 20 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 21 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" | 24 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 24 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 case user_manager::User::USER_IMAGE_EXTERNAL: | 143 case user_manager::User::USER_IMAGE_EXTERNAL: |
| 142 // TODO(ivankr): Distinguish this from selected from file. | 144 // TODO(ivankr): Distinguish this from selected from file. |
| 143 return default_user_image::kHistogramImageFromCamera; | 145 return default_user_image::kHistogramImageFromCamera; |
| 144 case user_manager::User::USER_IMAGE_PROFILE: | 146 case user_manager::User::USER_IMAGE_PROFILE: |
| 145 return default_user_image::kHistogramImageFromProfile; | 147 return default_user_image::kHistogramImageFromProfile; |
| 146 default: | 148 default: |
| 147 return image_index; | 149 return image_index; |
| 148 } | 150 } |
| 149 } | 151 } |
| 150 | 152 |
| 151 bool SaveImage(scoped_ptr<user_manager::UserImage::Bytes> image_bytes, | 153 bool SaveImage(std::unique_ptr<user_manager::UserImage::Bytes> image_bytes, |
| 152 const base::FilePath& image_path) { | 154 const base::FilePath& image_path) { |
| 153 if (image_bytes->empty() || | 155 if (image_bytes->empty() || |
| 154 base::WriteFile(image_path, | 156 base::WriteFile(image_path, |
| 155 reinterpret_cast<const char*>(image_bytes->data()), | 157 reinterpret_cast<const char*>(image_bytes->data()), |
| 156 image_bytes->size()) == -1) { | 158 image_bytes->size()) == -1) { |
| 157 LOG(ERROR) << "Failed to save image to file."; | 159 LOG(ERROR) << "Failed to save image to file."; |
| 158 return false; | 160 return false; |
| 159 } | 161 } |
| 160 | 162 |
| 161 return true; | 163 return true; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 const GURL& image_url); | 197 const GURL& image_url); |
| 196 | 198 |
| 197 // Sets the user image in local state to the default image indicated | 199 // Sets the user image in local state to the default image indicated |
| 198 // by |default_image_index|. Also updates the user object with the | 200 // by |default_image_index|. Also updates the user object with the |
| 199 // new image. | 201 // new image. |
| 200 void SetToDefaultImage(int default_image_index); | 202 void SetToDefaultImage(int default_image_index); |
| 201 | 203 |
| 202 // Saves the |user_image| to disk and sets the user image in local | 204 // Saves the |user_image| to disk and sets the user image in local |
| 203 // state to that image. Also updates the user with the new image. | 205 // state to that image. Also updates the user with the new image. |
| 204 void SetToImage(int image_index, | 206 void SetToImage(int image_index, |
| 205 scoped_ptr<user_manager::UserImage> user_image); | 207 std::unique_ptr<user_manager::UserImage> user_image); |
| 206 | 208 |
| 207 // Decodes the JPEG image |data|, crops and resizes the image, saves | 209 // Decodes the JPEG image |data|, crops and resizes the image, saves |
| 208 // it to disk and sets the user image in local state to that image. | 210 // it to disk and sets the user image in local state to that image. |
| 209 // Also updates the user object with the new image. | 211 // Also updates the user object with the new image. |
| 210 void SetToImageData(scoped_ptr<std::string> data); | 212 void SetToImageData(std::unique_ptr<std::string> data); |
| 211 | 213 |
| 212 // Loads the image at |path|, transcodes it to JPEG format, saves | 214 // Loads the image at |path|, transcodes it to JPEG format, saves |
| 213 // the image to disk and sets the user image in local state to that | 215 // the image to disk and sets the user image in local state to that |
| 214 // image. If |resize| is true, the image is cropped and resized | 216 // image. If |resize| is true, the image is cropped and resized |
| 215 // before transcoding. Also updates the user object with the new | 217 // before transcoding. Also updates the user object with the new |
| 216 // image. | 218 // image. |
| 217 void SetToPath(const base::FilePath& path, | 219 void SetToPath(const base::FilePath& path, |
| 218 int image_index, | 220 int image_index, |
| 219 const GURL& image_url, | 221 const GURL& image_url, |
| 220 bool resize); | 222 bool resize); |
| 221 | 223 |
| 222 private: | 224 private: |
| 223 // Called back after an image has been loaded from disk. | 225 // Called back after an image has been loaded from disk. |
| 224 void OnLoadImageDone(bool save, | 226 void OnLoadImageDone(bool save, |
| 225 scoped_ptr<user_manager::UserImage> user_image); | 227 std::unique_ptr<user_manager::UserImage> user_image); |
| 226 | 228 |
| 227 // Updates the user object with |user_image|. | 229 // Updates the user object with |user_image|. |
| 228 void UpdateUser(scoped_ptr<user_manager::UserImage> user_image); | 230 void UpdateUser(std::unique_ptr<user_manager::UserImage> user_image); |
| 229 | 231 |
| 230 // Updates the user object with |user_image|, and saves the image | 232 // Updates the user object with |user_image|, and saves the image |
| 231 // bytes. Local state will be updated as needed. | 233 // bytes. Local state will be updated as needed. |
| 232 void UpdateUserAndSaveImage(scoped_ptr<user_manager::UserImage> user_image); | 234 void UpdateUserAndSaveImage( |
| 235 std::unique_ptr<user_manager::UserImage> user_image); |
| 233 | 236 |
| 234 // Saves |image_bytes| to disk in JPEG format if | 237 // Saves |image_bytes| to disk in JPEG format if |
| 235 // |image_is_safe_format|. Local state will be updated as needed. | 238 // |image_is_safe_format|. Local state will be updated as needed. |
| 236 void SaveImageAndUpdateLocalState( | 239 void SaveImageAndUpdateLocalState( |
| 237 bool image_is_safe_format, | 240 bool image_is_safe_format, |
| 238 scoped_ptr<user_manager::UserImage::Bytes> image_bytes); | 241 std::unique_ptr<user_manager::UserImage::Bytes> image_bytes); |
| 239 | 242 |
| 240 // Called back after the user image has been saved to | 243 // Called back after the user image has been saved to |
| 241 // disk. Updates the user image information in local state. The | 244 // disk. Updates the user image information in local state. The |
| 242 // information is only updated if |success| is true (indicating that | 245 // information is only updated if |success| is true (indicating that |
| 243 // the image was saved successfully) or the user image is the | 246 // the image was saved successfully) or the user image is the |
| 244 // profile image (indicating that even if the image could not be | 247 // profile image (indicating that even if the image could not be |
| 245 // saved because it is not available right now, it will be | 248 // saved because it is not available right now, it will be |
| 246 // downloaded eventually). | 249 // downloaded eventually). |
| 247 void OnSaveImageDone(bool success); | 250 void OnSaveImageDone(bool success); |
| 248 | 251 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 DCHECK(!run_); | 288 DCHECK(!run_); |
| 286 run_ = true; | 289 run_ = true; |
| 287 | 290 |
| 288 image_index_ = image_index; | 291 image_index_ = image_index; |
| 289 image_url_ = image_url; | 292 image_url_ = image_url; |
| 290 image_path_ = image_path; | 293 image_path_ = image_path; |
| 291 | 294 |
| 292 if (image_index_ >= 0 && | 295 if (image_index_ >= 0 && |
| 293 image_index_ < default_user_image::kDefaultImagesCount) { | 296 image_index_ < default_user_image::kDefaultImagesCount) { |
| 294 // Load one of the default images. This happens synchronously. | 297 // Load one of the default images. This happens synchronously. |
| 295 scoped_ptr<user_manager::UserImage> user_image(new user_manager::UserImage( | 298 std::unique_ptr<user_manager::UserImage> user_image( |
| 296 default_user_image::GetDefaultImage(image_index_))); | 299 new user_manager::UserImage( |
| 300 default_user_image::GetDefaultImage(image_index_))); |
| 297 UpdateUser(std::move(user_image)); | 301 UpdateUser(std::move(user_image)); |
| 298 NotifyJobDone(); | 302 NotifyJobDone(); |
| 299 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || | 303 } else if (image_index_ == user_manager::User::USER_IMAGE_EXTERNAL || |
| 300 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { | 304 image_index_ == user_manager::User::USER_IMAGE_PROFILE) { |
| 301 // Load the user image from a file referenced by |image_path|. This happens | 305 // Load the user image from a file referenced by |image_path|. This happens |
| 302 // asynchronously. ROBUST_JPEG_CODEC can be used here because | 306 // asynchronously. ROBUST_JPEG_CODEC can be used here because |
| 303 // LoadImage() is called only for users whose user image has previously | 307 // LoadImage() is called only for users whose user image has previously |
| 304 // been set by one of the Set*() methods, which transcode to JPEG format. | 308 // been set by one of the Set*() methods, which transcode to JPEG format. |
| 305 DCHECK(!image_path_.empty()); | 309 DCHECK(!image_path_.empty()); |
| 306 user_image_loader::StartWithFilePath( | 310 user_image_loader::StartWithFilePath( |
| 307 parent_->background_task_runner_, image_path_, | 311 parent_->background_task_runner_, image_path_, |
| 308 ImageDecoder::ROBUST_JPEG_CODEC, | 312 ImageDecoder::ROBUST_JPEG_CODEC, |
| 309 0, // Do not crop. | 313 0, // Do not crop. |
| 310 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); | 314 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), false)); |
| 311 } else { | 315 } else { |
| 312 NOTREACHED(); | 316 NOTREACHED(); |
| 313 NotifyJobDone(); | 317 NotifyJobDone(); |
| 314 } | 318 } |
| 315 } | 319 } |
| 316 | 320 |
| 317 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { | 321 void UserImageManagerImpl::Job::SetToDefaultImage(int default_image_index) { |
| 318 DCHECK(!run_); | 322 DCHECK(!run_); |
| 319 run_ = true; | 323 run_ = true; |
| 320 | 324 |
| 321 DCHECK_LE(0, default_image_index); | 325 DCHECK_LE(0, default_image_index); |
| 322 DCHECK_GT(default_user_image::kDefaultImagesCount, default_image_index); | 326 DCHECK_GT(default_user_image::kDefaultImagesCount, default_image_index); |
| 323 | 327 |
| 324 image_index_ = default_image_index; | 328 image_index_ = default_image_index; |
| 325 scoped_ptr<user_manager::UserImage> user_image(new user_manager::UserImage( | 329 std::unique_ptr<user_manager::UserImage> user_image( |
| 326 default_user_image::GetDefaultImage(image_index_))); | 330 new user_manager::UserImage( |
| 331 default_user_image::GetDefaultImage(image_index_))); |
| 327 | 332 |
| 328 UpdateUser(std::move(user_image)); | 333 UpdateUser(std::move(user_image)); |
| 329 UpdateLocalState(); | 334 UpdateLocalState(); |
| 330 NotifyJobDone(); | 335 NotifyJobDone(); |
| 331 } | 336 } |
| 332 | 337 |
| 333 void UserImageManagerImpl::Job::SetToImage( | 338 void UserImageManagerImpl::Job::SetToImage( |
| 334 int image_index, | 339 int image_index, |
| 335 scoped_ptr<user_manager::UserImage> user_image) { | 340 std::unique_ptr<user_manager::UserImage> user_image) { |
| 336 DCHECK(!run_); | 341 DCHECK(!run_); |
| 337 run_ = true; | 342 run_ = true; |
| 338 | 343 |
| 339 DCHECK(image_index == user_manager::User::USER_IMAGE_EXTERNAL || | 344 DCHECK(image_index == user_manager::User::USER_IMAGE_EXTERNAL || |
| 340 image_index == user_manager::User::USER_IMAGE_PROFILE); | 345 image_index == user_manager::User::USER_IMAGE_PROFILE); |
| 341 | 346 |
| 342 image_index_ = image_index; | 347 image_index_ = image_index; |
| 343 | 348 |
| 344 UpdateUserAndSaveImage(std::move(user_image)); | 349 UpdateUserAndSaveImage(std::move(user_image)); |
| 345 } | 350 } |
| 346 | 351 |
| 347 void UserImageManagerImpl::Job::SetToImageData(scoped_ptr<std::string> data) { | 352 void UserImageManagerImpl::Job::SetToImageData( |
| 353 std::unique_ptr<std::string> data) { |
| 348 DCHECK(!run_); | 354 DCHECK(!run_); |
| 349 run_ = true; | 355 run_ = true; |
| 350 | 356 |
| 351 image_index_ = user_manager::User::USER_IMAGE_EXTERNAL; | 357 image_index_ = user_manager::User::USER_IMAGE_EXTERNAL; |
| 352 | 358 |
| 353 // This method uses ROBUST_JPEG_CODEC, not DEFAULT_CODEC: | 359 // This method uses ROBUST_JPEG_CODEC, not DEFAULT_CODEC: |
| 354 // * This is necessary because the method is used to update the user image | 360 // * This is necessary because the method is used to update the user image |
| 355 // whenever the policy for a user is set. In the case of device-local | 361 // whenever the policy for a user is set. In the case of device-local |
| 356 // accounts, policy may change at any time, even if the user is not | 362 // accounts, policy may change at any time, even if the user is not |
| 357 // currently logged in (and thus, DEFAULT_CODEC may not be used). | 363 // currently logged in (and thus, DEFAULT_CODEC may not be used). |
| (...skipping 20 matching lines...) Expand all Loading... |
| 378 | 384 |
| 379 DCHECK(!path.empty()); | 385 DCHECK(!path.empty()); |
| 380 user_image_loader::StartWithFilePath( | 386 user_image_loader::StartWithFilePath( |
| 381 parent_->background_task_runner_, path, ImageDecoder::DEFAULT_CODEC, | 387 parent_->background_task_runner_, path, ImageDecoder::DEFAULT_CODEC, |
| 382 resize ? login::kMaxUserImageSize : 0, | 388 resize ? login::kMaxUserImageSize : 0, |
| 383 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), true)); | 389 base::Bind(&Job::OnLoadImageDone, weak_factory_.GetWeakPtr(), true)); |
| 384 } | 390 } |
| 385 | 391 |
| 386 void UserImageManagerImpl::Job::OnLoadImageDone( | 392 void UserImageManagerImpl::Job::OnLoadImageDone( |
| 387 bool save, | 393 bool save, |
| 388 scoped_ptr<user_manager::UserImage> user_image) { | 394 std::unique_ptr<user_manager::UserImage> user_image) { |
| 389 if (save) { | 395 if (save) { |
| 390 UpdateUserAndSaveImage(std::move(user_image)); | 396 UpdateUserAndSaveImage(std::move(user_image)); |
| 391 } else { | 397 } else { |
| 392 UpdateUser(std::move(user_image)); | 398 UpdateUser(std::move(user_image)); |
| 393 NotifyJobDone(); | 399 NotifyJobDone(); |
| 394 } | 400 } |
| 395 } | 401 } |
| 396 | 402 |
| 397 void UserImageManagerImpl::Job::UpdateUser( | 403 void UserImageManagerImpl::Job::UpdateUser( |
| 398 scoped_ptr<user_manager::UserImage> user_image) { | 404 std::unique_ptr<user_manager::UserImage> user_image) { |
| 399 user_manager::User* user = parent_->GetUserAndModify(); | 405 user_manager::User* user = parent_->GetUserAndModify(); |
| 400 if (!user) | 406 if (!user) |
| 401 return; | 407 return; |
| 402 | 408 |
| 403 if (!user_image->image().isNull()) { | 409 if (!user_image->image().isNull()) { |
| 404 user->SetImage(std::move(user_image), image_index_); | 410 user->SetImage(std::move(user_image), image_index_); |
| 405 } else { | 411 } else { |
| 406 user->SetStubImage( | 412 user->SetStubImage( |
| 407 make_scoped_ptr(new user_manager::UserImage( | 413 base::WrapUnique(new user_manager::UserImage( |
| 408 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 414 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 409 IDR_PROFILE_PICTURE_LOADING))), | 415 IDR_PROFILE_PICTURE_LOADING))), |
| 410 image_index_, false); | 416 image_index_, false); |
| 411 } | 417 } |
| 412 user->SetImageURL(image_url_); | 418 user->SetImageURL(image_url_); |
| 413 | 419 |
| 414 parent_->OnJobChangedUserImage(); | 420 parent_->OnJobChangedUserImage(); |
| 415 } | 421 } |
| 416 | 422 |
| 417 void UserImageManagerImpl::Job::UpdateUserAndSaveImage( | 423 void UserImageManagerImpl::Job::UpdateUserAndSaveImage( |
| 418 scoped_ptr<user_manager::UserImage> user_image) { | 424 std::unique_ptr<user_manager::UserImage> user_image) { |
| 419 // TODO(crbug.com/593251): Remove the data copy. | 425 // TODO(crbug.com/593251): Remove the data copy. |
| 420 // Copy the image bytes, before the user image is passed to | 426 // Copy the image bytes, before the user image is passed to |
| 421 // UpdateUser(). This is needed to safely save the data bytes to the disk | 427 // UpdateUser(). This is needed to safely save the data bytes to the disk |
| 422 // in the blocking pool. Copying is not desirable but the user image is | 428 // in the blocking pool. Copying is not desirable but the user image is |
| 423 // JPEG data of 512x512 pixels (usually <100KB) hence it's not enormous. | 429 // JPEG data of 512x512 pixels (usually <100KB) hence it's not enormous. |
| 424 const bool image_is_safe_format = user_image->is_safe_format(); | 430 const bool image_is_safe_format = user_image->is_safe_format(); |
| 425 scoped_ptr<user_manager::UserImage::Bytes> copied_bytes; | 431 std::unique_ptr<user_manager::UserImage::Bytes> copied_bytes; |
| 426 if (image_is_safe_format) { | 432 if (image_is_safe_format) { |
| 427 copied_bytes.reset( | 433 copied_bytes.reset( |
| 428 new user_manager::UserImage::Bytes(user_image->image_bytes())); | 434 new user_manager::UserImage::Bytes(user_image->image_bytes())); |
| 429 } | 435 } |
| 430 | 436 |
| 431 UpdateUser(std::move(user_image)); | 437 UpdateUser(std::move(user_image)); |
| 432 | 438 |
| 433 SaveImageAndUpdateLocalState(image_is_safe_format, std::move(copied_bytes)); | 439 SaveImageAndUpdateLocalState(image_is_safe_format, std::move(copied_bytes)); |
| 434 } | 440 } |
| 435 | 441 |
| 436 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( | 442 void UserImageManagerImpl::Job::SaveImageAndUpdateLocalState( |
| 437 bool image_is_safe_format, | 443 bool image_is_safe_format, |
| 438 scoped_ptr<user_manager::UserImage::Bytes> image_bytes) { | 444 std::unique_ptr<user_manager::UserImage::Bytes> image_bytes) { |
| 439 base::FilePath user_data_dir; | 445 base::FilePath user_data_dir; |
| 440 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 446 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 441 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); | 447 image_path_ = user_data_dir.Append(user_id() + kSafeImagePathExtension); |
| 442 | 448 |
| 443 // This should always be true, because of the following reasons: | 449 // This should always be true, because of the following reasons: |
| 444 // | 450 // |
| 445 // 1) Profile image from Google account -> UserImage is created with | 451 // 1) Profile image from Google account -> UserImage is created with |
| 446 // CreateAndEncode() that generates safe bytes representation. | 452 // CreateAndEncode() that generates safe bytes representation. |
| 447 // 2) Profile image from user-specified image -> The bytes representation | 453 // 2) Profile image from user-specified image -> The bytes representation |
| 448 // is regenerated after the original image is decoded and cropped. | 454 // is regenerated after the original image is decoded and cropped. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 469 NotifyJobDone(); | 475 NotifyJobDone(); |
| 470 } | 476 } |
| 471 | 477 |
| 472 void UserImageManagerImpl::Job::UpdateLocalState() { | 478 void UserImageManagerImpl::Job::UpdateLocalState() { |
| 473 // Ignore if data stored or cached outside the user's cryptohome is to be | 479 // Ignore if data stored or cached outside the user's cryptohome is to be |
| 474 // treated as ephemeral. | 480 // treated as ephemeral. |
| 475 if (parent_->user_manager_->IsUserNonCryptohomeDataEphemeral( | 481 if (parent_->user_manager_->IsUserNonCryptohomeDataEphemeral( |
| 476 AccountId::FromUserEmail(user_id()))) | 482 AccountId::FromUserEmail(user_id()))) |
| 477 return; | 483 return; |
| 478 | 484 |
| 479 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 485 std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| 480 entry->Set(kImagePathNodeName, new base::StringValue(image_path_.value())); | 486 entry->Set(kImagePathNodeName, new base::StringValue(image_path_.value())); |
| 481 entry->Set(kImageIndexNodeName, new base::FundamentalValue(image_index_)); | 487 entry->Set(kImageIndexNodeName, new base::FundamentalValue(image_index_)); |
| 482 if (!image_url_.is_empty()) | 488 if (!image_url_.is_empty()) |
| 483 entry->Set(kImageURLNodeName, new base::StringValue(image_url_.spec())); | 489 entry->Set(kImageURLNodeName, new base::StringValue(image_url_.spec())); |
| 484 DictionaryPrefUpdate update(g_browser_process->local_state(), | 490 DictionaryPrefUpdate update(g_browser_process->local_state(), |
| 485 kUserImageProperties); | 491 kUserImageProperties); |
| 486 update->SetWithoutPathExpansion(user_id(), entry.release()); | 492 update->SetWithoutPathExpansion(user_id(), entry.release()); |
| 487 | 493 |
| 488 parent_->user_manager_->NotifyLocalStateChanged(); | 494 parent_->user_manager_->NotifyLocalStateChanged(); |
| 489 } | 495 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 536 |
| 531 if (!image_properties) { | 537 if (!image_properties) { |
| 532 SetInitialUserImage(); | 538 SetInitialUserImage(); |
| 533 return; | 539 return; |
| 534 } | 540 } |
| 535 | 541 |
| 536 int image_index = user_manager::User::USER_IMAGE_INVALID; | 542 int image_index = user_manager::User::USER_IMAGE_INVALID; |
| 537 image_properties->GetInteger(kImageIndexNodeName, &image_index); | 543 image_properties->GetInteger(kImageIndexNodeName, &image_index); |
| 538 if (image_index >= 0 && | 544 if (image_index >= 0 && |
| 539 image_index < default_user_image::kDefaultImagesCount) { | 545 image_index < default_user_image::kDefaultImagesCount) { |
| 540 user->SetImage(make_scoped_ptr(new user_manager::UserImage( | 546 user->SetImage(base::WrapUnique(new user_manager::UserImage( |
| 541 default_user_image::GetDefaultImage(image_index))), | 547 default_user_image::GetDefaultImage(image_index))), |
| 542 image_index); | 548 image_index); |
| 543 return; | 549 return; |
| 544 } | 550 } |
| 545 | 551 |
| 546 if (image_index != user_manager::User::USER_IMAGE_EXTERNAL && | 552 if (image_index != user_manager::User::USER_IMAGE_EXTERNAL && |
| 547 image_index != user_manager::User::USER_IMAGE_PROFILE) { | 553 image_index != user_manager::User::USER_IMAGE_PROFILE) { |
| 548 NOTREACHED(); | 554 NOTREACHED(); |
| 549 return; | 555 return; |
| 550 } | 556 } |
| 551 | 557 |
| 552 std::string image_url_string; | 558 std::string image_url_string; |
| 553 image_properties->GetString(kImageURLNodeName, &image_url_string); | 559 image_properties->GetString(kImageURLNodeName, &image_url_string); |
| 554 GURL image_url(image_url_string); | 560 GURL image_url(image_url_string); |
| 555 std::string image_path; | 561 std::string image_path; |
| 556 image_properties->GetString(kImagePathNodeName, &image_path); | 562 image_properties->GetString(kImagePathNodeName, &image_path); |
| 557 | 563 |
| 558 user->SetImageURL(image_url); | 564 user->SetImageURL(image_url); |
| 559 user->SetStubImage(make_scoped_ptr(new user_manager::UserImage( | 565 user->SetStubImage(base::WrapUnique(new user_manager::UserImage( |
| 560 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 566 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 561 IDR_PROFILE_PICTURE_LOADING))), | 567 IDR_PROFILE_PICTURE_LOADING))), |
| 562 image_index, true); | 568 image_index, true); |
| 563 DCHECK(!image_path.empty() || | 569 DCHECK(!image_path.empty() || |
| 564 image_index == user_manager::User::USER_IMAGE_PROFILE); | 570 image_index == user_manager::User::USER_IMAGE_PROFILE); |
| 565 if (image_path.empty()) { | 571 if (image_path.empty()) { |
| 566 // Return if the profile image is to be used but has not been downloaded | 572 // Return if the profile image is to be used but has not been downloaded |
| 567 // yet. The profile image will be downloaded after login. | 573 // yet. The profile image will be downloaded after login. |
| 568 return; | 574 return; |
| 569 } | 575 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 } | 627 } |
| 622 | 628 |
| 623 void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) { | 629 void UserImageManagerImpl::SaveUserDefaultImageIndex(int default_image_index) { |
| 624 if (IsUserImageManaged()) | 630 if (IsUserImageManaged()) |
| 625 return; | 631 return; |
| 626 job_.reset(new Job(this)); | 632 job_.reset(new Job(this)); |
| 627 job_->SetToDefaultImage(default_image_index); | 633 job_->SetToDefaultImage(default_image_index); |
| 628 } | 634 } |
| 629 | 635 |
| 630 void UserImageManagerImpl::SaveUserImage( | 636 void UserImageManagerImpl::SaveUserImage( |
| 631 scoped_ptr<user_manager::UserImage> user_image) { | 637 std::unique_ptr<user_manager::UserImage> user_image) { |
| 632 if (IsUserImageManaged()) | 638 if (IsUserImageManaged()) |
| 633 return; | 639 return; |
| 634 job_.reset(new Job(this)); | 640 job_.reset(new Job(this)); |
| 635 job_->SetToImage(user_manager::User::USER_IMAGE_EXTERNAL, | 641 job_->SetToImage(user_manager::User::USER_IMAGE_EXTERNAL, |
| 636 std::move(user_image)); | 642 std::move(user_image)); |
| 637 } | 643 } |
| 638 | 644 |
| 639 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { | 645 void UserImageManagerImpl::SaveUserImageFromFile(const base::FilePath& path) { |
| 640 if (IsUserImageManaged()) | 646 if (IsUserImageManaged()) |
| 641 return; | 647 return; |
| 642 job_.reset(new Job(this)); | 648 job_.reset(new Job(this)); |
| 643 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); | 649 job_->SetToPath(path, user_manager::User::USER_IMAGE_EXTERNAL, GURL(), true); |
| 644 } | 650 } |
| 645 | 651 |
| 646 void UserImageManagerImpl::SaveUserImageFromProfileImage() { | 652 void UserImageManagerImpl::SaveUserImageFromProfileImage() { |
| 647 if (IsUserImageManaged()) | 653 if (IsUserImageManaged()) |
| 648 return; | 654 return; |
| 649 // Use the profile image if it has been downloaded already. Otherwise, use a | 655 // Use the profile image if it has been downloaded already. Otherwise, use a |
| 650 // stub image (gray avatar). | 656 // stub image (gray avatar). |
| 651 job_.reset(new Job(this)); | 657 job_.reset(new Job(this)); |
| 652 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, | 658 job_->SetToImage(user_manager::User::USER_IMAGE_PROFILE, |
| 653 downloaded_profile_image_.isNull() | 659 downloaded_profile_image_.isNull() |
| 654 ? make_scoped_ptr(new user_manager::UserImage) | 660 ? base::WrapUnique(new user_manager::UserImage) |
| 655 : user_manager::UserImage::CreateAndEncode( | 661 : user_manager::UserImage::CreateAndEncode( |
| 656 downloaded_profile_image_)); | 662 downloaded_profile_image_)); |
| 657 // If no profile image has been downloaded yet, ensure that a download is | 663 // If no profile image has been downloaded yet, ensure that a download is |
| 658 // started. | 664 // started. |
| 659 if (downloaded_profile_image_.isNull()) | 665 if (downloaded_profile_image_.isNull()) |
| 660 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); | 666 DownloadProfileData(kProfileDownloadReasonProfileImageChosen); |
| 661 } | 667 } |
| 662 | 668 |
| 663 void UserImageManagerImpl::DeleteUserImage() { | 669 void UserImageManagerImpl::DeleteUserImage() { |
| 664 job_.reset(); | 670 job_.reset(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 user_image_sync_observer_.reset(); | 704 user_image_sync_observer_.reset(); |
| 699 } | 705 } |
| 700 | 706 |
| 701 void UserImageManagerImpl::OnExternalDataCleared(const std::string& policy) { | 707 void UserImageManagerImpl::OnExternalDataCleared(const std::string& policy) { |
| 702 DCHECK_EQ(policy::key::kUserAvatarImage, policy); | 708 DCHECK_EQ(policy::key::kUserAvatarImage, policy); |
| 703 has_managed_image_ = false; | 709 has_managed_image_ = false; |
| 704 SetInitialUserImage(); | 710 SetInitialUserImage(); |
| 705 TryToCreateImageSyncObserver(); | 711 TryToCreateImageSyncObserver(); |
| 706 } | 712 } |
| 707 | 713 |
| 708 void UserImageManagerImpl::OnExternalDataFetched(const std::string& policy, | 714 void UserImageManagerImpl::OnExternalDataFetched( |
| 709 scoped_ptr<std::string> data) { | 715 const std::string& policy, |
| 716 std::unique_ptr<std::string> data) { |
| 710 DCHECK_EQ(policy::key::kUserAvatarImage, policy); | 717 DCHECK_EQ(policy::key::kUserAvatarImage, policy); |
| 711 DCHECK(IsUserImageManaged()); | 718 DCHECK(IsUserImageManaged()); |
| 712 if (data) { | 719 if (data) { |
| 713 job_.reset(new Job(this)); | 720 job_.reset(new Job(this)); |
| 714 job_->SetToImageData(std::move(data)); | 721 job_->SetToImageData(std::move(data)); |
| 715 } | 722 } |
| 716 } | 723 } |
| 717 | 724 |
| 718 // static | 725 // static |
| 719 void UserImageManagerImpl::IgnoreProfileDataDownloadDelayForTesting() { | 726 void UserImageManagerImpl::IgnoreProfileDataDownloadDelayForTesting() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 736 return profile_image_url_.spec(); | 743 return profile_image_url_.spec(); |
| 737 } | 744 } |
| 738 | 745 |
| 739 bool UserImageManagerImpl::IsPreSignin() const { | 746 bool UserImageManagerImpl::IsPreSignin() const { |
| 740 return false; | 747 return false; |
| 741 } | 748 } |
| 742 | 749 |
| 743 void UserImageManagerImpl::OnProfileDownloadSuccess( | 750 void UserImageManagerImpl::OnProfileDownloadSuccess( |
| 744 ProfileDownloader* downloader) { | 751 ProfileDownloader* downloader) { |
| 745 // Ensure that the |profile_downloader_| is deleted when this method returns. | 752 // Ensure that the |profile_downloader_| is deleted when this method returns. |
| 746 scoped_ptr<ProfileDownloader> profile_downloader( | 753 std::unique_ptr<ProfileDownloader> profile_downloader( |
| 747 profile_downloader_.release()); | 754 profile_downloader_.release()); |
| 748 DCHECK_EQ(downloader, profile_downloader.get()); | 755 DCHECK_EQ(downloader, profile_downloader.get()); |
| 749 | 756 |
| 750 user_manager_->UpdateUserAccountData( | 757 user_manager_->UpdateUserAccountData( |
| 751 AccountId::FromUserEmail(user_id()), | 758 AccountId::FromUserEmail(user_id()), |
| 752 user_manager::UserManager::UserAccountData( | 759 user_manager::UserManager::UserAccountData( |
| 753 downloader->GetProfileFullName(), downloader->GetProfileGivenName(), | 760 downloader->GetProfileFullName(), downloader->GetProfileGivenName(), |
| 754 downloader->GetProfileLocale())); | 761 downloader->GetProfileLocale())); |
| 755 if (!downloading_profile_image_) | 762 if (!downloading_profile_image_) |
| 756 return; | 763 return; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 } | 964 } |
| 958 | 965 |
| 959 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { | 966 bool UserImageManagerImpl::IsUserLoggedInAndHasGaiaAccount() const { |
| 960 const user_manager::User* user = GetUser(); | 967 const user_manager::User* user = GetUser(); |
| 961 if (!user) | 968 if (!user) |
| 962 return false; | 969 return false; |
| 963 return user->is_logged_in() && user->HasGaiaAccount(); | 970 return user->is_logged_in() && user->HasGaiaAccount(); |
| 964 } | 971 } |
| 965 | 972 |
| 966 } // namespace chromeos | 973 } // namespace chromeos |
| OLD | NEW |