Commit 200729f8 authored by pam@chromium.org's avatar pam@chromium.org

Collect the custodian's full name when a supervised user is created.

Collect the custodian's GAIA account display name using the
ProfileDownloader and save it in the supervised user's prefs
so it can be shown in that profile's UI.

BUG=249691
TEST=manual

Review URL: https://chromiumcodereview.appspot.com/16950018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208013 0039d316-1c4b-4281-b951-d872f2087c98
parent c9cfcbb1
...@@ -74,7 +74,8 @@ ManagedUserRegistrationService::ManagedUserRegistrationService( ...@@ -74,7 +74,8 @@ ManagedUserRegistrationService::ManagedUserRegistrationService(
: weak_ptr_factory_(this), : weak_ptr_factory_(this),
prefs_(prefs), prefs_(prefs),
token_fetcher_(token_fetcher.Pass()), token_fetcher_(token_fetcher.Pass()),
pending_managed_user_acknowledged_(false) { pending_managed_user_acknowledged_(false),
download_profile_(NULL) {
pref_change_registrar_.Init(prefs); pref_change_registrar_.Init(prefs);
pref_change_registrar_.Add( pref_change_registrar_.Add(
prefs::kGoogleServicesLastUsername, prefs::kGoogleServicesLastUsername,
...@@ -143,6 +144,18 @@ void ManagedUserRegistrationService::Register( ...@@ -143,6 +144,18 @@ void ManagedUserRegistrationService::Register(
weak_ptr_factory_.GetWeakPtr(), info.name)); weak_ptr_factory_.GetWeakPtr(), info.name));
} }
void ManagedUserRegistrationService::DownloadProfile(
Profile* profile,
const DownloadProfileCallback& callback) {
download_callback_ = callback;
download_profile_ = profile;
// If another profile download is in progress, drop it. It's not worth
// queueing them up, and more likely that the one that hasn't ended yet is
// failing somehow than that the new one won't succeed.
profile_downloader_.reset(new ProfileDownloader(this));
profile_downloader_->Start();
}
void ManagedUserRegistrationService::CancelPendingRegistration() { void ManagedUserRegistrationService::CancelPendingRegistration() {
AbortPendingRegistration( AbortPendingRegistration(
false, // Don't run the callback. The error will be ignored. false, // Don't run the callback. The error will be ignored.
...@@ -399,3 +412,39 @@ void ManagedUserRegistrationService::CompleteRegistration( ...@@ -399,3 +412,39 @@ void ManagedUserRegistrationService::CompleteRegistration(
pending_managed_user_id_.clear(); pending_managed_user_id_.clear();
pending_managed_user_acknowledged_ = false; pending_managed_user_acknowledged_ = false;
} }
bool ManagedUserRegistrationService::NeedsProfilePicture() const {
return false;
}
int ManagedUserRegistrationService::GetDesiredImageSideLength() const {
return 0;
}
std::string ManagedUserRegistrationService::GetCachedPictureURL() const {
return std::string();
}
Profile* ManagedUserRegistrationService::GetBrowserProfile() {
DCHECK(download_profile_);
return download_profile_;
}
void ManagedUserRegistrationService::OnProfileDownloadComplete() {
download_callback_.Reset();
download_profile_ = NULL;
profile_downloader_.reset();
}
void ManagedUserRegistrationService::OnProfileDownloadSuccess(
ProfileDownloader* downloader) {
download_callback_.Run(downloader->GetProfileFullName());
OnProfileDownloadComplete();
}
void ManagedUserRegistrationService::OnProfileDownloadFailure(
ProfileDownloader* downloader,
ProfileDownloaderDelegate::FailureReason reason) {
// Ignore failures; proceed without the custodian's name.
OnProfileDownloadComplete();
}
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "base/prefs/pref_change_registrar.h" #include "base/prefs/pref_change_registrar.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/timer.h" #include "base/timer.h"
#include "chrome/browser/profiles/profile_downloader.h"
#include "chrome/browser/profiles/profile_downloader_delegate.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
#include "sync/api/syncable_service.h" #include "sync/api/syncable_service.h"
...@@ -40,7 +42,8 @@ struct ManagedUserRegistrationInfo { ...@@ -40,7 +42,8 @@ struct ManagedUserRegistrationInfo {
// management server and associating it with its custodian. It is owned by the // management server and associating it with its custodian. It is owned by the
// custodian's profile. // custodian's profile.
class ManagedUserRegistrationService : public BrowserContextKeyedService, class ManagedUserRegistrationService : public BrowserContextKeyedService,
public syncer::SyncableService { public syncer::SyncableService,
public ProfileDownloaderDelegate {
public: public:
// Callback for Register() below. If registration is successful, |token| will // Callback for Register() below. If registration is successful, |token| will
// contain an OAuth2 refresh token for the newly registered managed user, // contain an OAuth2 refresh token for the newly registered managed user,
...@@ -50,11 +53,26 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService, ...@@ -50,11 +53,26 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
const std::string& /* token */)> const std::string& /* token */)>
RegistrationCallback; RegistrationCallback;
// Callback for DownloadProfile() below. If the GAIA profile download is
// successful, the profile's full (display) name will be returned.
typedef base::Callback<void(const string16& /* full name */)>
DownloadProfileCallback;
ManagedUserRegistrationService( ManagedUserRegistrationService(
PrefService* prefs, PrefService* prefs,
scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher); scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher);
virtual ~ManagedUserRegistrationService(); virtual ~ManagedUserRegistrationService();
// ProfileDownloaderDelegate:
virtual bool NeedsProfilePicture() const OVERRIDE;
virtual int GetDesiredImageSideLength() const OVERRIDE;
virtual std::string GetCachedPictureURL() const OVERRIDE;
virtual Profile* GetBrowserProfile() OVERRIDE;
virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) OVERRIDE;
virtual void OnProfileDownloadFailure(
ProfileDownloader* downloader,
ProfileDownloaderDelegate::FailureReason reason) OVERRIDE;
static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
// Registers a new managed user with the server. |info| contains necessary // Registers a new managed user with the server. |info| contains necessary
...@@ -65,6 +83,14 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService, ...@@ -65,6 +83,14 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
void Register(const ManagedUserRegistrationInfo& info, void Register(const ManagedUserRegistrationInfo& info,
const RegistrationCallback& callback); const RegistrationCallback& callback);
// Downloads the GAIA account information for the |profile|. This is a best-
// effort attempt with no error reporting nor timeout. If the download is
// successful, the profile's full (display) name will be returned via the
// callback. If the download fails or never completes, the callback will
// not be called.
void DownloadProfile(Profile* profile,
const DownloadProfileCallback& callback);
// Cancels any registration currently in progress, without calling the // Cancels any registration currently in progress, without calling the
// callback or reporting an error. This should be called when the user // callback or reporting an error. This should be called when the user
// actively cancels the registration by canceling profile creation. // actively cancels the registration by canceling profile creation.
...@@ -114,6 +140,8 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService, ...@@ -114,6 +140,8 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
void CompleteRegistration(bool run_callback, void CompleteRegistration(bool run_callback,
const GoogleServiceAuthError& error); const GoogleServiceAuthError& error);
void OnProfileDownloadComplete();
base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_; base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_;
PrefService* prefs_; PrefService* prefs_;
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
...@@ -130,6 +158,10 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService, ...@@ -130,6 +158,10 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
bool pending_managed_user_acknowledged_; bool pending_managed_user_acknowledged_;
RegistrationCallback callback_; RegistrationCallback callback_;
Profile* download_profile_;
scoped_ptr<ProfileDownloader> profile_downloader_;
DownloadProfileCallback download_callback_;
DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService); DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService);
}; };
......
...@@ -545,6 +545,8 @@ void ManagedUserService::Init() { ...@@ -545,6 +545,8 @@ void ManagedUserService::Init() {
void ManagedUserService::RegisterAndInitSync( void ManagedUserService::RegisterAndInitSync(
Profile* custodian_profile, Profile* custodian_profile,
const ProfileManager::CreateCallback& callback) { const ProfileManager::CreateCallback& callback) {
// Register the managed user with the custodian's account.
ManagedUserRegistrationService* registration_service = ManagedUserRegistrationService* registration_service =
ManagedUserRegistrationServiceFactory::GetForProfile(custodian_profile); ManagedUserRegistrationServiceFactory::GetForProfile(custodian_profile);
string16 name = UTF8ToUTF16( string16 name = UTF8ToUTF16(
...@@ -554,6 +556,19 @@ void ManagedUserService::RegisterAndInitSync( ...@@ -554,6 +556,19 @@ void ManagedUserService::RegisterAndInitSync(
info, info,
base::Bind(&ManagedUserService::OnManagedUserRegistered, base::Bind(&ManagedUserService::OnManagedUserRegistered,
weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile));
// Fetch the custodian's profile information, to store the name.
// TODO(pamg): If --gaia-profile-info (keyword: switches::kGaiaProfileInfo)
// is ever enabled, take the name from the ProfileInfoCache instead.
registration_service->DownloadProfile(custodian_profile,
base::Bind(&ManagedUserService::OnCustodianProfileDownloaded,
weak_ptr_factory_.GetWeakPtr()));
}
void ManagedUserService::OnCustodianProfileDownloaded(
const string16& full_name) {
profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianName,
UTF16ToUTF8(full_name));
} }
void ManagedUserService::OnManagedUserRegistered( void ManagedUserService::OnManagedUserRegistered(
......
...@@ -188,6 +188,8 @@ class ManagedUserService : public BrowserContextKeyedService, ...@@ -188,6 +188,8 @@ class ManagedUserService : public BrowserContextKeyedService,
DISALLOW_COPY_AND_ASSIGN(URLFilterContext); DISALLOW_COPY_AND_ASSIGN(URLFilterContext);
}; };
void OnCustodianProfileDownloaded(const string16& full_name);
void OnManagedUserRegistered(const ProfileManager::CreateCallback& callback, void OnManagedUserRegistered(const ProfileManager::CreateCallback& callback,
Profile* custodian_profile, Profile* custodian_profile,
const GoogleServiceAuthError& auth_error, const GoogleServiceAuthError& auth_error,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment