Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / signin / ios / browser / profile_oauth2_token_service_ios_provider.h
blobb9c8da901f425e24efda9fa25c118e3d3d4eba81
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
6 #define COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
8 #if defined(__OBJC__)
9 @class NSDate;
10 @class NSError;
11 @class NSString;
12 #else
13 class NSDate;
14 class NSError;
15 class NSString;
16 #endif // defined(__OBJC__)
18 #include <set>
19 #include <string>
20 #include <vector>
22 #include "base/callback.h"
24 enum AuthenticationErrorCategory {
25 // Unknown errors.
26 kAuthenticationErrorCategoryUnknownErrors,
27 // Authorization errors.
28 kAuthenticationErrorCategoryAuthorizationErrors,
29 // Authorization errors with HTTP_FORBIDDEN (403) error code.
30 kAuthenticationErrorCategoryAuthorizationForbiddenErrors,
31 // Network server errors includes parsing error and should be treated as
32 // transient/offline errors.
33 kAuthenticationErrorCategoryNetworkServerErrors,
34 // User cancellation errors should be handled by treating them as a no-op.
35 kAuthenticationErrorCategoryUserCancellationErrors,
36 // User identity not found errors.
37 kAuthenticationErrorCategoryUnknownIdentityErrors,
40 // Interface that provides support for ProfileOAuth2TokenServiceIOS.
41 class ProfileOAuth2TokenServiceIOSProvider {
42 public:
43 // Account information.
44 struct AccountInfo {
45 std::string gaia;
46 std::string email;
49 typedef base::Callback<void(NSString* token,
50 NSDate* expiration,
51 NSError* error)> AccessTokenCallback;
53 ProfileOAuth2TokenServiceIOSProvider() {}
54 virtual ~ProfileOAuth2TokenServiceIOSProvider() {}
56 // Returns the ids of all accounts.
57 virtual std::vector<AccountInfo> GetAllAccounts() const = 0;
59 // Returns the account info composed of a GAIA id and email corresponding to
60 // email |email|.
61 virtual AccountInfo GetAccountInfoForEmail(
62 const std::string& email) const = 0;
64 // Returns the account info composed of a GAIA id and email corresponding to
65 // GAIA id |gaia|.
66 virtual AccountInfo GetAccountInfoForGaia(const std::string& gaia) const = 0;
68 // Starts fetching an access token for the account with id |gaia_id| with
69 // the given |scopes|. Once the token is obtained, |callback| is called.
70 virtual void GetAccessToken(const std::string& gaia_id,
71 const std::string& client_id,
72 const std::string& client_secret,
73 const std::set<std::string>& scopes,
74 const AccessTokenCallback& callback) = 0;
76 // Returns the authentication error category of |error|.
77 virtual AuthenticationErrorCategory GetAuthenticationErrorCategory(
78 NSError* error) const = 0;
81 #endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_