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

Unified Diff: chrome/browser/policy/user_policy_identity_strategy.cc

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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/policy/user_policy_identity_strategy.cc
diff --git a/chrome/browser/policy/user_policy_identity_strategy.cc b/chrome/browser/policy/user_policy_identity_strategy.cc
index ae04c1414fafd9d0438780df1e7abc2eafc1e06b..3f8a998be1ecbf1a2e19932117594f8a64a70b4f 100644
--- a/chrome/browser/policy/user_policy_identity_strategy.cc
+++ b/chrome/browser/policy/user_policy_identity_strategy.cc
@@ -10,7 +10,6 @@
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
#include "chrome/browser/policy/proto/device_management_constants.h"
#include "chrome/browser/policy/proto/device_management_local.pb.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/common/guid.h"
#include "chrome/common/net/gaia/gaia_constants.h"
#include "content/browser/browser_thread.h"
@@ -18,9 +17,6 @@
#include "content/common/notification_service.h"
#include "content/common/notification_source.h"
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/login/user_manager.h"
-#endif
namespace policy {
@@ -37,6 +33,9 @@ class UserPolicyIdentityStrategy::TokenCache
void Load();
void Store(const std::string& token, const std::string& device_id);
+ bool load_initiated();
+ bool load_finished();
Mattias Nissler (ping if slow) 2011/05/26 10:20:20 what do you need these for?
sfeuz 2011/05/31 07:32:31 Currently there is the following potential race co
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 I see and agree we should handle that condition gr
sfeuz 2011/06/03 08:30:35 Done.
+
private:
friend class base::RefCountedThreadSafe<
UserPolicyIdentityStrategy::TokenCache>;
@@ -49,6 +48,8 @@ class UserPolicyIdentityStrategy::TokenCache
const base::WeakPtr<UserPolicyIdentityStrategy> identity_strategy_;
const FilePath cache_file_;
+ bool load_finished_;
+ bool load_initiated_;
DISALLOW_COPY_AND_ASSIGN(TokenCache);
};
@@ -57,10 +58,14 @@ UserPolicyIdentityStrategy::TokenCache::TokenCache(
const base::WeakPtr<UserPolicyIdentityStrategy>& identity_strategy,
const FilePath& cache_file)
: identity_strategy_(identity_strategy),
- cache_file_(cache_file) {}
+ cache_file_(cache_file),
+ load_finished_(false),
+ load_initiated_(false) {}
void UserPolicyIdentityStrategy::TokenCache::Load() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!load_initiated());
+ load_initiated_ = true;
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
@@ -108,6 +113,8 @@ void UserPolicyIdentityStrategy::TokenCache::NotifyOnUIThread(
const std::string& token,
const std::string& device_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!load_finished());
+ load_finished_ = true;
if (identity_strategy_.get())
identity_strategy_->OnCacheLoaded(token, device_id);
}
@@ -136,27 +143,20 @@ void UserPolicyIdentityStrategy::TokenCache::StoreOnFileThread(
file_util::WriteFile(cache_file_, data.c_str(), data.length());
}
+bool UserPolicyIdentityStrategy::TokenCache::load_initiated() {
+ return load_initiated_;
+}
+
+bool UserPolicyIdentityStrategy::TokenCache::load_finished() {
+ return load_finished_;
+}
+
UserPolicyIdentityStrategy::UserPolicyIdentityStrategy(
- Profile* profile,
+ const std::string& user_name,
const FilePath& cache_file)
- : profile_(profile),
+ : user_name_(user_name),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
cache_ = new TokenCache(weak_ptr_factory_.GetWeakPtr(), cache_file);
- registrar_.Add(this,
- NotificationType::TOKEN_AVAILABLE,
- Source<TokenService>(profile->GetTokenService()));
-
- // Register for the event of user login. The device management token won't
- // be fetched until we know the domain of the currently logged in user.
-#if defined(OS_CHROMEOS)
- registrar_.Add(this,
- NotificationType::LOGIN_USER_CHANGED,
- NotificationService::AllSources());
-#else
- registrar_.Add(this,
- NotificationType::GOOGLE_SIGNIN_SUCCESSFUL,
- Source<Profile>(profile_));
-#endif
}
UserPolicyIdentityStrategy::~UserPolicyIdentityStrategy() {}
@@ -192,9 +192,8 @@ std::string UserPolicyIdentityStrategy::GetPolicyType() {
bool UserPolicyIdentityStrategy::GetCredentials(std::string* username,
std::string* auth_token) {
- *username = GetCurrentUser();
- *auth_token = profile_->GetTokenService()->GetTokenForService(
- GaiaConstants::kDeviceManagementService);
+ *username = user_name_;
+ *auth_token = auth_token_;
return !username->empty() && !auth_token->empty() && !device_id_.empty();
}
@@ -207,20 +206,8 @@ void UserPolicyIdentityStrategy::OnDeviceTokenAvailable(
NotifyDeviceTokenChanged();
}
-std::string UserPolicyIdentityStrategy::GetCurrentUser() {
-#if defined(OS_CHROMEOS)
- // TODO(mnissler) On CrOS it seems impossible to figure out what user belongs
- // to a profile. Revisit after multi-profile support landed.
- return chromeos::UserManager::Get()->logged_in_user().email();
-#else
- return profile_->GetBrowserSignin()->GetSignedInUsername();
-#endif
-}
-
void UserPolicyIdentityStrategy::CheckAndTriggerFetch() {
- if (!GetCurrentUser().empty() &&
- profile_->GetTokenService()->HasTokenForService(
- GaiaConstants::kDeviceManagementService)) {
+ if (!user_name_.empty() && !auth_token_.empty() && cache_->load_finished()) {
// For user tokens, there is no actual identifier. We generate a random
// identifier instead each time we ask for the token.
device_id_ = guid::GenerateGUID();
@@ -228,6 +215,11 @@ void UserPolicyIdentityStrategy::CheckAndTriggerFetch() {
}
}
+void UserPolicyIdentityStrategy::SetAuthToken(const std::string& auth_token) {
+ auth_token_ = auth_token;
+ CheckAndTriggerFetch();
+}
+
void UserPolicyIdentityStrategy::OnCacheLoaded(const std::string& token,
const std::string& device_id) {
if (!token.empty() && !device_id.empty()) {
@@ -239,32 +231,5 @@ void UserPolicyIdentityStrategy::OnCacheLoaded(const std::string& token,
}
}
-void UserPolicyIdentityStrategy::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (type == NotificationType::TOKEN_AVAILABLE) {
- if (Source<TokenService>(source).ptr() == profile_->GetTokenService()) {
- const TokenService::TokenAvailableDetails* token_details =
- Details<const TokenService::TokenAvailableDetails>(details).ptr();
- if (token_details->service() == GaiaConstants::kDeviceManagementService)
- if (device_token_.empty()) {
- // Request a new device management server token, but only in case we
- // don't already have it.
- CheckAndTriggerFetch();
- }
- }
-#if defined(OS_CHROMEOS)
- } else if (type == NotificationType::LOGIN_USER_CHANGED) {
- CheckAndTriggerFetch();
-#else
- } else if (type == NotificationType::GOOGLE_SIGNIN_SUCCESSFUL) {
- if (profile_ == Source<Profile>(source).ptr())
- CheckAndTriggerFetch();
-#endif
- } else {
- NOTREACHED();
- }
-}
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698