OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/sync/profile_sync_auth_provider.h" | 5 #include "chrome/browser/sync/profile_sync_auth_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 11 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
12 #include "google_apis/gaia/gaia_constants.h" | 12 #include "google_apis/gaia/gaia_constants.h" |
13 | 13 |
14 // This is thin proxy class for forwarding calls between sync and UI threads. | 14 // This is thin proxy class for forwarding calls between sync and UI threads. |
15 // The main purpose is to hide the fact that ProfileSyncAuthProvider and | 15 // The main purpose is to hide the fact that ProfileSyncAuthProvider and |
16 // SyncThreadProxy have independent lifetimes. If ProfileSyncAuthProvider is | 16 // SyncThreadProxy have independent lifetimes. If ProfileSyncAuthProvider is |
17 // destroyed first calls to RequestAccessToken will never complete. This is fine | 17 // destroyed first calls to RequestAccessToken will never complete. This is fine |
18 // since sync thread is not blocked and is in the process of shutdown anyway. | 18 // since sync thread is not blocked and is in the process of shutdown anyway. |
19 class ProfileSyncAuthProvider::SyncThreadProxy | 19 class ProfileSyncAuthProvider::SyncThreadProxy |
20 : public syncer::SyncAuthProvider, | 20 : public syncer::SyncAuthProvider, |
21 public base::NonThreadSafe { | 21 public base::NonThreadSafe { |
22 public: | 22 public: |
23 SyncThreadProxy( | 23 SyncThreadProxy( |
24 base::WeakPtr<ProfileSyncAuthProvider> provider_impl, | 24 base::WeakPtr<ProfileSyncAuthProvider> provider_impl, |
25 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner); | 25 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner); |
26 | 26 |
27 // syncer::SyncAuthProvider implementation. | 27 // syncer::SyncAuthProvider implementation. |
28 virtual void RequestAccessToken( | 28 virtual void RequestAccessToken( |
29 const RequestTokenCallback& callback) OVERRIDE; | 29 const RequestTokenCallback& callback) override; |
30 virtual void InvalidateAccessToken(const std::string& token) OVERRIDE; | 30 virtual void InvalidateAccessToken(const std::string& token) override; |
31 | 31 |
32 private: | 32 private: |
33 base::WeakPtr<ProfileSyncAuthProvider> provider_impl_; | 33 base::WeakPtr<ProfileSyncAuthProvider> provider_impl_; |
34 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_; | 34 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_; |
35 | 35 |
36 DISALLOW_COPY_AND_ASSIGN(SyncThreadProxy); | 36 DISALLOW_COPY_AND_ASSIGN(SyncThreadProxy); |
37 }; | 37 }; |
38 | 38 |
39 ProfileSyncAuthProvider::SyncThreadProxy::SyncThreadProxy( | 39 ProfileSyncAuthProvider::SyncThreadProxy::SyncThreadProxy( |
40 base::WeakPtr<ProfileSyncAuthProvider> provider_impl, | 40 base::WeakPtr<ProfileSyncAuthProvider> provider_impl, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 token_service_->InvalidateToken(account_id_, oauth2_scope_, token); | 129 token_service_->InvalidateToken(account_id_, oauth2_scope_, token); |
130 } | 130 } |
131 | 131 |
132 scoped_ptr<syncer::SyncAuthProvider> | 132 scoped_ptr<syncer::SyncAuthProvider> |
133 ProfileSyncAuthProvider::CreateProviderForSyncThread() { | 133 ProfileSyncAuthProvider::CreateProviderForSyncThread() { |
134 DCHECK(CalledOnValidThread()); | 134 DCHECK(CalledOnValidThread()); |
135 scoped_ptr<syncer::SyncAuthProvider> auth_provider(new SyncThreadProxy( | 135 scoped_ptr<syncer::SyncAuthProvider> auth_provider(new SyncThreadProxy( |
136 weak_factory_.GetWeakPtr(), base::MessageLoopProxy::current())); | 136 weak_factory_.GetWeakPtr(), base::MessageLoopProxy::current())); |
137 return auth_provider.Pass(); | 137 return auth_provider.Pass(); |
138 } | 138 } |
OLD | NEW |