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_SERVICES_GCM_GCM_DRIVER_H_ | 5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_DRIVER_H_ |
6 #define CHROME_BROWSER_SERVICES_GCM_GCM_DRIVER_H_ | 6 #define CHROME_BROWSER_SERVICES_GCM_GCM_DRIVER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
17 #include "components/gcm_driver/default_gcm_app_handler.h" | 18 #include "components/gcm_driver/default_gcm_app_handler.h" |
18 #include "google_apis/gaia/identity_provider.h" | 19 #include "google_apis/gaia/identity_provider.h" |
19 #include "google_apis/gcm/gcm_client.h" | 20 #include "google_apis/gcm/gcm_client.h" |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 class FilePath; | 23 class FilePath; |
| 24 class SequencedTaskRunner; |
23 } | 25 } |
24 | 26 |
25 namespace extensions { | 27 namespace extensions { |
26 class ExtensionGCMAppHandlerTest; | 28 class ExtensionGCMAppHandlerTest; |
27 } | 29 } |
28 | 30 |
29 namespace net { | 31 namespace net { |
30 class URLRequestContextGetter; | 32 class URLRequestContextGetter; |
31 } | 33 } |
32 | 34 |
33 namespace gcm { | 35 namespace gcm { |
34 | 36 |
35 class GCMAppHandler; | 37 class GCMAppHandler; |
36 class GCMClientFactory; | 38 class GCMClientFactory; |
37 | 39 |
38 // A bridge between the GCM users in Chrome and the GCMClient layer. | 40 // A bridge between the GCM users in Chrome and the GCMClient layer. |
39 class GCMDriver : public IdentityProvider::Observer { | 41 class GCMDriver : public IdentityProvider::Observer { |
40 public: | 42 public: |
41 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; | 43 typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap; |
42 typedef base::Callback<void(const std::string& registration_id, | 44 typedef base::Callback<void(const std::string& registration_id, |
43 GCMClient::Result result)> RegisterCallback; | 45 GCMClient::Result result)> RegisterCallback; |
44 typedef base::Callback<void(const std::string& message_id, | 46 typedef base::Callback<void(const std::string& message_id, |
45 GCMClient::Result result)> SendCallback; | 47 GCMClient::Result result)> SendCallback; |
46 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; | 48 typedef base::Callback<void(GCMClient::Result result)> UnregisterCallback; |
47 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> | 49 typedef base::Callback<void(const GCMClient::GCMStatistics& stats)> |
48 GetGCMStatisticsCallback; | 50 GetGCMStatisticsCallback; |
49 | 51 |
50 GCMDriver(scoped_ptr<GCMClientFactory> gcm_client_factory, | 52 GCMDriver( |
51 scoped_ptr<IdentityProvider> identity_provider, | 53 scoped_ptr<GCMClientFactory> gcm_client_factory, |
52 const base::FilePath& store_path, | 54 scoped_ptr<IdentityProvider> identity_provider, |
53 const scoped_refptr<net::URLRequestContextGetter>& request_context); | 55 const base::FilePath& store_path, |
| 56 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 57 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
| 58 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
| 59 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
54 virtual ~GCMDriver(); | 60 virtual ~GCMDriver(); |
55 | 61 |
56 // Enables/disables GCM service. | 62 // Enables/disables GCM service. |
57 void Enable(); | 63 void Enable(); |
58 void Disable(); | 64 void Disable(); |
59 | 65 |
60 // This method must be called before destroying the GCMDriver. Once it has | 66 // This method must be called before destroying the GCMDriver. Once it has |
61 // been called, no other GCMDriver methods may be used. | 67 // been called, no other GCMDriver methods may be used. |
62 virtual void Shutdown(); | 68 virtual void Shutdown(); |
63 | 69 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 bool gcm_enabled_; | 186 bool gcm_enabled_; |
181 | 187 |
182 // Flag to indicate if GCMClient is ready. | 188 // Flag to indicate if GCMClient is ready. |
183 bool gcm_client_ready_; | 189 bool gcm_client_ready_; |
184 | 190 |
185 // The account ID that this service is responsible for. Empty when the service | 191 // The account ID that this service is responsible for. Empty when the service |
186 // is not running. | 192 // is not running. |
187 std::string account_id_; | 193 std::string account_id_; |
188 | 194 |
189 scoped_ptr<IdentityProvider> identity_provider_; | 195 scoped_ptr<IdentityProvider> identity_provider_; |
| 196 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
| 197 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
190 | 198 |
191 scoped_ptr<DelayedTaskController> delayed_task_controller_; | 199 scoped_ptr<DelayedTaskController> delayed_task_controller_; |
192 | 200 |
193 // For all the work occurring on the IO thread. Must be destroyed on the IO | 201 // For all the work occurring on the IO thread. Must be destroyed on the IO |
194 // thread. | 202 // thread. |
195 scoped_ptr<IOWorker> io_worker_; | 203 scoped_ptr<IOWorker> io_worker_; |
196 | 204 |
197 // App handler map (from app_id to handler pointer). | 205 // App handler map (from app_id to handler pointer). |
198 // The handler is not owned. | 206 // The handler is not owned. |
199 GCMAppHandlerMap app_handlers_; | 207 GCMAppHandlerMap app_handlers_; |
(...skipping 15 matching lines...) Expand all Loading... |
215 | 223 |
216 // Used to pass a weak pointer to the IO worker. | 224 // Used to pass a weak pointer to the IO worker. |
217 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; | 225 base::WeakPtrFactory<GCMDriver> weak_ptr_factory_; |
218 | 226 |
219 DISALLOW_COPY_AND_ASSIGN(GCMDriver); | 227 DISALLOW_COPY_AND_ASSIGN(GCMDriver); |
220 }; | 228 }; |
221 | 229 |
222 } // namespace gcm | 230 } // namespace gcm |
223 | 231 |
224 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_DRIVER_H_ | 232 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_DRIVER_H_ |
OLD | NEW |