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 COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 6 #define COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_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/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "components/gcm_driver/gcm_client.h" | 17 #include "components/gcm_driver/gcm_client.h" |
18 #include "components/gcm_driver/gcm_driver.h" | 18 #include "components/gcm_driver/gcm_driver.h" |
19 #include "google_apis/gaia/identity_provider.h" | |
20 | 19 |
21 namespace base { | 20 namespace base { |
22 class FilePath; | 21 class FilePath; |
23 class SequencedTaskRunner; | 22 class SequencedTaskRunner; |
24 } | 23 } |
25 | 24 |
26 namespace extensions { | 25 namespace extensions { |
27 class ExtensionGCMAppHandlerTest; | 26 class ExtensionGCMAppHandlerTest; |
28 } | 27 } |
29 | 28 |
30 namespace net { | 29 namespace net { |
31 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
32 } | 31 } |
33 | 32 |
34 namespace gcm { | 33 namespace gcm { |
35 | 34 |
36 class GCMAppHandler; | 35 class GCMAppHandler; |
37 class GCMClientFactory; | 36 class GCMClientFactory; |
38 | 37 |
39 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. | 38 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. |
40 class GCMDriverDesktop : public GCMDriver, public IdentityProvider::Observer { | 39 class GCMDriverDesktop : public GCMDriver { |
41 public: | 40 public: |
42 GCMDriverDesktop( | 41 GCMDriverDesktop( |
43 scoped_ptr<GCMClientFactory> gcm_client_factory, | 42 scoped_ptr<GCMClientFactory> gcm_client_factory, |
44 scoped_ptr<IdentityProvider> identity_provider, | |
45 const GCMClient::ChromeBuildInfo& chrome_build_info, | 43 const GCMClient::ChromeBuildInfo& chrome_build_info, |
46 const base::FilePath& store_path, | 44 const base::FilePath& store_path, |
47 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 45 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
48 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 46 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
49 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 47 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
50 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); | 48 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
51 virtual ~GCMDriverDesktop(); | 49 virtual ~GCMDriverDesktop(); |
52 | 50 |
53 // IdentityProvider::Observer implementation: | |
54 virtual void OnActiveAccountLogin() OVERRIDE; | |
55 virtual void OnActiveAccountLogout() OVERRIDE; | |
56 | |
57 // GCMDriver overrides: | 51 // GCMDriver overrides: |
58 virtual void Shutdown() OVERRIDE; | 52 virtual void Shutdown() OVERRIDE; |
53 virtual void SignIn() OVERRIDE; | |
54 virtual void Purge() OVERRIDE; | |
59 virtual void AddAppHandler(const std::string& app_id, | 55 virtual void AddAppHandler(const std::string& app_id, |
60 GCMAppHandler* handler) OVERRIDE; | 56 GCMAppHandler* handler) OVERRIDE; |
61 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; | 57 virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE; |
62 | 58 |
63 // GCMDriver implementation: | 59 // GCMDriver implementation: |
64 virtual void Enable() OVERRIDE; | 60 virtual void Enable() OVERRIDE; |
65 virtual void Disable() OVERRIDE; | 61 virtual void Disable() OVERRIDE; |
66 virtual GCMClient* GetGCMClientForTesting() const OVERRIDE; | 62 virtual GCMClient* GetGCMClientForTesting() const OVERRIDE; |
67 virtual bool IsStarted() const OVERRIDE; | 63 virtual bool IsStarted() const OVERRIDE; |
68 virtual bool IsGCMClientReady() const OVERRIDE; | 64 virtual bool IsGCMClientReady() const OVERRIDE; |
69 virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback, | 65 virtual void GetGCMStatistics(const GetGCMStatisticsCallback& callback, |
70 bool clear_logs) OVERRIDE; | 66 bool clear_logs) OVERRIDE; |
71 virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback, | 67 virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback, |
72 bool recording) OVERRIDE; | 68 bool recording) OVERRIDE; |
73 virtual std::string SignedInUserName() const OVERRIDE; | |
74 | 69 |
75 protected: | 70 protected: |
76 // GCMDriver implementation: | 71 // GCMDriver implementation: |
77 virtual GCMClient::Result EnsureStarted() OVERRIDE; | 72 virtual GCMClient::Result EnsureStarted() OVERRIDE; |
78 virtual void RegisterImpl( | 73 virtual void RegisterImpl( |
79 const std::string& app_id, | 74 const std::string& app_id, |
80 const std::vector<std::string>& sender_ids) OVERRIDE; | 75 const std::vector<std::string>& sender_ids) OVERRIDE; |
81 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE; | 76 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE; |
82 virtual void SendImpl(const std::string& app_id, | 77 virtual void SendImpl(const std::string& app_id, |
83 const std::string& receiver_id, | 78 const std::string& receiver_id, |
84 const GCMClient::OutgoingMessage& message) OVERRIDE; | 79 const GCMClient::OutgoingMessage& message) OVERRIDE; |
85 | 80 |
86 private: | 81 private: |
87 class DelayedTaskController; | 82 class DelayedTaskController; |
88 class IOWorker; | 83 class IOWorker; |
89 | 84 |
90 // Stops the GCM service. It can be restarted by calling EnsureStarted again. | 85 // Stops the GCM service. It can be restarted by calling EnsureStarted again. |
91 void Stop(); | 86 void Stop(); |
92 | 87 |
93 // Remove cached data when GCM service is stopped. | 88 // Remove cached data when GCM service is stopped. |
94 void RemoveCachedData(); | 89 void RemoveCachedData(); |
95 | 90 |
96 // Checks out of GCM and erases any cached and persisted data. | |
97 void CheckOut(); | |
98 | |
99 void DoRegister(const std::string& app_id, | 91 void DoRegister(const std::string& app_id, |
100 const std::vector<std::string>& sender_ids); | 92 const std::vector<std::string>& sender_ids); |
101 void DoUnregister(const std::string& app_id); | 93 void DoUnregister(const std::string& app_id); |
102 void DoSend(const std::string& app_id, | 94 void DoSend(const std::string& app_id, |
103 const std::string& receiver_id, | 95 const std::string& receiver_id, |
104 const GCMClient::OutgoingMessage& message); | 96 const GCMClient::OutgoingMessage& message); |
105 | 97 |
106 // Callbacks posted from IO thread to UI thread. | 98 // Callbacks posted from IO thread to UI thread. |
107 void MessageReceived(const std::string& app_id, | 99 void MessageReceived(const std::string& app_id, |
108 const GCMClient::IncomingMessage& message); | 100 const GCMClient::IncomingMessage& message); |
109 void MessagesDeleted(const std::string& app_id); | 101 void MessagesDeleted(const std::string& app_id); |
110 void MessageSendError(const std::string& app_id, | 102 void MessageSendError(const std::string& app_id, |
111 const GCMClient::SendErrorDetails& send_error_details); | 103 const GCMClient::SendErrorDetails& send_error_details); |
112 void GCMClientReady(); | 104 void GCMClientReady(); |
113 | 105 |
114 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); | 106 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); |
115 | 107 |
108 // Flag to indicate if the sign-in is met. | |
bartfab (slow)
2014/06/13 11:27:21
Nit: That sentence sounds odd. What does it mean f
jianli
2014/06/13 18:04:49
Done.
| |
109 // TODO(jianli): to be removed when sign-in enforcement is dropped. | |
bartfab (slow)
2014/06/13 11:27:21
Nit: s/to/To/
jianli
2014/06/13 18:04:49
Done.
| |
110 bool signed_in_; | |
111 | |
112 // Flag to indicate if GCM is started. | |
113 bool gcm_started_; | |
114 | |
116 // Flag to indicate if GCM is enabled. | 115 // Flag to indicate if GCM is enabled. |
117 bool gcm_enabled_; | 116 bool gcm_enabled_; |
118 | 117 |
119 // Flag to indicate if GCMClient is ready. | 118 // Flag to indicate if GCMClient is ready. |
120 bool gcm_client_ready_; | 119 bool gcm_client_ready_; |
121 | 120 |
122 // The account ID that this service is responsible for. Empty when the service | |
123 // is not running. | |
124 std::string account_id_; | |
125 | |
126 scoped_ptr<IdentityProvider> identity_provider_; | |
127 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 121 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
128 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 122 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
129 | 123 |
130 scoped_ptr<DelayedTaskController> delayed_task_controller_; | 124 scoped_ptr<DelayedTaskController> delayed_task_controller_; |
131 | 125 |
132 // For all the work occurring on the IO thread. Must be destroyed on the IO | 126 // For all the work occurring on the IO thread. Must be destroyed on the IO |
133 // thread. | 127 // thread. |
134 scoped_ptr<IOWorker> io_worker_; | 128 scoped_ptr<IOWorker> io_worker_; |
135 | 129 |
136 // Callback for GetGCMStatistics. | 130 // Callback for GetGCMStatistics. |
137 GetGCMStatisticsCallback request_gcm_statistics_callback_; | 131 GetGCMStatisticsCallback request_gcm_statistics_callback_; |
138 | 132 |
139 // Used to pass a weak pointer to the IO worker. | 133 // Used to pass a weak pointer to the IO worker. |
140 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; | 134 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; |
141 | 135 |
142 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); | 136 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); |
143 }; | 137 }; |
144 | 138 |
145 } // namespace gcm | 139 } // namespace gcm |
146 | 140 |
147 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 141 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
OLD | NEW |