Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_auth_provider.h
blobde3f3d9e67f8a978a47d54f3e1c50a4c38dca1a2
1 // Copyright 2014 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 CHROME_BROWSER_SYNC_PROFILE_SYNC_AUTH_PROVIDER_H_
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_AUTH_PROVIDER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "google_apis/gaia/oauth2_token_service.h"
11 #include "sync/internal_api/public/sync_auth_provider.h"
13 class ProfileOAuth2TokenService;
15 namespace base {
16 class SingleThreadTaskRunner;
17 } // namespace base
19 // ProfileSyncAuthProvider implements function for SyncAuthProvider. It doesn't
20 // inherit from SyncAuthProvider because it lives on UI thread while requests
21 // originate from sync thread. SyncThreadProxy implements SyncAuthProvider and
22 // forwards all requests.
23 class ProfileSyncAuthProvider : public OAuth2TokenService::Consumer,
24 public base::NonThreadSafe {
25 public:
26 ProfileSyncAuthProvider(ProfileOAuth2TokenService* token_service,
27 const std::string& account_id,
28 const std::string& scope);
29 ~ProfileSyncAuthProvider() override;
31 // OAuth2TokenService::Consumer implementation.
32 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
33 const std::string& access_token,
34 const base::Time& expiration_time) override;
35 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
36 const GoogleServiceAuthError& error) override;
38 // Request access token from OAuth2TokenService. Once access token is received
39 // result should be posted to callback on task_runner thread.
40 void RequestAccessToken(
41 const syncer::SyncAuthProvider::RequestTokenCallback& callback,
42 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
44 void InvalidateAccessToken(const std::string& token);
46 scoped_ptr<syncer::SyncAuthProvider> CreateProviderForSyncThread();
48 private:
49 class SyncThreadProxy;
51 void RespondToTokenRequest(const GoogleServiceAuthError& error,
52 const std::string& token);
54 ProfileOAuth2TokenService* token_service_;
55 std::string account_id_;
56 OAuth2TokenService::ScopeSet oauth2_scope_;
58 // Only one outstanding request is allowed. Previous request is reported
59 // cancelled if new one arrives.
60 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
61 syncer::SyncAuthProvider::RequestTokenCallback request_token_callback_;
62 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_;
64 base::WeakPtrFactory<ProfileSyncAuthProvider> weak_factory_;
66 DISALLOW_COPY_AND_ASSIGN(ProfileSyncAuthProvider);
69 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_AUTH_PROVIDER_H_