Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Side by Side Diff: chrome/browser/chromeos/gdata/auth_service.h

Issue 10920091: Move Drive API files to google_apis directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reflect comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_AUTH_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_AUTH_SERVICE_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/memory/weak_ptr.h"
12 #include "base/observer_list.h"
13 #include "chrome/browser/google_apis/gdata_errorcode.h"
14 #include "chrome/browser/google_apis/operations_base.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17
18 class Profile;
19
20 namespace gdata {
21
22 class OperationRegistry;
23
24 // This class provides authentication for Google services.
25 // It integrates specific service integration with OAuth2 stack
26 // (TokenService) and provides OAuth2 token refresh infrastructure.
27 // All public functions must be called on UI thread.
28 class AuthService : public content::NotificationObserver {
29 public:
30 class Observer {
31 public:
32 // Triggered when a new OAuth2 refresh token is received from TokenService.
33 virtual void OnOAuth2RefreshTokenChanged() = 0;
34
35 protected:
36 virtual ~Observer() {}
37 };
38
39 explicit AuthService(const std::vector<std::string>& scopes);
40 virtual ~AuthService();
41
42 // Adds and removes the observer. AddObserver() should be called before
43 // Initialize() as it can change the refresh token.
44 void AddObserver(Observer* observer);
45 void RemoveObserver(Observer* observer);
46
47 // Initializes the auth service. Starts TokenService to retrieve the
48 // refresh token.
49 void Initialize(Profile* profile);
50
51 // Starts fetching OAuth2 auth token from the refresh token for |scopes_|.
52 void StartAuthentication(OperationRegistry* registry,
53 const AuthStatusCallback& callback);
54
55 // True if an OAuth2 access token is retrieved and believed to be fresh.
56 // The access token is used to access the Drive server.
57 bool HasAccessToken() const { return !access_token_.empty(); }
58
59 // True if an OAuth2 refresh token is present. Its absence means that user
60 // is not properly authenticated.
61 // The refresh token is used to get the access token.
62 bool HasRefreshToken() const { return !refresh_token_.empty(); }
63
64 // Returns OAuth2 access token.
65 const std::string& access_token() const { return access_token_; }
66
67 // Clears OAuth2 access token.
68 void ClearAccessToken() { access_token_.clear(); }
69
70 // Overridden from content::NotificationObserver:
71 virtual void Observe(int type,
72 const content::NotificationSource& source,
73 const content::NotificationDetails& details) OVERRIDE;
74
75 // Sets the access_token as specified. This should be used only for testing.
76 void set_access_token_for_testing(const std::string& token) {
77 access_token_ = token;
78 }
79
80 private:
81 // Helper function for StartAuthentication() call.
82 void StartAuthenticationOnUIThread(OperationRegistry* registry,
83 const AuthStatusCallback& callback);
84
85 // Callback for AuthOperation (InternalAuthStatusCallback).
86 void OnAuthCompleted(const AuthStatusCallback& callback,
87 GDataErrorCode error,
88 const std::string& access_token);
89
90 Profile* profile_;
91 std::string refresh_token_;
92 std::string access_token_;
93 std::vector<std::string> scopes_;
94 ObserverList<Observer> observers_;
95
96 content::NotificationRegistrar registrar_;
97
98 // Note: This should remain the last member so it'll be destroyed and
99 // invalidate its weak pointers before any other members are destroyed.
100 base::WeakPtrFactory<AuthService> weak_ptr_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(AuthService);
103 };
104
105 } // namespace gdata
106
107 #endif // CHROME_BROWSER_CHROMEOS_GDATA_AUTH_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.cc ('k') | chrome/browser/chromeos/gdata/auth_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698