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_CHROMEOS_GDATA_GDATA_AUTH_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_AUTH_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_AUTH_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_AUTH_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 void RemoveObserver(Observer* observer); | 47 void RemoveObserver(Observer* observer); |
48 | 48 |
49 // Initializes the auth service. Starts TokenService to retrieve the | 49 // Initializes the auth service. Starts TokenService to retrieve the |
50 // refresh token. | 50 // refresh token. |
51 void Initialize(Profile* profile); | 51 void Initialize(Profile* profile); |
52 | 52 |
53 // Starts fetching OAuth2 auth token from the refresh token. | 53 // Starts fetching OAuth2 auth token from the refresh token. |
54 void StartAuthentication(GDataOperationRegistry* registry, | 54 void StartAuthentication(GDataOperationRegistry* registry, |
55 const AuthStatusCallback& callback); | 55 const AuthStatusCallback& callback); |
56 | 56 |
57 // True if OAuth2 auth token is retrieved and believed to be fresh. | 57 // True if an OAuth2 access token is retrieved and believed to be fresh. |
58 bool IsFullyAuthenticated() const { return !auth_token_.empty(); } | 58 // The access token is used to access the gdata server. |
| 59 bool HasAccessToken() const { return !access_token_.empty(); } |
59 | 60 |
60 // True if OAuth2 refresh token is present. It's absence means that user | 61 // True if an OAuth2 refresh token is present. Its absence means that user |
61 // is not properly authenticated. | 62 // is not properly authenticated. |
62 bool IsPartiallyAuthenticated() const { return !refresh_token_.empty(); } | 63 // The refresh token is used to get the access token. |
| 64 bool HasRefreshToken() const { return !refresh_token_.empty(); } |
63 | 65 |
64 // Gets OAuth2 auth token. | 66 // Returns OAuth2 access token. |
65 const std::string& oauth2_auth_token() const { return auth_token_; } | 67 const std::string& access_token() const { return access_token_; } |
66 | 68 |
67 // Clears OAuth2 token. | 69 // Clears OAuth2 access token. |
68 void ClearOAuth2Token() { auth_token_.clear(); } | 70 void ClearAccessToken() { access_token_.clear(); } |
69 | |
70 // Gets OAuth2 refresh token. | |
71 const std::string& GetOAuth2RefreshToken() { return refresh_token_; } | |
72 | 71 |
73 // Callback for AuthOperation (InternalAuthStatusCallback). | 72 // Callback for AuthOperation (InternalAuthStatusCallback). |
74 void OnAuthCompleted(scoped_refptr<base::MessageLoopProxy> relay_proxy, | 73 void OnAuthCompleted(scoped_refptr<base::MessageLoopProxy> relay_proxy, |
75 const AuthStatusCallback& callback, | 74 const AuthStatusCallback& callback, |
76 GDataErrorCode error, | 75 GDataErrorCode error, |
77 const std::string& auth_token); | 76 const std::string& access_token); |
78 | 77 |
79 // Overridden from content::NotificationObserver: | 78 // Overridden from content::NotificationObserver: |
80 virtual void Observe(int type, | 79 virtual void Observe(int type, |
81 const content::NotificationSource& source, | 80 const content::NotificationSource& source, |
82 const content::NotificationDetails& details) OVERRIDE; | 81 const content::NotificationDetails& details) OVERRIDE; |
83 | 82 |
84 // Sets the auth_token as specified. This should be used only for testing. | 83 // Sets the access_token as specified. This should be used only for testing. |
85 void set_oauth2_auth_token_for_testing(const std::string& token) { | 84 void set_access_token_for_testing(const std::string& token) { |
86 auth_token_ = token; | 85 access_token_ = token; |
87 } | 86 } |
88 | 87 |
89 private: | 88 private: |
90 // Helper function for StartAuthentication() call. | 89 // Helper function for StartAuthentication() call. |
91 void StartAuthenticationOnUIThread( | 90 void StartAuthenticationOnUIThread( |
92 GDataOperationRegistry* registry, | 91 GDataOperationRegistry* registry, |
93 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 92 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
94 const AuthStatusCallback& callback); | 93 const AuthStatusCallback& callback); |
95 | 94 |
96 Profile* profile_; | 95 Profile* profile_; |
97 std::string refresh_token_; | 96 std::string refresh_token_; |
98 std::string auth_token_; | 97 std::string access_token_; |
99 ObserverList<Observer> observers_; | 98 ObserverList<Observer> observers_; |
100 | 99 |
101 content::NotificationRegistrar registrar_; | 100 content::NotificationRegistrar registrar_; |
102 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_; | 101 base::WeakPtrFactory<GDataAuthService> weak_ptr_factory_; |
103 base::WeakPtr<GDataAuthService> weak_ptr_bound_to_ui_thread_; | 102 base::WeakPtr<GDataAuthService> weak_ptr_bound_to_ui_thread_; |
104 | 103 |
105 DISALLOW_COPY_AND_ASSIGN(GDataAuthService); | 104 DISALLOW_COPY_AND_ASSIGN(GDataAuthService); |
106 }; | 105 }; |
107 | 106 |
108 } // namespace gdata | 107 } // namespace gdata |
109 | 108 |
110 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_AUTH_SERVICE_H_ | 109 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_AUTH_SERVICE_H_ |
OLD | NEW |