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

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

Issue 12929014: Identity API: Pop-up a sign-in dialog if gaia credentials are bad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 7 years, 9 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 | « chrome/browser/extensions/api/identity/identity_api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/identity/identity_api.h" 5 #include "chrome/browser/extensions/api/identity/identity_api.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_function_dispatcher.h" 9 #include "chrome/browser/extensions/extension_function_dispatcher.h"
10 #include "chrome/browser/extensions/extension_install_prompt.h" 10 #include "chrome/browser/extensions/extension_install_prompt.h"
(...skipping 27 matching lines...) Expand all
38 const char kUserRejected[] = "The user did not approve access."; 38 const char kUserRejected[] = "The user did not approve access.";
39 const char kUserNotSignedIn[] = "The user is not signed in."; 39 const char kUserNotSignedIn[] = "The user is not signed in.";
40 const char kInvalidRedirect[] = "Did not redirect to the right URL."; 40 const char kInvalidRedirect[] = "Did not redirect to the right URL.";
41 } // namespace identity_constants 41 } // namespace identity_constants
42 42
43 namespace GetAuthToken = api::experimental_identity::GetAuthToken; 43 namespace GetAuthToken = api::experimental_identity::GetAuthToken;
44 namespace LaunchWebAuthFlow = api::experimental_identity::LaunchWebAuthFlow; 44 namespace LaunchWebAuthFlow = api::experimental_identity::LaunchWebAuthFlow;
45 namespace identity = api::experimental_identity; 45 namespace identity = api::experimental_identity;
46 46
47 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() 47 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction()
48 : interactive_(false) {} 48 : interactive_(false),
49 should_retry_with_signin_(false) {}
49 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() {} 50 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() {}
50 51
51 bool IdentityGetAuthTokenFunction::RunImpl() { 52 bool IdentityGetAuthTokenFunction::RunImpl() {
52 scoped_ptr<GetAuthToken::Params> params(GetAuthToken::Params::Create(*args_)); 53 scoped_ptr<GetAuthToken::Params> params(GetAuthToken::Params::Create(*args_));
53 EXTENSION_FUNCTION_VALIDATE(params.get()); 54 EXTENSION_FUNCTION_VALIDATE(params.get());
54 if (params->details.get() && params->details->interactive.get()) 55 if (params->details.get() && params->details->interactive.get())
55 interactive_ = *params->details->interactive; 56 interactive_ = *params->details->interactive;
57 should_retry_with_signin_ = interactive_;
56 58
57 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(GetExtension()); 59 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(GetExtension());
58 60
59 // Check that the necessary information is present in the manfist. 61 // Check that the necessary information is present in the manfist.
60 if (oauth2_info.client_id.empty()) { 62 if (oauth2_info.client_id.empty()) {
61 error_ = identity_constants::kInvalidClientId; 63 error_ = identity_constants::kInvalidClientId;
62 return false; 64 return false;
63 } 65 }
64 66
65 if (oauth2_info.scopes.size() == 0) { 67 if (oauth2_info.scopes.size() == 0) {
(...skipping 24 matching lines...) Expand all
90 92
91 void IdentityGetAuthTokenFunction::OnMintTokenSuccess( 93 void IdentityGetAuthTokenFunction::OnMintTokenSuccess(
92 const std::string& access_token) { 94 const std::string& access_token) {
93 SetResult(Value::CreateStringValue(access_token)); 95 SetResult(Value::CreateStringValue(access_token));
94 SendResponse(true); 96 SendResponse(true);
95 Release(); // Balanced in RunImpl. 97 Release(); // Balanced in RunImpl.
96 } 98 }
97 99
98 void IdentityGetAuthTokenFunction::OnMintTokenFailure( 100 void IdentityGetAuthTokenFunction::OnMintTokenFailure(
99 const GoogleServiceAuthError& error) { 101 const GoogleServiceAuthError& error) {
102 if (should_retry_with_signin_) {
103 switch (error.state()) {
104 case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS:
105 case GoogleServiceAuthError::ACCOUNT_DELETED:
106 case GoogleServiceAuthError::ACCOUNT_DISABLED:
107 ShowLoginPopup();
108 return;
109 default:
110 // Return error to caller.
111 break;
112 }
113 }
114
Pete Williamson 2013/03/22 16:42:34 How will the user know *why* they are being asked
Michael Courage 2013/03/25 21:28:04 There is nothing on the sign in screen that explai
100 error_ = std::string(identity_constants::kAuthFailure) + error.ToString(); 115 error_ = std::string(identity_constants::kAuthFailure) + error.ToString();
101 SendResponse(false); 116 SendResponse(false);
102 Release(); // Balanced in RunImpl. 117 Release(); // Balanced in RunImpl.
103 } 118 }
104 119
105 void IdentityGetAuthTokenFunction::OnIssueAdviceSuccess( 120 void IdentityGetAuthTokenFunction::OnIssueAdviceSuccess(
106 const IssueAdviceInfo& issue_advice) { 121 const IssueAdviceInfo& issue_advice) {
107 // Existing grant was revoked and we used NO_FORCE, so we got info back 122 // Existing grant was revoked and we used NO_FORCE, so we got info back
108 // instead. 123 // instead.
109 if (interactive_) { 124 if (interactive_) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 login_ui_service->AddObserver(this); 181 login_ui_service->AddObserver(this);
167 } 182 }
168 183
169 void IdentityGetAuthTokenFunction::StopObservingLoginService() { 184 void IdentityGetAuthTokenFunction::StopObservingLoginService() {
170 LoginUIService* login_ui_service = 185 LoginUIService* login_ui_service =
171 LoginUIServiceFactory::GetForProfile(profile()); 186 LoginUIServiceFactory::GetForProfile(profile());
172 login_ui_service->RemoveObserver(this); 187 login_ui_service->RemoveObserver(this);
173 } 188 }
174 189
175 void IdentityGetAuthTokenFunction::ShowLoginPopup() { 190 void IdentityGetAuthTokenFunction::ShowLoginPopup() {
191 should_retry_with_signin_ = false;
176 StartObservingLoginService(); 192 StartObservingLoginService();
177 193
178 LoginUIService* login_ui_service = 194 LoginUIService* login_ui_service =
179 LoginUIServiceFactory::GetForProfile(profile()); 195 LoginUIServiceFactory::GetForProfile(profile());
180 login_ui_service->ShowLoginPopup(); 196 login_ui_service->ShowLoginPopup();
181 } 197 }
182 198
183 void IdentityGetAuthTokenFunction::ShowOAuthApprovalDialog( 199 void IdentityGetAuthTokenFunction::ShowOAuthApprovalDialog(
184 const IssueAdviceInfo& issue_advice) { 200 const IssueAdviceInfo& issue_advice) {
185 install_ui_->ConfirmIssueAdvice(this, GetExtension(), issue_advice); 201 install_ui_->ConfirmIssueAdvice(this, GetExtension(), issue_advice);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 281
266 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> > 282 static base::LazyInstance<ProfileKeyedAPIFactory<IdentityAPI> >
267 g_factory = LAZY_INSTANCE_INITIALIZER; 283 g_factory = LAZY_INSTANCE_INITIALIZER;
268 284
269 // static 285 // static
270 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() { 286 ProfileKeyedAPIFactory<IdentityAPI>* IdentityAPI::GetFactoryInstance() {
271 return &g_factory.Get(); 287 return &g_factory.Get();
272 } 288 }
273 289
274 } // namespace extensions 290 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698