| 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_GOOGLE_APIS_AUTH_SERVICE_INTERFACE_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_INTERFACE_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_INTERFACE_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_INTERFACE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "chrome/browser/google_apis/gdata_errorcode.h" | 11 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 12 | 12 |
| 13 class Profile; | 13 class Profile; |
| 14 | 14 |
| 15 namespace google_apis { | 15 namespace google_apis { |
| 16 | 16 |
| 17 class AuthServiceObserver; | 17 class AuthServiceObserver; |
| 18 | 18 |
| 19 // Called when fetching of access token is complete. | 19 // Called when fetching of access token is complete. |
| 20 typedef base::Callback<void(GDataErrorCode error, | 20 typedef base::Callback<void(GDataErrorCode error, |
| 21 const std::string& access_token)> | 21 const std::string& access_token)> |
| 22 AuthStatusCallback; | 22 AuthStatusCallback; |
| 23 | 23 |
| 24 // This defines an interface for the authentication service which is required | 24 // This defines an interface for the authentication service which is required |
| 25 // by authenticated requests (AuthenticatedRequestInterface). | 25 // by authenticated requests (AuthenticatedRequestInterface). |
| 26 // All functions must be called on UI thread. | 26 // All functions must be called on UI thread. |
| 27 class AuthServiceInterface { | 27 class AuthServiceInterface { |
| 28 public: | 28 public: |
| 29 virtual ~AuthServiceInterface() {} |
| 30 |
| 29 // Adds and removes the observer. AddObserver() should be called before | 31 // Adds and removes the observer. AddObserver() should be called before |
| 30 // Initialize() as it can change the refresh token. | 32 // Initialize() as it can change the refresh token. |
| 31 virtual void AddObserver(AuthServiceObserver* observer) = 0; | 33 virtual void AddObserver(AuthServiceObserver* observer) = 0; |
| 32 virtual void RemoveObserver(AuthServiceObserver* observer) = 0; | 34 virtual void RemoveObserver(AuthServiceObserver* observer) = 0; |
| 33 | 35 |
| 34 // Initializes the auth service. Starts TokenService to retrieve the | |
| 35 // refresh token. | |
| 36 virtual void Initialize(Profile* profile) = 0; | |
| 37 | |
| 38 // Starts fetching OAuth2 access token from the refresh token. | 36 // Starts fetching OAuth2 access token from the refresh token. |
| 39 // |callback| must not be null. | 37 // |callback| must not be null. |
| 40 virtual void StartAuthentication(const AuthStatusCallback& callback) = 0; | 38 virtual void StartAuthentication(const AuthStatusCallback& callback) = 0; |
| 41 | 39 |
| 42 // True if an OAuth2 access token is retrieved and believed to be fresh. | 40 // True if an OAuth2 access token is retrieved and believed to be fresh. |
| 43 // The access token is used to access the Drive server. | 41 // The access token is used to access the Drive server. |
| 44 virtual bool HasAccessToken() const = 0; | 42 virtual bool HasAccessToken() const = 0; |
| 45 | 43 |
| 46 // True if an OAuth2 refresh token is present. Its absence means that user | 44 // True if an OAuth2 refresh token is present. Its absence means that user |
| 47 // is not properly authenticated. | 45 // is not properly authenticated. |
| 48 // The refresh token is used to get the access token. | 46 // The refresh token is used to get the access token. |
| 49 virtual bool HasRefreshToken() const = 0; | 47 virtual bool HasRefreshToken() const = 0; |
| 50 | 48 |
| 51 // Returns OAuth2 access token. | 49 // Returns OAuth2 access token. |
| 52 virtual const std::string& access_token() const = 0; | 50 virtual const std::string& access_token() const = 0; |
| 53 | 51 |
| 54 // Clears OAuth2 access token. | 52 // Clears OAuth2 access token. |
| 55 virtual void ClearAccessToken() = 0; | 53 virtual void ClearAccessToken() = 0; |
| 56 | 54 |
| 57 // Clears OAuth2 refresh token. | 55 // Clears OAuth2 refresh token. |
| 58 virtual void ClearRefreshToken() = 0; | 56 virtual void ClearRefreshToken() = 0; |
| 59 }; | 57 }; |
| 60 | 58 |
| 61 } // namespace google_apis | 59 } // namespace google_apis |
| 62 | 60 |
| 63 #endif // CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_INTERFACE_H_ | 61 #endif // CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_INTERFACE_H_ |
| OLD | NEW |