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

Unified Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 34523003: settings: Make DeviceOAuth2TokenServiceFactory::Get() async (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 7 years, 2 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
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
};
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698