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

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

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: address code review comments Created 7 years, 8 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
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h"
12 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" 13 #include "chrome/browser/extensions/api/identity/web_auth_flow.h"
13 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" 14 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
14 #include "chrome/browser/extensions/extension_function.h" 15 #include "chrome/browser/extensions/extension_function.h"
15 #include "chrome/browser/extensions/extension_install_prompt.h" 16 #include "chrome/browser/extensions/extension_install_prompt.h"
16 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 17 #include "chrome/browser/signin/signin_global_error.h"
17 #include "google_apis/gaia/oauth2_mint_token_flow.h" 18 #include "google_apis/gaia/oauth2_mint_token_flow.h"
18 19
19 class GetAuthTokenFunctionTest; 20 class GetAuthTokenFunctionTest;
20 class MockGetAuthTokenFunction; 21 class MockGetAuthTokenFunction;
21 class GoogleServiceAuthError; 22 class GoogleServiceAuthError;
22 class Profile; 23 class Profile;
23 24
24 namespace extensions { 25 namespace extensions {
25 26
26 namespace identity_constants { 27 namespace identity_constants {
27 extern const char kInvalidClientId[]; 28 extern const char kInvalidClientId[];
28 extern const char kInvalidScopes[]; 29 extern const char kInvalidScopes[];
29 extern const char kAuthFailure[]; 30 extern const char kAuthFailure[];
30 extern const char kNoGrant[]; 31 extern const char kNoGrant[];
31 extern const char kUserRejected[]; 32 extern const char kUserRejected[];
32 extern const char kUserNotSignedIn[]; 33 extern const char kUserNotSignedIn[];
33 extern const char kInvalidRedirect[]; 34 extern const char kInvalidRedirect[];
34 } // namespace identity_constants 35 } // namespace identity_constants
35 36
36 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction, 37 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction,
37 public OAuth2MintTokenFlow::Delegate, 38 public OAuth2MintTokenFlow::Delegate,
38 public ExtensionInstallPrompt::Delegate, 39 public ExtensionInstallPrompt::Delegate,
39 public LoginUIService::Observer { 40 public IdentitySigninFlow::Delegate {
40 public: 41 public:
41 DECLARE_EXTENSION_FUNCTION("experimental.identity.getAuthToken", 42 DECLARE_EXTENSION_FUNCTION("experimental.identity.getAuthToken",
42 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN) 43 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN)
43 44
44 IdentityGetAuthTokenFunction(); 45 IdentityGetAuthTokenFunction();
45 46
46 protected: 47 protected:
47 virtual ~IdentityGetAuthTokenFunction(); 48 virtual ~IdentityGetAuthTokenFunction();
48 49
49 private: 50 private:
50 friend class GetAuthTokenFunctionTest; 51 friend class GetAuthTokenFunctionTest;
51 friend class MockGetAuthTokenFunction; 52 friend class MockGetAuthTokenFunction;
52 53
53 // ExtensionFunction: 54 // ExtensionFunction:
54 virtual bool RunImpl() OVERRIDE; 55 virtual bool RunImpl() OVERRIDE;
55 56
56 // OAuth2MintTokenFlow::Delegate implementation: 57 // OAuth2MintTokenFlow::Delegate implementation:
57 virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE; 58 virtual void OnMintTokenSuccess(const std::string& access_token) OVERRIDE;
58 virtual void OnMintTokenFailure( 59 virtual void OnMintTokenFailure(
59 const GoogleServiceAuthError& error) OVERRIDE; 60 const GoogleServiceAuthError& error) OVERRIDE;
60 virtual void OnIssueAdviceSuccess( 61 virtual void OnIssueAdviceSuccess(
61 const IssueAdviceInfo& issue_advice) OVERRIDE; 62 const IssueAdviceInfo& issue_advice) OVERRIDE;
62 63
63 // LoginUIService::Observer implementation. 64 // IdentitySigninFlow::Delegate implementation:
64 virtual void OnLoginUIShown(LoginUIService::LoginUI* ui) OVERRIDE { 65 virtual void SigninSuccess(const std::string& token) OVERRIDE;
65 // Do nothing when login ui is shown. 66 virtual void SigninFailed() OVERRIDE;
66 }
67 virtual void OnLoginUIClosed(LoginUIService::LoginUI* ui) OVERRIDE;
68 67
69 // ExtensionInstallPrompt::Delegate implementation: 68 // ExtensionInstallPrompt::Delegate implementation:
70 virtual void InstallUIProceed() OVERRIDE; 69 virtual void InstallUIProceed() OVERRIDE;
71 virtual void InstallUIAbort(bool user_initiated) OVERRIDE; 70 virtual void InstallUIAbort(bool user_initiated) OVERRIDE;
72 71
73 // Shows the login UI in a browser popup. 72 // Starts a MintTokenFlow with the given mode.
74 bool StartLogin(); 73 void StartFlow(OAuth2MintTokenFlow::Mode mode);
75 // Starts a MintTokenFlow with the given mode; Returns success.
76 bool StartFlow(OAuth2MintTokenFlow::Mode mode);
77 74
78 virtual void StartObservingLoginService();
79 virtual void StopObservingLoginService();
80 virtual void ShowLoginPopup(); 75 virtual void ShowLoginPopup();
81 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice); 76 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice);
82 // Caller owns the returned instance. 77 // Caller owns the returned instance.
83 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( 78 virtual OAuth2MintTokenFlow* CreateMintTokenFlow(
84 OAuth2MintTokenFlow::Mode mode); 79 OAuth2MintTokenFlow::Mode mode);
85 80
86 // Checks if there is a master login token to mint tokens for the extension. 81 // Checks if there is a master login token to mint tokens for the extension.
87 virtual bool HasLoginToken() const; 82 virtual bool HasLoginToken() const;
88 83
89 bool interactive_; 84 bool should_prompt_for_scopes_;
90 scoped_ptr<OAuth2MintTokenFlow> flow_; 85 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_;
86 std::string refresh_token_;
87 bool should_prompt_for_signin_;
91 88
92 // When launched in interactive mode, and if there is no existing grant, 89 // When launched in interactive mode, and if there is no existing grant,
93 // a permissions prompt will be popped up to the user. 90 // a permissions prompt will be popped up to the user.
94 scoped_ptr<ExtensionInstallPrompt> install_ui_; 91 scoped_ptr<ExtensionInstallPrompt> install_ui_;
92 scoped_ptr<IdentitySigninFlow> signin_flow_;
95 }; 93 };
96 94
97 class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction, 95 class IdentityLaunchWebAuthFlowFunction : public AsyncExtensionFunction,
98 public WebAuthFlow::Delegate { 96 public WebAuthFlow::Delegate {
99 public: 97 public:
100 DECLARE_EXTENSION_FUNCTION("experimental.identity.launchWebAuthFlow", 98 DECLARE_EXTENSION_FUNCTION("experimental.identity.launchWebAuthFlow",
101 EXPERIMENTAL_IDENTITY_LAUNCHWEBAUTHFLOW) 99 EXPERIMENTAL_IDENTITY_LAUNCHWEBAUTHFLOW)
102 100
103 IdentityLaunchWebAuthFlowFunction(); 101 IdentityLaunchWebAuthFlowFunction();
104 102
105 private: 103 private:
106 virtual ~IdentityLaunchWebAuthFlowFunction(); 104 virtual ~IdentityLaunchWebAuthFlowFunction();
107 virtual bool RunImpl() OVERRIDE; 105 virtual bool RunImpl() OVERRIDE;
108 106
109 // WebAuthFlow::Delegate implementation. 107 // WebAuthFlow::Delegate implementation.
110 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE; 108 virtual void OnAuthFlowSuccess(const std::string& redirect_url) OVERRIDE;
111 virtual void OnAuthFlowFailure() OVERRIDE; 109 virtual void OnAuthFlowFailure() OVERRIDE;
112 110
113 scoped_ptr<WebAuthFlow> auth_flow_; 111 scoped_ptr<WebAuthFlow> auth_flow_;
114 }; 112 };
115 113
116 class IdentityAPI : public ProfileKeyedAPI { 114 class IdentityAPI : public ProfileKeyedAPI,
115 public SigninGlobalError::AuthStatusProvider,
116 public content::NotificationObserver {
117 public: 117 public:
118 explicit IdentityAPI(Profile* profile); 118 explicit IdentityAPI(Profile* profile);
119 virtual ~IdentityAPI(); 119 virtual ~IdentityAPI();
120 void Initialize();
121
122 void ReportAuthError(const GoogleServiceAuthError& error);
120 123
121 // ProfileKeyedAPI implementation. 124 // ProfileKeyedAPI implementation.
125 virtual void Shutdown() OVERRIDE;
122 static ProfileKeyedAPIFactory<IdentityAPI>* GetFactoryInstance(); 126 static ProfileKeyedAPIFactory<IdentityAPI>* GetFactoryInstance();
123 127
128 // AuthStatusProvider implementation.
129 virtual GoogleServiceAuthError GetAuthStatus() const OVERRIDE;
130
131 // content::NotificationObserver implementation.
132 virtual void Observe(int type,
133 const content::NotificationSource& source,
134 const content::NotificationDetails& details) OVERRIDE;
135
124 private: 136 private:
125 friend class ProfileKeyedAPIFactory<IdentityAPI>; 137 friend class ProfileKeyedAPIFactory<IdentityAPI>;
126 138
127 // ProfileKeyedAPI implementation. 139 // ProfileKeyedAPI implementation.
128 static const char* service_name() { 140 static const char* service_name() {
129 return "IdentityAPI"; 141 return "IdentityAPI";
130 } 142 }
131 static const bool kServiceIsNULLWhileTesting = true; 143 static const bool kServiceIsNULLWhileTesting = true;
144
145 Profile* profile_;
146 SigninManager* signin_manager_;
147 GoogleServiceAuthError error_;
148 // Used to listen to notifications from the TokenService.
149 content::NotificationRegistrar registrar_;
132 }; 150 };
133 151
152 template <>
153 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies();
154
134 } // namespace extensions 155 } // namespace extensions
135 156
136 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ 157 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698