OLD | NEW |
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 <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h" | 16 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h" |
17 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h" | 17 #include "chrome/browser/extensions/api/identity/identity_mint_queue.h" |
18 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h" | 18 #include "chrome/browser/extensions/api/identity/identity_signin_flow.h" |
19 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" | 19 #include "chrome/browser/extensions/api/identity/web_auth_flow.h" |
20 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | 20 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
21 #include "chrome/browser/extensions/extension_function.h" | 21 #include "chrome/browser/extensions/extension_function.h" |
| 22 #include "chrome/browser/signin/oauth2_token_service.h" |
22 #include "chrome/browser/signin/signin_global_error.h" | 23 #include "chrome/browser/signin/signin_global_error.h" |
23 #include "google_apis/gaia/oauth2_mint_token_flow.h" | 24 #include "google_apis/gaia/oauth2_mint_token_flow.h" |
24 | 25 |
25 class GoogleServiceAuthError; | 26 class GoogleServiceAuthError; |
| 27 class MockGetAuthTokenFunction; |
26 class Profile; | 28 class Profile; |
27 class SigninManagerBase; | 29 class SigninManagerBase; |
28 | 30 |
29 namespace extensions { | 31 namespace extensions { |
30 | 32 |
31 class GetAuthTokenFunctionTest; | 33 class GetAuthTokenFunctionTest; |
32 class MockGetAuthTokenFunction; | 34 class MockGetAuthTokenFunction; |
33 | 35 |
34 namespace identity_constants { | 36 namespace identity_constants { |
35 extern const char kInvalidClientId[]; | 37 extern const char kInvalidClientId[]; |
(...skipping 22 matching lines...) Expand all Loading... |
58 // the server, and an access token will be returned to the caller. | 60 // the server, and an access token will be returned to the caller. |
59 // | 61 // |
60 // In some cases we need to display a sign-in dialog. Normally the | 62 // In some cases we need to display a sign-in dialog. Normally the |
61 // profile will be signed in already, but if it turns out we need a | 63 // profile will be signed in already, but if it turns out we need a |
62 // new login token, there is a sign-in flow. If that flow completes | 64 // new login token, there is a sign-in flow. If that flow completes |
63 // successfully, getAuthToken proceeds to the non-interactive flow. | 65 // successfully, getAuthToken proceeds to the non-interactive flow. |
64 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction, | 66 class IdentityGetAuthTokenFunction : public AsyncExtensionFunction, |
65 public GaiaWebAuthFlow::Delegate, | 67 public GaiaWebAuthFlow::Delegate, |
66 public IdentityMintRequestQueue::Request, | 68 public IdentityMintRequestQueue::Request, |
67 public OAuth2MintTokenFlow::Delegate, | 69 public OAuth2MintTokenFlow::Delegate, |
68 public IdentitySigninFlow::Delegate { | 70 public IdentitySigninFlow::Delegate, |
| 71 public OAuth2TokenService::Consumer { |
69 public: | 72 public: |
70 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken", | 73 DECLARE_EXTENSION_FUNCTION("identity.getAuthToken", |
71 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN); | 74 EXPERIMENTAL_IDENTITY_GETAUTHTOKEN); |
72 | 75 |
73 IdentityGetAuthTokenFunction(); | 76 IdentityGetAuthTokenFunction(); |
74 | 77 |
75 protected: | 78 protected: |
76 virtual ~IdentityGetAuthTokenFunction(); | 79 virtual ~IdentityGetAuthTokenFunction(); |
77 | 80 |
78 private: | 81 private: |
(...skipping 27 matching lines...) Expand all Loading... |
106 virtual void SigninSuccess(const std::string& token) OVERRIDE; | 109 virtual void SigninSuccess(const std::string& token) OVERRIDE; |
107 virtual void SigninFailed() OVERRIDE; | 110 virtual void SigninFailed() OVERRIDE; |
108 | 111 |
109 // GaiaWebAuthFlow::Delegate implementation: | 112 // GaiaWebAuthFlow::Delegate implementation: |
110 virtual void OnGaiaFlowFailure(GaiaWebAuthFlow::Failure failure, | 113 virtual void OnGaiaFlowFailure(GaiaWebAuthFlow::Failure failure, |
111 GoogleServiceAuthError service_error, | 114 GoogleServiceAuthError service_error, |
112 const std::string& oauth_error) OVERRIDE; | 115 const std::string& oauth_error) OVERRIDE; |
113 virtual void OnGaiaFlowCompleted(const std::string& access_token, | 116 virtual void OnGaiaFlowCompleted(const std::string& access_token, |
114 const std::string& expiration) OVERRIDE; | 117 const std::string& expiration) OVERRIDE; |
115 | 118 |
| 119 // OAuth2TokenService::Consumer implementation: |
| 120 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 121 const std::string& access_token, |
| 122 const base::Time& expiration_time) OVERRIDE; |
| 123 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 124 const GoogleServiceAuthError& error) OVERRIDE; |
| 125 |
116 // Starts a mint token request to GAIA. | 126 // Starts a mint token request to GAIA. |
117 void StartGaiaRequest(OAuth2MintTokenFlow::Mode mode); | 127 void StartGaiaRequest(OAuth2MintTokenFlow::Mode mode); |
118 | 128 |
119 // Methods for invoking UI. Overridable for testing. | 129 // Methods for invoking UI. Overridable for testing. |
120 virtual void ShowLoginPopup(); | 130 virtual void ShowLoginPopup(); |
121 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice); | 131 virtual void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice); |
122 // Caller owns the returned instance. | 132 // Caller owns the returned instance. |
123 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( | 133 virtual OAuth2MintTokenFlow* CreateMintTokenFlow( |
124 OAuth2MintTokenFlow::Mode mode); | 134 OAuth2MintTokenFlow::Mode mode); |
125 | 135 |
126 // Checks if there is a master login token to mint tokens for the extension. | 136 // Checks if there is a master login token to mint tokens for the extension. |
127 virtual bool HasLoginToken() const; | 137 virtual bool HasLoginToken() const; |
128 | 138 |
129 // Maps OAuth2 protocol errors to an error message returned to the | 139 // Maps OAuth2 protocol errors to an error message returned to the |
130 // developer in chrome.runtime.lastError. | 140 // developer in chrome.runtime.lastError. |
131 std::string MapOAuth2ErrorToDescription(const std::string& error); | 141 std::string MapOAuth2ErrorToDescription(const std::string& error); |
132 | 142 |
133 bool should_prompt_for_scopes_; | 143 bool should_prompt_for_scopes_; |
134 IdentityMintRequestQueue::MintType mint_token_flow_type_; | 144 IdentityMintRequestQueue::MintType mint_token_flow_type_; |
135 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_; | 145 scoped_ptr<OAuth2MintTokenFlow> mint_token_flow_; |
136 std::string refresh_token_; | 146 std::string refresh_token_; |
137 bool should_prompt_for_signin_; | 147 bool should_prompt_for_signin_; |
138 | 148 |
139 // When launched in interactive mode, and if there is no existing grant, | 149 // When launched in interactive mode, and if there is no existing grant, |
140 // a permissions prompt will be popped up to the user. | 150 // a permissions prompt will be popped up to the user. |
141 IssueAdviceInfo issue_advice_; | 151 IssueAdviceInfo issue_advice_; |
142 scoped_ptr<GaiaWebAuthFlow> gaia_web_auth_flow_; | 152 scoped_ptr<GaiaWebAuthFlow> gaia_web_auth_flow_; |
143 scoped_ptr<IdentitySigninFlow> signin_flow_; | 153 scoped_ptr<IdentitySigninFlow> signin_flow_; |
| 154 scoped_ptr<OAuth2TokenService::Request> device_token_request_; |
144 }; | 155 }; |
145 | 156 |
146 class IdentityRemoveCachedAuthTokenFunction : public SyncExtensionFunction { | 157 class IdentityRemoveCachedAuthTokenFunction : public SyncExtensionFunction { |
147 public: | 158 public: |
148 DECLARE_EXTENSION_FUNCTION("identity.removeCachedAuthToken", | 159 DECLARE_EXTENSION_FUNCTION("identity.removeCachedAuthToken", |
149 EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN) | 160 EXPERIMENTAL_IDENTITY_REMOVECACHEDAUTHTOKEN) |
150 IdentityRemoveCachedAuthTokenFunction(); | 161 IdentityRemoveCachedAuthTokenFunction(); |
151 | 162 |
152 protected: | 163 protected: |
153 virtual ~IdentityRemoveCachedAuthTokenFunction(); | 164 virtual ~IdentityRemoveCachedAuthTokenFunction(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 IdentityMintRequestQueue mint_queue_; | 289 IdentityMintRequestQueue mint_queue_; |
279 CachedTokens token_cache_; | 290 CachedTokens token_cache_; |
280 }; | 291 }; |
281 | 292 |
282 template <> | 293 template <> |
283 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); | 294 void ProfileKeyedAPIFactory<IdentityAPI>::DeclareFactoryDependencies(); |
284 | 295 |
285 } // namespace extensions | 296 } // namespace extensions |
286 | 297 |
287 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ | 298 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_API_H_ |
OLD | NEW |