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_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_H_ |
6 #define CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 // (OAuth2TokenService) and provides OAuth2 token refresh infrastructure. | 27 // (OAuth2TokenService) and provides OAuth2 token refresh infrastructure. |
28 // All public functions must be called on UI thread. | 28 // All public functions must be called on UI thread. |
29 class AuthService : public AuthServiceInterface, | 29 class AuthService : public AuthServiceInterface, |
30 public OAuth2TokenService::Observer { | 30 public OAuth2TokenService::Observer { |
31 public: | 31 public: |
32 // |url_request_context_getter| is used to perform authentication with | 32 // |url_request_context_getter| is used to perform authentication with |
33 // URLFetcher. | 33 // URLFetcher. |
34 // | 34 // |
35 // |scopes| specifies OAuth2 scopes. | 35 // |scopes| specifies OAuth2 scopes. |
36 AuthService(OAuth2TokenService* oauth2_token_service, | 36 AuthService(OAuth2TokenService* oauth2_token_service, |
| 37 const std::string& account_id, |
37 net::URLRequestContextGetter* url_request_context_getter, | 38 net::URLRequestContextGetter* url_request_context_getter, |
38 const std::vector<std::string>& scopes); | 39 const std::vector<std::string>& scopes); |
39 virtual ~AuthService(); | 40 virtual ~AuthService(); |
40 | 41 |
41 // Overriden from AuthServiceInterface: | 42 // Overriden from AuthServiceInterface: |
42 virtual void AddObserver(AuthServiceObserver* observer) OVERRIDE; | 43 virtual void AddObserver(AuthServiceObserver* observer) OVERRIDE; |
43 virtual void RemoveObserver(AuthServiceObserver* observer) OVERRIDE; | 44 virtual void RemoveObserver(AuthServiceObserver* observer) OVERRIDE; |
44 virtual void StartAuthentication(const AuthStatusCallback& callback) OVERRIDE; | 45 virtual void StartAuthentication(const AuthStatusCallback& callback) OVERRIDE; |
45 virtual bool HasAccessToken() const OVERRIDE; | 46 virtual bool HasAccessToken() const OVERRIDE; |
46 virtual bool HasRefreshToken() const OVERRIDE; | 47 virtual bool HasRefreshToken() const OVERRIDE; |
47 virtual const std::string& access_token() const OVERRIDE; | 48 virtual const std::string& access_token() const OVERRIDE; |
48 virtual void ClearAccessToken() OVERRIDE; | 49 virtual void ClearAccessToken() OVERRIDE; |
49 virtual void ClearRefreshToken() OVERRIDE; | 50 virtual void ClearRefreshToken() OVERRIDE; |
50 | 51 |
51 // Overridden from OAuth2TokenService::Observer: | 52 // Overridden from OAuth2TokenService::Observer: |
52 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | 53 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
53 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | 54 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; |
54 | 55 |
55 private: | 56 private: |
56 // Called when the state of the refresh token changes. | 57 // Called when the state of the refresh token changes. |
57 void OnHandleRefreshToken(bool has_refresh_token); | 58 void OnHandleRefreshToken(bool has_refresh_token); |
58 | 59 |
59 // Called when authentication request from StartAuthentication() is | 60 // Called when authentication request from StartAuthentication() is |
60 // completed. | 61 // completed. |
61 void OnAuthCompleted(const AuthStatusCallback& callback, | 62 void OnAuthCompleted(const AuthStatusCallback& callback, |
62 GDataErrorCode error, | 63 GDataErrorCode error, |
63 const std::string& access_token); | 64 const std::string& access_token); |
64 | 65 |
65 OAuth2TokenService* oauth2_token_service_; | 66 OAuth2TokenService* oauth2_token_service_; |
| 67 std::string account_id_; |
66 net::URLRequestContextGetter* url_request_context_getter_; // Not owned. | 68 net::URLRequestContextGetter* url_request_context_getter_; // Not owned. |
67 bool has_refresh_token_; | 69 bool has_refresh_token_; |
68 std::string access_token_; | 70 std::string access_token_; |
69 std::vector<std::string> scopes_; | 71 std::vector<std::string> scopes_; |
70 ObserverList<AuthServiceObserver> observers_; | 72 ObserverList<AuthServiceObserver> observers_; |
71 base::ThreadChecker thread_checker_; | 73 base::ThreadChecker thread_checker_; |
72 | 74 |
73 // Note: This should remain the last member so it'll be destroyed and | 75 // Note: This should remain the last member so it'll be destroyed and |
74 // invalidate its weak pointers before any other members are destroyed. | 76 // invalidate its weak pointers before any other members are destroyed. |
75 base::WeakPtrFactory<AuthService> weak_ptr_factory_; | 77 base::WeakPtrFactory<AuthService> weak_ptr_factory_; |
76 | 78 |
77 DISALLOW_COPY_AND_ASSIGN(AuthService); | 79 DISALLOW_COPY_AND_ASSIGN(AuthService); |
78 }; | 80 }; |
79 | 81 |
80 } // namespace google_apis | 82 } // namespace google_apis |
81 | 83 |
82 #endif // CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_H_ | 84 #endif // CHROME_BROWSER_GOOGLE_APIS_AUTH_SERVICE_H_ |
OLD | NEW |