OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_ |
| 6 #define CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "google_apis/gaia/oauth2_token_service.h" |
| 13 #include "google_apis/gcm/gcm_client.h" |
| 14 #include "sync/notifier/gcm_network_channel_delegate.h" |
| 15 |
| 16 class Profile; |
| 17 |
| 18 namespace base { |
| 19 class SingleThreadTaskRunner; |
| 20 } // namespace base |
| 21 |
| 22 namespace invalidation { |
| 23 |
| 24 // GCMInvalidationBridge and GCMInvalidationBridge::Core implement functions |
| 25 // needed for GCMNetworkChannel. GCMInvalidationBridge lives on UI thread while |
| 26 // Core lives on IO thread. Core implements GCMNetworkChannelDelegate and posts |
| 27 // all function calls to GCMInvalidationBridge which does actual work to perform |
| 28 // them. |
| 29 class GCMInvalidationBridge : public OAuth2TokenService::Consumer, |
| 30 public base::NonThreadSafe { |
| 31 public: |
| 32 class Core; |
| 33 |
| 34 explicit GCMInvalidationBridge(Profile* profile); |
| 35 virtual ~GCMInvalidationBridge(); |
| 36 |
| 37 // OAuth2TokenService::Consumer implementation. |
| 38 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 39 const std::string& access_token, |
| 40 const base::Time& expiration_time) OVERRIDE; |
| 41 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 42 const GoogleServiceAuthError& error) OVERRIDE; |
| 43 |
| 44 scoped_ptr<syncer::GCMNetworkChannelDelegate> CreateDelegate(); |
| 45 |
| 46 void CoreInitializationDone( |
| 47 base::WeakPtr<Core> core, |
| 48 scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner); |
| 49 |
| 50 // Functions reflecting GCMNetworkChannelDelegate interface. These are called |
| 51 // on UI thread to perform actual work. |
| 52 void RequestToken( |
| 53 syncer::GCMNetworkChannelDelegate::RequestTokenCallback callback); |
| 54 void InvalidateToken(const std::string& token); |
| 55 |
| 56 void Register(syncer::GCMNetworkChannelDelegate::RegisterCallback callback); |
| 57 |
| 58 void RegisterFinished( |
| 59 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, |
| 60 const std::string& registration_id, |
| 61 gcm::GCMClient::Result result); |
| 62 |
| 63 private: |
| 64 // GCMInvalidationBridge is owned by TiclInvalidationService therefore it is |
| 65 // expected that profile_ pointer is valid throughout lifetime of this object. |
| 66 Profile* profile_; |
| 67 |
| 68 base::WeakPtr<Core> core_; |
| 69 scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner_; |
| 70 |
| 71 // Fields related to RequestToken function. |
| 72 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 73 syncer::GCMNetworkChannelDelegate::RequestTokenCallback |
| 74 request_token_callback_; |
| 75 |
| 76 base::WeakPtrFactory<GCMInvalidationBridge> weak_factory_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(GCMInvalidationBridge); |
| 79 }; |
| 80 |
| 81 } // namespace invalidation |
| 82 |
| 83 #endif // CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_ |
OLD | NEW |