summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-22 07:05:55 +0000
committerpam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-22 07:05:55 +0000
commit200729f8427980b23db088f854ad825dc8011b5c (patch)
tree2848a9c42d9c89be0815d4285826ff1a579fe498
parentc9cfcbb1c372d8a71418a0edbd2978b128d1805d (diff)
downloadchromium_src-200729f8427980b23db088f854ad825dc8011b5c.zip
chromium_src-200729f8427980b23db088f854ad825dc8011b5c.tar.gz
chromium_src-200729f8427980b23db088f854ad825dc8011b5c.tar.bz2
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
-rw-r--r--chrome/browser/managed_mode/managed_user_registration_service.cc51
-rw-r--r--chrome/browser/managed_mode/managed_user_registration_service.h34
-rw-r--r--chrome/browser/managed_mode/managed_user_service.cc15
-rw-r--r--chrome/browser/managed_mode/managed_user_service.h2
4 files changed, 100 insertions, 2 deletions
diff --git a/chrome/browser/managed_mode/managed_user_registration_service.cc b/chrome/browser/managed_mode/managed_user_registration_service.cc
index 25c5954..ae0da0e 100644
--- a/chrome/browser/managed_mode/managed_user_registration_service.cc
+++ b/chrome/browser/managed_mode/managed_user_registration_service.cc
@@ -74,7 +74,8 @@ ManagedUserRegistrationService::ManagedUserRegistrationService(
: weak_ptr_factory_(this),
prefs_(prefs),
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_.Add(
prefs::kGoogleServicesLastUsername,
@@ -143,6 +144,18 @@ void ManagedUserRegistrationService::Register(
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() {
AbortPendingRegistration(
false, // Don't run the callback. The error will be ignored.
@@ -399,3 +412,39 @@ void ManagedUserRegistrationService::CompleteRegistration(
pending_managed_user_id_.clear();
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();
+}
diff --git a/chrome/browser/managed_mode/managed_user_registration_service.h b/chrome/browser/managed_mode/managed_user_registration_service.h
index c2938f4..bc78a6c 100644
--- a/chrome/browser/managed_mode/managed_user_registration_service.h
+++ b/chrome/browser/managed_mode/managed_user_registration_service.h
@@ -13,6 +13,8 @@
#include "base/prefs/pref_change_registrar.h"
#include "base/strings/string16.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 "components/browser_context_keyed_service/browser_context_keyed_service.h"
#include "sync/api/syncable_service.h"
@@ -40,7 +42,8 @@ struct ManagedUserRegistrationInfo {
// management server and associating it with its custodian. It is owned by the
// custodian's profile.
class ManagedUserRegistrationService : public BrowserContextKeyedService,
- public syncer::SyncableService {
+ public syncer::SyncableService,
+ public ProfileDownloaderDelegate {
public:
// Callback for Register() below. If registration is successful, |token| will
// contain an OAuth2 refresh token for the newly registered managed user,
@@ -50,11 +53,26 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
const std::string& /* token */)>
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(
PrefService* prefs,
scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher);
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);
// Registers a new managed user with the server. |info| contains necessary
@@ -65,6 +83,14 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
void Register(const ManagedUserRegistrationInfo& info,
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
// callback or reporting an error. This should be called when the user
// actively cancels the registration by canceling profile creation.
@@ -114,6 +140,8 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
void CompleteRegistration(bool run_callback,
const GoogleServiceAuthError& error);
+ void OnProfileDownloadComplete();
+
base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_;
PrefService* prefs_;
PrefChangeRegistrar pref_change_registrar_;
@@ -130,6 +158,10 @@ class ManagedUserRegistrationService : public BrowserContextKeyedService,
bool pending_managed_user_acknowledged_;
RegistrationCallback callback_;
+ Profile* download_profile_;
+ scoped_ptr<ProfileDownloader> profile_downloader_;
+ DownloadProfileCallback download_callback_;
+
DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService);
};
diff --git a/chrome/browser/managed_mode/managed_user_service.cc b/chrome/browser/managed_mode/managed_user_service.cc
index 9509063..1460a16 100644
--- a/chrome/browser/managed_mode/managed_user_service.cc
+++ b/chrome/browser/managed_mode/managed_user_service.cc
@@ -545,6 +545,8 @@ void ManagedUserService::Init() {
void ManagedUserService::RegisterAndInitSync(
Profile* custodian_profile,
const ProfileManager::CreateCallback& callback) {
+
+ // Register the managed user with the custodian's account.
ManagedUserRegistrationService* registration_service =
ManagedUserRegistrationServiceFactory::GetForProfile(custodian_profile);
string16 name = UTF8ToUTF16(
@@ -554,6 +556,19 @@ void ManagedUserService::RegisterAndInitSync(
info,
base::Bind(&ManagedUserService::OnManagedUserRegistered,
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(
diff --git a/chrome/browser/managed_mode/managed_user_service.h b/chrome/browser/managed_mode/managed_user_service.h
index 7d9dbeb..22528b0 100644
--- a/chrome/browser/managed_mode/managed_user_service.h
+++ b/chrome/browser/managed_mode/managed_user_service.h
@@ -188,6 +188,8 @@ class ManagedUserService : public BrowserContextKeyedService,
DISALLOW_COPY_AND_ASSIGN(URLFilterContext);
};
+ void OnCustodianProfileDownloaded(const string16& full_name);
+
void OnManagedUserRegistered(const ProfileManager::CreateCallback& callback,
Profile* custodian_profile,
const GoogleServiceAuthError& auth_error,