Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ios / public / provider / components / signin / browser / profile_oauth2_token_service_ios_provider.h
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.
4
5 #ifndef IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
6 #define IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_
7
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__)
17
18 #include <set>
19 #include <string>
20 #include <vector>
21
22 #include "base/callback.h"
23
24 namespace ios {
25
26 enum AuthenticationErrorCategory {
27   // Unknown errors.
28   kAuthenticationErrorCategoryUnknownErrors,
29   // Authorization errors.
30   kAuthenticationErrorCategoryAuthorizationErrors,
31   // Authorization errors with HTTP_FORBIDDEN (403) error code.
32   kAuthenticationErrorCategoryAuthorizationForbiddenErrors,
33   // Network server errors includes parsing error and should be treated as
34   // transient/offline errors.
35   kAuthenticationErrorCategoryNetworkServerErrors,
36   // User cancellation errors should be handled by treating them as a no-op.
37   kAuthenticationErrorCategoryUserCancellationErrors,
38   // User identity not found errors.
39   kAuthenticationErrorCategoryUnknownIdentityErrors,
40 };
41
42 // Interface that provides support for ProfileOAuth2TokenServiceIOS.
43 class ProfileOAuth2TokenServiceIOSProvider {
44  public:
45   typedef base::Callback<void(NSString* token,
46                               NSDate* expiration,
47                               NSError* error)> AccessTokenCallback;
48
49   ProfileOAuth2TokenServiceIOSProvider() {};
50   virtual ~ProfileOAuth2TokenServiceIOSProvider() {};
51
52   // Initializes the shared authentication library. This method should be called
53   // when loading credentials if the user is signed in to Chrome via the shared
54   // authentication library.
55   virtual void InitializeSharedAuthentication() = 0;
56
57   // Returns the ids of all accounts.
58   virtual std::vector<std::string> GetAllAccountIds() = 0;
59
60   // Starts fetching an access token for the account with id |account_id| with
61   // the given |scopes|. Once the token is obtained, |callback| is called.
62   virtual void GetAccessToken(const std::string& account_id,
63                               const std::string& client_id,
64                               const std::string& client_secret,
65                               const std::set<std::string>& scopes,
66                               const AccessTokenCallback& callback) = 0;
67
68   // Returns the authentication error category of |error|.
69   virtual AuthenticationErrorCategory GetAuthenticationErrorCategory(
70       NSError* error) const = 0;
71 };
72
73 }  // namespace ios
74
75 #endif  // IOS_PUBLIC_PROVIDER_COMPONENTS_SIGNIN_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_PROVIDER_H_