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 "chrome/browser/services/gcm/gcm_app_handler.h" | 12 #include "chrome/browser/services/gcm/gcm_app_handler.h" |
13 #include "google_apis/gaia/oauth2_token_service.h" | 13 #include "google_apis/gaia/oauth2_token_service.h" |
14 #include "google_apis/gcm/gcm_client.h" | 14 #include "google_apis/gcm/gcm_client.h" |
15 #include "sync/notifier/gcm_network_channel_delegate.h" | 15 #include "sync/notifier/gcm_network_channel_delegate.h" |
16 | 16 |
17 class Profile; | |
18 | |
19 namespace base { | 17 namespace base { |
20 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
21 } // namespace base | 19 } // namespace base |
22 | 20 |
| 21 namespace gcm { |
| 22 class GCMProfileService; |
| 23 } // namespace gcm |
| 24 |
23 namespace invalidation { | 25 namespace invalidation { |
24 | 26 |
| 27 class InvalidationAuthProvider; |
| 28 |
25 // GCMInvalidationBridge and GCMInvalidationBridge::Core implement functions | 29 // GCMInvalidationBridge and GCMInvalidationBridge::Core implement functions |
26 // needed for GCMNetworkChannel. GCMInvalidationBridge lives on UI thread while | 30 // needed for GCMNetworkChannel. GCMInvalidationBridge lives on UI thread while |
27 // Core lives on IO thread. Core implements GCMNetworkChannelDelegate and posts | 31 // Core lives on IO thread. Core implements GCMNetworkChannelDelegate and posts |
28 // all function calls to GCMInvalidationBridge which does actual work to perform | 32 // all function calls to GCMInvalidationBridge which does actual work to perform |
29 // them. | 33 // them. |
30 class GCMInvalidationBridge : public gcm::GCMAppHandler, | 34 class GCMInvalidationBridge : public gcm::GCMAppHandler, |
31 public OAuth2TokenService::Consumer, | 35 public OAuth2TokenService::Consumer, |
32 public base::NonThreadSafe { | 36 public base::NonThreadSafe { |
33 public: | 37 public: |
34 class Core; | 38 class Core; |
35 | 39 |
36 explicit GCMInvalidationBridge(Profile* profile); | 40 GCMInvalidationBridge(gcm::GCMProfileService* gcm_profile_service, |
| 41 InvalidationAuthProvider* auth_provider); |
37 virtual ~GCMInvalidationBridge(); | 42 virtual ~GCMInvalidationBridge(); |
38 | 43 |
39 // OAuth2TokenService::Consumer implementation. | 44 // OAuth2TokenService::Consumer implementation. |
40 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 45 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
41 const std::string& access_token, | 46 const std::string& access_token, |
42 const base::Time& expiration_time) OVERRIDE; | 47 const base::Time& expiration_time) OVERRIDE; |
43 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 48 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
44 const GoogleServiceAuthError& error) OVERRIDE; | 49 const GoogleServiceAuthError& error) OVERRIDE; |
45 | 50 |
46 // gcm::GCMEventRouter implementation. | 51 // gcm::GCMEventRouter implementation. |
(...skipping 21 matching lines...) Expand all Loading... |
68 void Register(syncer::GCMNetworkChannelDelegate::RegisterCallback callback); | 73 void Register(syncer::GCMNetworkChannelDelegate::RegisterCallback callback); |
69 | 74 |
70 void SubscribeForIncomingMessages(); | 75 void SubscribeForIncomingMessages(); |
71 | 76 |
72 void RegisterFinished( | 77 void RegisterFinished( |
73 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, | 78 syncer::GCMNetworkChannelDelegate::RegisterCallback callback, |
74 const std::string& registration_id, | 79 const std::string& registration_id, |
75 gcm::GCMClient::Result result); | 80 gcm::GCMClient::Result result); |
76 | 81 |
77 private: | 82 private: |
78 // GCMInvalidationBridge is owned by TiclInvalidationService therefore it is | 83 gcm::GCMProfileService* const gcm_profile_service_; |
79 // expected that profile_ pointer is valid throughout lifetime of this object. | 84 InvalidationAuthProvider* const auth_provider_; |
80 Profile* profile_; | |
81 | 85 |
82 base::WeakPtr<Core> core_; | 86 base::WeakPtr<Core> core_; |
83 scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner_; | 87 scoped_refptr<base::SingleThreadTaskRunner> core_thread_task_runner_; |
84 | 88 |
85 // Fields related to RequestToken function. | 89 // Fields related to RequestToken function. |
86 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 90 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
87 syncer::GCMNetworkChannelDelegate::RequestTokenCallback | 91 syncer::GCMNetworkChannelDelegate::RequestTokenCallback |
88 request_token_callback_; | 92 request_token_callback_; |
89 bool subscribed_for_incoming_messages_; | 93 bool subscribed_for_incoming_messages_; |
90 | 94 |
91 base::WeakPtrFactory<GCMInvalidationBridge> weak_factory_; | 95 base::WeakPtrFactory<GCMInvalidationBridge> weak_factory_; |
92 | 96 |
93 DISALLOW_COPY_AND_ASSIGN(GCMInvalidationBridge); | 97 DISALLOW_COPY_AND_ASSIGN(GCMInvalidationBridge); |
94 }; | 98 }; |
95 | 99 |
96 } // namespace invalidation | 100 } // namespace invalidation |
97 | 101 |
98 #endif // CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_ | 102 #endif // CHROME_BROWSER_INVALIDATION_GCM_INVALIDATION_BRIDGE_H_ |
OLD | NEW |