Chromium Code Reviews| 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 982d86f3792e4600c35c0423e268145e376a18fa..beff54328de571c32cb51ffcaea5d9d0b8d83e81 100644 |
| --- a/chrome/browser/policy/device_token_fetcher.cc |
| +++ b/chrome/browser/policy/device_token_fetcher.cc |
| @@ -23,18 +23,23 @@ namespace em = enterprise_management; |
| DeviceTokenFetcher::DeviceTokenFetcher( |
| DeviceManagementBackend* backend, |
| + TokenService* token_service, |
| const FilePath& token_path) |
| : token_path_(token_path), |
| backend_(backend), |
| + token_service_(token_service), |
| state_(kStateNotStarted), |
| device_token_load_complete_event_(true, false) { |
| 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 |
| - // device management token gets fetched after the AuthTokens are available. |
| - registrar_.Add(this, |
| - NotificationType::TOKEN_AVAILABLE, |
| - NotificationService::AllSources()); |
| + |
| + auth_token_ = token_service_->GetTokenForService( |
| + GaiaConstants::kDeviceManagementService); |
| + |
| + if (!HasAuthToken()) { |
|
Nico
2010/11/18 14:34:24
You check in |Observe|, so this isn't really neces
Mattias Nissler (ping if slow)
2010/11/18 15:08:16
Removed. Done.
|
| + registrar_.Add(this, |
| + NotificationType::TOKEN_AVAILABLE, |
| + Source<TokenService>(token_service_)); |
| + } |
| } |
| void DeviceTokenFetcher::Observe(NotificationType type, |
| @@ -42,13 +47,14 @@ 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) { |
| - if (!HasAuthToken()) { |
| - auth_token_ = token_details->token(); |
| - SendServerRequestIfPossible(); |
| + if (Source<TokenService>(source).ptr() == token_service_) { |
| + const TokenService::TokenAvailableDetails* token_details = |
| + Details<const TokenService::TokenAvailableDetails>(details).ptr(); |
| + if (token_details->service() == GaiaConstants::kDeviceManagementService) { |
| + if (!HasAuthToken()) { |
| + auth_token_ = token_details->token(); |
| + SendServerRequestIfPossible(); |
| + } |
| } |
| } |
| } else { |
| @@ -102,6 +108,11 @@ void DeviceTokenFetcher::StartFetching() { |
| } |
| } |
| +void DeviceTokenFetcher::Shutdown() { |
| + token_service_ = NULL; |
| + backend_ = NULL; |
| +} |
| + |
| void DeviceTokenFetcher::AttemptTokenLoadFromDisk() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| if (file_util::PathExists(token_path_)) { |
| @@ -139,7 +150,8 @@ void DeviceTokenFetcher::MakeReadyToRequestDeviceToken() { |
| void DeviceTokenFetcher::SendServerRequestIfPossible() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (state_ == kStateReadyToRequestDeviceTokenFromServer |
| - && HasAuthToken()) { |
| + && HasAuthToken() |
| + && backend_) { |
| em::DeviceRegisterRequest register_request; |
| SetState(kStateRequestingDeviceTokenFromServer); |
| backend_->ProcessRegisterRequest(auth_token_, |