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