Add conversions for EmbedObject, Figcaption and Figure
[chromium-blink-merge.git] / google_apis / drive / auth_service.h
blobf055a1ccb31f85ac7666afbd8bba2b816ff98af5
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.
5 #ifndef GOOGLE_APIS_DRIVE_AUTH_SERVICE_H_
6 #define GOOGLE_APIS_DRIVE_AUTH_SERVICE_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/weak_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/threading/thread_checker.h"
14 #include "google_apis/drive/auth_service_interface.h"
15 #include "google_apis/gaia/oauth2_token_service.h"
17 namespace net {
18 class URLRequestContextGetter;
21 namespace google_apis {
23 class AuthServiceObserver;
25 // This class provides authentication for Google services.
26 // It integrates specific service integration with OAuth2 stack
27 // (OAuth2TokenService) and provides OAuth2 token refresh infrastructure.
28 // All public functions must be called on UI thread.
29 class AuthService : public AuthServiceInterface,
30 public OAuth2TokenService::Observer {
31 public:
32 // |url_request_context_getter| is used to perform authentication with
33 // URLFetcher.
35 // |scopes| specifies OAuth2 scopes.
36 AuthService(OAuth2TokenService* oauth2_token_service,
37 const std::string& account_id,
38 net::URLRequestContextGetter* url_request_context_getter,
39 const std::vector<std::string>& scopes);
40 virtual ~AuthService();
42 // Overriden from AuthServiceInterface:
43 virtual void AddObserver(AuthServiceObserver* observer) OVERRIDE;
44 virtual void RemoveObserver(AuthServiceObserver* observer) OVERRIDE;
45 virtual void StartAuthentication(const AuthStatusCallback& callback) OVERRIDE;
46 virtual bool HasAccessToken() const OVERRIDE;
47 virtual bool HasRefreshToken() const OVERRIDE;
48 virtual const std::string& access_token() const OVERRIDE;
49 virtual void ClearAccessToken() OVERRIDE;
50 virtual void ClearRefreshToken() OVERRIDE;
52 // Overridden from OAuth2TokenService::Observer:
53 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
54 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
56 private:
57 // Called when the state of the refresh token changes.
58 void OnHandleRefreshToken(bool has_refresh_token);
60 // Called when authentication request from StartAuthentication() is
61 // completed.
62 void OnAuthCompleted(const AuthStatusCallback& callback,
63 GDataErrorCode error,
64 const std::string& access_token);
66 OAuth2TokenService* oauth2_token_service_;
67 std::string account_id_;
68 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
69 bool has_refresh_token_;
70 std::string access_token_;
71 std::vector<std::string> scopes_;
72 ObserverList<AuthServiceObserver> observers_;
73 base::ThreadChecker thread_checker_;
75 // Note: This should remain the last member so it'll be destroyed and
76 // invalidate its weak pointers before any other members are destroyed.
77 base::WeakPtrFactory<AuthService> weak_ptr_factory_;
79 DISALLOW_COPY_AND_ASSIGN(AuthService);
82 } // namespace google_apis
84 #endif // GOOGLE_APIS_DRIVE_AUTH_SERVICE_H_