Index: chrome/browser/policy/device_token_fetcher.cc |
diff --git a/chrome/browser/policy/device_token_fetcher.cc b/chrome/browser/policy/device_token_fetcher.cc |
index c2c7464107ba4a979e9e04d3cea14039d7172ab2..206b95478a44fa4a59d1884b9cfdd40d717c94e1 100644 |
--- a/chrome/browser/policy/device_token_fetcher.cc |
+++ b/chrome/browser/policy/device_token_fetcher.cc |
@@ -7,18 +7,40 @@ |
#include "base/file_util.h" |
#include "base/path_service.h" |
#include "base/singleton.h" |
+#include "base/string_util.h" |
+#include "chrome/browser/chromeos/login/user_manager.h" |
#include "chrome/browser/net/gaia/token_service.h" |
+#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/profile.h" |
#include "chrome/common/chrome_paths.h" |
#include "chrome/common/net/gaia/gaia_constants.h" |
#include "chrome/common/notification_details.h" |
#include "chrome/common/notification_service.h" |
#include "chrome/common/notification_source.h" |
#include "chrome/common/notification_type.h" |
+#include "chrome/common/pref_names.h" |
+ |
+#if defined(OS_CHROMEOS) |
+#include "chrome/browser/chromeos/login/user_manager.h" |
+#else |
+#include "chrome/browser/sync/signin_manager.h" |
+#endif |
+ |
+class PrefService; |
namespace { |
static const char kPlaceholderDeviceID[] = "placeholder_device_id"; |
+int kNumNonDasherDomains = 2; |
Mattias Nissler (ping if slow)
2010/11/16 09:54:31
You can move this down and use arraysize(kNonDashe
gfeher
2010/11/16 17:37:01
Done.
|
+ |
+// Domain names that are known not to support Dasher. |
+// We don't register the device when such a user logs in. |
+const char* kNonDasherDomains[] = { |
+ "@googlemail.com", |
+ "@gmail.com" |
+}; |
+ |
} // namespace |
namespace policy { |
@@ -29,7 +51,8 @@ DeviceTokenFetcher::DeviceTokenFetcher( |
: token_path_(token_path), |
backend_(backend), |
state_(kStateNotStarted), |
- device_token_load_complete_event_(true, false) { |
+ device_token_load_complete_event_(true, false), |
+ profile_(NULL) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
// The token fetcher gets initialized AuthTokens for the device management |
// server are available. Install a notification observer to ensure that the |
@@ -37,6 +60,17 @@ DeviceTokenFetcher::DeviceTokenFetcher( |
registrar_.Add(this, |
NotificationType::TOKEN_AVAILABLE, |
NotificationService::AllSources()); |
+ // 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, |
+ NotificationService::AllSources()); |
+ #endif |
} |
void DeviceTokenFetcher::Observe(NotificationType type, |
@@ -44,7 +78,6 @@ void DeviceTokenFetcher::Observe(NotificationType type, |
const NotificationDetails& details) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
if (type == NotificationType::TOKEN_AVAILABLE) { |
- const Source<TokenService> token_service(source); |
const TokenService::TokenAvailableDetails* token_details = |
Details<const TokenService::TokenAvailableDetails>(details).ptr(); |
if (token_details->service() == GaiaConstants::kDeviceManagementService) { |
@@ -53,11 +86,49 @@ void DeviceTokenFetcher::Observe(NotificationType type, |
SendServerRequestIfPossible(); |
} |
} |
+ #if defined(OS_CHROMEOS) |
+ } else if (type == NotificationType::LOGIN_USER_CHANGED) { |
+ SendServerRequestIfPossible(); |
+ #else |
+ } else if (type == NotificationType::GOOGLE_SIGNIN_SUCCESSFUL) { |
+ profile_ = Source<Profile>(source).ptr(); |
+ SendServerRequestIfPossible(); |
+ #endif |
} else { |
NOTREACHED(); |
} |
} |
+std::string DeviceTokenFetcher::GetCurrentUser() { |
+ if (injected_username.get() == NULL) { |
Mattias Nissler (ping if slow)
2010/11/16 09:54:31
Is the inject_username quirk really necessary? I s
gfeher
2010/11/16 17:37:01
Done.
|
+#if defined(OS_CHROMEOS) |
+ return chromeos::UserManager::Get()->logged_in_user().email(); |
+#else |
+ if (profile_ == NULL) { |
+ return ""; |
+ } |
+ return profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); |
+#endif |
+ } else { |
+ return *(injected_username.get()); |
+ } |
+} |
+ |
+bool DeviceTokenFetcher::CanCurrentUserBeDasher() { |
+ std::string username = GetCurrentUser(); |
+ if (username.empty()) { |
+ // This means incognito user in case of ChromiumOS and |
+ // no logged-in user in case of Chromium (SigninService). |
+ return false; |
+ } |
+ for (int i = 0; i < kNumNonDasherDomains; i++) { |
+ if (EndsWith(username, kNonDasherDomains[i], true)) { |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
void DeviceTokenFetcher::HandleRegisterResponse( |
const em::DeviceRegisterResponse& response) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -129,7 +200,7 @@ void DeviceTokenFetcher::MakeReadyToRequestDeviceToken() { |
void DeviceTokenFetcher::SendServerRequestIfPossible() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
if (state_ == kStateReadyToRequestDeviceTokenFromServer |
- && HasAuthToken()) { |
+ && HasAuthToken() && CanCurrentUserBeDasher()) { |
em::DeviceRegisterRequest register_request; |
SetState(kStateRequestingDeviceTokenFromServer); |
backend_->ProcessRegisterRequest(auth_token_, |