| 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/supervised_user/custodian_profile_downloader_service.h" | 5 #include "chrome/browser/supervised_user/custodian_profile_downloader_service.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" |
| 9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "components/signin/core/browser/signin_manager.h" |
| 10 #include "google_apis/gaia/gaia_auth_util.h" | 12 #include "google_apis/gaia/gaia_auth_util.h" |
| 11 | 13 |
| 12 CustodianProfileDownloaderService::CustodianProfileDownloaderService( | 14 CustodianProfileDownloaderService::CustodianProfileDownloaderService( |
| 13 Profile* custodian_profile) | 15 Profile* custodian_profile) |
| 14 : custodian_profile_(custodian_profile) { | 16 : custodian_profile_(custodian_profile) { |
| 15 } | 17 } |
| 16 | 18 |
| 17 CustodianProfileDownloaderService::~CustodianProfileDownloaderService() {} | 19 CustodianProfileDownloaderService::~CustodianProfileDownloaderService() {} |
| 18 | 20 |
| 19 void CustodianProfileDownloaderService::Shutdown() { | 21 void CustodianProfileDownloaderService::Shutdown() { |
| 20 profile_downloader_.reset(); | 22 profile_downloader_.reset(); |
| 21 } | 23 } |
| 22 | 24 |
| 23 void CustodianProfileDownloaderService::DownloadProfile( | 25 void CustodianProfileDownloaderService::DownloadProfile( |
| 24 const DownloadProfileCallback& callback) { | 26 const DownloadProfileCallback& callback) { |
| 25 // The user must be logged in. | 27 // The user must be logged in. |
| 26 std::string username = custodian_profile_->GetPrefs()->GetString( | 28 if (!SigninManagerFactory::GetForProfile(custodian_profile_) |
| 27 prefs::kGoogleServicesUsername); | 29 ->IsAuthenticated()) { |
| 28 if (username.empty()) | |
| 29 return; | 30 return; |
| 31 } |
| 30 | 32 |
| 31 download_callback_ = callback; | 33 download_callback_ = callback; |
| 32 std::string current_email = custodian_profile_->GetProfileName(); | 34 std::string current_email = custodian_profile_->GetProfileName(); |
| 33 if (gaia::AreEmailsSame(last_downloaded_profile_email_, current_email)) { | 35 if (gaia::AreEmailsSame(last_downloaded_profile_email_, current_email)) { |
| 34 // Profile was previously downloaded successfully, use it as it is unlikely | 36 // Profile was previously downloaded successfully, use it as it is unlikely |
| 35 // that we will need to download it again. | 37 // that we will need to download it again. |
| 36 OnProfileDownloadSuccess(profile_downloader_.get()); | 38 OnProfileDownloadSuccess(profile_downloader_.get()); |
| 37 return; | 39 return; |
| 38 } | 40 } |
| 39 // If another profile download is in progress, drop it. It's not worth | 41 // If another profile download is in progress, drop it. It's not worth |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 last_downloaded_profile_email_ = in_progress_profile_email_; | 70 last_downloaded_profile_email_ = in_progress_profile_email_; |
| 69 } | 71 } |
| 70 | 72 |
| 71 void CustodianProfileDownloaderService::OnProfileDownloadFailure( | 73 void CustodianProfileDownloaderService::OnProfileDownloadFailure( |
| 72 ProfileDownloader* downloader, | 74 ProfileDownloader* downloader, |
| 73 ProfileDownloaderDelegate::FailureReason reason) { | 75 ProfileDownloaderDelegate::FailureReason reason) { |
| 74 // Ignore failures; proceed without the custodian's name. | 76 // Ignore failures; proceed without the custodian's name. |
| 75 download_callback_.Reset(); | 77 download_callback_.Reset(); |
| 76 profile_downloader_.reset(); | 78 profile_downloader_.reset(); |
| 77 } | 79 } |
| OLD | NEW |