Index: chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
index 962e93b6c22268f7fbad69e4d51a769535f05cc6..45509d696ce225df084c681ab58e137af4a3d826 100644 |
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc |
@@ -373,7 +373,8 @@ class PrintPreviewHandler::AccessTokenService |
: public OAuth2TokenService::Consumer { |
public: |
explicit AccessTokenService(PrintPreviewHandler* handler) |
- : handler_(handler) { |
+ : handler_(handler), |
+ weak_factory_(this) { |
} |
void RequestToken(const std::string& type) { |
@@ -392,13 +393,35 @@ class PrintPreviewHandler::AccessTokenService |
} |
} else if (type == "device") { |
#if defined(OS_CHROMEOS) |
- chromeos::DeviceOAuth2TokenService* token_service = |
- chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
- account_id = token_service->GetRobotAccountId(); |
- service = token_service; |
+ chromeos::DeviceOAuth2TokenServiceFactory::Get( |
+ base::Bind( |
+ &AccessTokenService::DidGetTokenService, |
+ weak_factory_.GetWeakPtr(), |
+ type)); |
+ return; |
#endif |
} |
+ ContinueRequestToken(type, service, account_id); |
+ } |
+ |
+#if defined(OS_CHROMEOS) |
+ // Continuation of RequestToken(). |
+ void DidGetTokenService(const std::string& type, |
+ chromeos::DeviceOAuth2TokenService* token_service) { |
+ std::string account_id; |
+ if (token_service) |
+ account_id = token_service->GetRobotAccountId(); |
+ ContinueRequestToken(type, |
+ token_service, |
+ account_id); |
+ } |
+#endif |
+ |
+ // Continuation of RequestToken(). |
+ void ContinueRequestToken(const std::string& type, |
+ OAuth2TokenService* service, |
+ const std::string& account_id) { |
if (service) { |
OAuth2TokenService::ScopeSet oauth_scopes; |
oauth_scopes.insert(cloud_print::kCloudPrintAuth); |
@@ -438,6 +461,7 @@ class PrintPreviewHandler::AccessTokenService |
linked_ptr<OAuth2TokenService::Request> > Requests; |
Requests requests_; |
PrintPreviewHandler* handler_; |
+ base::WeakPtrFactory<AccessTokenService> weak_factory_; |
DISALLOW_COPY_AND_ASSIGN(AccessTokenService); |
}; |