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

Unified Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 9404011: Explicitly wait for user policy before completing login. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/login_utils.cc
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index 458304b399b32018ee04464cb1b1147b874c5335..b2d83e85cebdf64b6f3bbe72b5558fa1a1fb1f39 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/file_path.h"
@@ -542,7 +543,9 @@ class LoginUtilsImpl : public LoginUtils,
using_oauth_(false),
has_cookies_(false),
delegate_(NULL),
- job_restart_request_(NULL) {
+ job_restart_request_(NULL),
+ user_policy_ready_(false),
+ profile_pending_creation_(NULL) {
net::NetworkChangeNotifier::AddOnlineStateObserver(this);
}
@@ -648,6 +651,13 @@ class LoginUtilsImpl : public LoginUtils,
void OnProfileCreated(Profile* profile,
Profile::CreateStatus status);
+ // Callback for asynchronous notification that user policy is ready.
+ void OnUserPolicyReady();
+
+ // Invoked to resume profile creation after the profile is created and user
+ // policy has been loaded.
+ void ResumeProfileCreation(Profile* user_profile);
+
std::string password_;
GaiaAuthConsumer::ClientLoginResult credentials_;
bool pending_requests_;
@@ -665,6 +675,12 @@ class LoginUtilsImpl : public LoginUtils,
// Used to restart Chrome to switch to the guest mode.
JobRestartRequest* job_restart_request_;
+ // Profile creation should only resume once user policy is ready. Since both
+ // profile creation and user policy readiness notifications come
Mattias Nissler (ping if slow) 2012/02/16 10:24:11 s/come/are reported/
+ // asynchronously, these fields are used to track whether both are done.
+ bool user_policy_ready_;
+ Profile* profile_pending_creation_;
+
DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl);
};
@@ -751,7 +767,12 @@ void LoginUtilsImpl::PrepareProfile(
// Initialize user policy before the profile is created so the profile
// initialization code sees the cached policy settings.
- connector->InitializeUserPolicy(username, wait_for_policy_fetch);
+ user_policy_ready_ = false;
+ profile_pending_creation_ = NULL;
+ connector->InitializeUserPolicy(
Nikita (slow) 2012/02/20 16:10:24 What's the cost (and what happens behind the scene
Joao da Silva 2012/02/20 16:23:15 The cost is always the same. A couple of objects a
+ username,
+ wait_for_policy_fetch,
+ base::Bind(&LoginUtilsImpl::OnUserPolicyReady, AsWeakPtr()));
if (wait_for_policy_fetch) {
// Profile creation will block until user policy is fetched, which
@@ -773,12 +794,24 @@ void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) {
delegate_ = NULL;
}
+void LoginUtilsImpl::OnUserPolicyReady() {
+ user_policy_ready_ = true;
+ if (profile_pending_creation_) {
+ ResumeProfileCreation(profile_pending_creation_);
+ profile_pending_creation_ = NULL;
+ }
+}
+
void LoginUtilsImpl::OnProfileCreated(
Profile* user_profile,
Profile::CreateStatus status) {
CHECK(user_profile);
switch (status) {
case Profile::CREATE_STATUS_INITIALIZED:
+ if (user_policy_ready_)
+ ResumeProfileCreation(user_profile);
+ else
+ profile_pending_creation_ = user_profile;
break;
case Profile::CREATE_STATUS_CREATED: {
if (UserManager::Get()->current_user_is_new())
@@ -798,14 +831,16 @@ void LoginUtilsImpl::OnProfileCreated(
if (use_shared_proxies_pref->IsDefaultValue())
user_profile->GetPrefs()->SetBoolean(prefs::kUseSharedProxies, false);
RespectLocalePreference(user_profile);
- return;
+ break;
}
case Profile::CREATE_STATUS_FAIL:
default:
NOTREACHED();
- return;
+ break;
}
+}
+void LoginUtilsImpl::ResumeProfileCreation(Profile* user_profile) {
BootTimesLoader* btl = BootTimesLoader::Get();
btl->AddLoginTimeMarker("UserProfileGotten", false);

Powered by Google App Engine
This is Rietveld 408576698