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

Side by Side Diff: extensions/shell/browser/api/identity/identity_api.cc

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address final comments Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « extensions/shell/app_shell.gypi ('k') | extensions/shell/browser/shell_oauth2_token_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/shell/browser/api/identity/identity_api.h" 5 #include "extensions/shell/browser/api/identity/identity_api.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 OAuth2MintTokenFlow* flow) { 58 OAuth2MintTokenFlow* flow) {
59 mint_token_flow_.reset(flow); 59 mint_token_flow_.reset(flow);
60 } 60 }
61 61
62 ExtensionFunction::ResponseAction IdentityGetAuthTokenFunction::Run() { 62 ExtensionFunction::ResponseAction IdentityGetAuthTokenFunction::Run() {
63 scoped_ptr<api::identity::GetAuthToken::Params> params( 63 scoped_ptr<api::identity::GetAuthToken::Params> params(
64 api::identity::GetAuthToken::Params::Create(*args_)); 64 api::identity::GetAuthToken::Params::Create(*args_));
65 EXTENSION_FUNCTION_VALIDATE(params.get()); 65 EXTENSION_FUNCTION_VALIDATE(params.get());
66 66
67 ShellOAuth2TokenService* service = ShellOAuth2TokenService::GetInstance(); 67 ShellOAuth2TokenService* service = ShellOAuth2TokenService::GetInstance();
68 std::string account_id = service->account_id(); 68 std::string account_id = service->AccountId();
69 if (account_id.empty()) 69 if (account_id.empty())
70 return RespondNow(Error(kErrorNoUserAccount)); 70 return RespondNow(Error(kErrorNoUserAccount));
71 71
72 if (!service->RefreshTokenIsAvailable(account_id)) 72 if (!service->RefreshTokenIsAvailable(account_id))
73 return RespondNow(Error(kErrorNoRefreshToken)); 73 return RespondNow(Error(kErrorNoRefreshToken));
74 74
75 // Verify that we have scopes. 75 // Verify that we have scopes.
76 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension()); 76 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension());
77 if (oauth2_info.scopes.empty()) 77 if (oauth2_info.scopes.empty())
78 return RespondNow(Error(kErrorNoScopesInManifest)); 78 return RespondNow(Error(kErrorNoScopesInManifest));
79 79
80 // Balanced in OnGetTokenFailure() and in the OAuth2MintTokenFlow callbacks. 80 // Balanced in OnGetTokenFailure() and in the OAuth2MintTokenFlow callbacks.
81 AddRef(); 81 AddRef();
82 82
83 // First, fetch a logged-in-user access token for the Chrome project client ID 83 // First, fetch a logged-in-user access token for the Chrome project client ID
84 // and client secret. This token is used later to get a second access token 84 // and client secret. This token is used later to get a second access token
85 // that will be returned to the app. 85 // that will be returned to the app.
86 std::set<std::string> no_scopes; 86 std::set<std::string> no_scopes;
87 access_token_request_ = 87 access_token_request_ =
88 service->StartRequest(service->account_id(), no_scopes, this); 88 service->StartRequest(service->AccountId(), no_scopes, this);
89 return RespondLater(); 89 return RespondLater();
90 } 90 }
91 91
92 void IdentityGetAuthTokenFunction::OnGetTokenSuccess( 92 void IdentityGetAuthTokenFunction::OnGetTokenSuccess(
93 const OAuth2TokenService::Request* request, 93 const OAuth2TokenService::Request* request,
94 const std::string& access_token, 94 const std::string& access_token,
95 const base::Time& expiration_time) { 95 const base::Time& expiration_time) {
96 // Tests may override the mint token flow. 96 // Tests may override the mint token flow.
97 if (!mint_token_flow_) { 97 if (!mint_token_flow_) {
98 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension()); 98 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 scoped_ptr<api::identity::RemoveCachedAuthToken::Params> params( 151 scoped_ptr<api::identity::RemoveCachedAuthToken::Params> params(
152 api::identity::RemoveCachedAuthToken::Params::Create(*args_)); 152 api::identity::RemoveCachedAuthToken::Params::Create(*args_));
153 EXTENSION_FUNCTION_VALIDATE(params.get()); 153 EXTENSION_FUNCTION_VALIDATE(params.get());
154 // This stub identity API does not maintain a token cache, so there is nothing 154 // This stub identity API does not maintain a token cache, so there is nothing
155 // to remove. 155 // to remove.
156 return RespondNow(NoArguments()); 156 return RespondNow(NoArguments());
157 } 157 }
158 158
159 } // namespace shell 159 } // namespace shell
160 } // namespace extensions 160 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/shell/app_shell.gypi ('k') | extensions/shell/browser/shell_oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698