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 "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "components/gcm_driver/gcm_channel_status_syncer.h" |
18 #include "components/gcm_driver/gcm_client.h" | 19 #include "components/gcm_driver/gcm_client.h" |
19 #include "components/gcm_driver/gcm_connection_observer.h" | 20 #include "components/gcm_driver/gcm_connection_observer.h" |
20 #include "components/gcm_driver/gcm_driver.h" | 21 #include "components/gcm_driver/gcm_driver.h" |
21 | 22 |
| 23 class PrefService; |
| 24 |
22 namespace base { | 25 namespace base { |
23 class FilePath; | 26 class FilePath; |
24 class SequencedTaskRunner; | 27 class SequencedTaskRunner; |
25 } | 28 } |
26 | 29 |
27 namespace extensions { | 30 namespace extensions { |
28 class ExtensionGCMAppHandlerTest; | 31 class ExtensionGCMAppHandlerTest; |
29 } | 32 } |
30 | 33 |
31 namespace net { | 34 namespace net { |
32 class URLRequestContextGetter; | 35 class URLRequestContextGetter; |
33 } | 36 } |
34 | 37 |
35 namespace gcm { | 38 namespace gcm { |
36 | 39 |
37 class GCMAppHandler; | 40 class GCMAppHandler; |
38 class GCMClientFactory; | 41 class GCMClientFactory; |
39 class GCMDelayedTaskController; | 42 class GCMDelayedTaskController; |
40 | 43 |
41 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. | 44 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. |
42 class GCMDriverDesktop : public GCMDriver { | 45 class GCMDriverDesktop : public GCMDriver { |
43 public: | 46 public: |
44 GCMDriverDesktop( | 47 GCMDriverDesktop( |
45 scoped_ptr<GCMClientFactory> gcm_client_factory, | 48 scoped_ptr<GCMClientFactory> gcm_client_factory, |
46 const GCMClient::ChromeBuildInfo& chrome_build_info, | 49 const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 50 PrefService* prefs, |
47 const base::FilePath& store_path, | 51 const base::FilePath& store_path, |
48 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 52 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
49 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 53 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
50 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 54 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
51 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); | 55 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner); |
52 virtual ~GCMDriverDesktop(); | 56 virtual ~GCMDriverDesktop(); |
53 | 57 |
54 // GCMDriver overrides: | 58 // GCMDriver overrides: |
55 virtual void Shutdown() OVERRIDE; | 59 virtual void Shutdown() OVERRIDE; |
56 virtual void OnSignedIn() OVERRIDE; | 60 virtual void OnSignedIn() OVERRIDE; |
(...skipping 19 matching lines...) Expand all Loading... |
76 | 80 |
77 // GCMDriverDesktop specific implementation. | 81 // GCMDriverDesktop specific implementation. |
78 // Sets a list of accounts with OAuth2 tokens for the next checkin. | 82 // Sets a list of accounts with OAuth2 tokens for the next checkin. |
79 // |account_tokens| maps email addresses to OAuth2 access tokens. | 83 // |account_tokens| maps email addresses to OAuth2 access tokens. |
80 // |account_removed| indicates that an account has been removed since the | 84 // |account_removed| indicates that an account has been removed since the |
81 // last time the callback was called, which triggers an immediate checkin, | 85 // last time the callback was called, which triggers an immediate checkin, |
82 // to ensure that association between device and account is removed. | 86 // to ensure that association between device and account is removed. |
83 void SetAccountsForCheckin( | 87 void SetAccountsForCheckin( |
84 const std::map<std::string, std::string>& account_tokens); | 88 const std::map<std::string, std::string>& account_tokens); |
85 | 89 |
| 90 // Exposed for testing purpose. |
| 91 bool gcm_enabled() const { return gcm_enabled_; } |
| 92 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() { |
| 93 return &gcm_channel_status_syncer_; |
| 94 } |
| 95 |
86 protected: | 96 protected: |
87 // GCMDriver implementation: | 97 // GCMDriver implementation: |
88 virtual GCMClient::Result EnsureStarted() OVERRIDE; | 98 virtual GCMClient::Result EnsureStarted() OVERRIDE; |
89 virtual void RegisterImpl( | 99 virtual void RegisterImpl( |
90 const std::string& app_id, | 100 const std::string& app_id, |
91 const std::vector<std::string>& sender_ids) OVERRIDE; | 101 const std::vector<std::string>& sender_ids) OVERRIDE; |
92 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE; | 102 virtual void UnregisterImpl(const std::string& app_id) OVERRIDE; |
93 virtual void SendImpl(const std::string& app_id, | 103 virtual void SendImpl(const std::string& app_id, |
94 const std::string& receiver_id, | 104 const std::string& receiver_id, |
95 const GCMClient::OutgoingMessage& message) OVERRIDE; | 105 const GCMClient::OutgoingMessage& message) OVERRIDE; |
(...skipping 21 matching lines...) Expand all Loading... |
117 void MessageSendError(const std::string& app_id, | 127 void MessageSendError(const std::string& app_id, |
118 const GCMClient::SendErrorDetails& send_error_details); | 128 const GCMClient::SendErrorDetails& send_error_details); |
119 void SendAcknowledged(const std::string& app_id, | 129 void SendAcknowledged(const std::string& app_id, |
120 const std::string& message_id); | 130 const std::string& message_id); |
121 void GCMClientReady(); | 131 void GCMClientReady(); |
122 void OnConnected(const net::IPEndPoint& ip_endpoint); | 132 void OnConnected(const net::IPEndPoint& ip_endpoint); |
123 void OnDisconnected(); | 133 void OnDisconnected(); |
124 | 134 |
125 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); | 135 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); |
126 | 136 |
| 137 GCMChannelStatusSyncer gcm_channel_status_syncer_; |
| 138 |
127 // Flag to indicate whether the user is signed in to a GAIA account. | 139 // Flag to indicate whether the user is signed in to a GAIA account. |
128 // TODO(jianli): To be removed when sign-in enforcement is dropped. | 140 // TODO(jianli): To be removed when sign-in enforcement is dropped. |
129 bool signed_in_; | 141 bool signed_in_; |
130 | 142 |
131 // Flag to indicate if GCM is started. | 143 // Flag to indicate if GCM is started. |
132 bool gcm_started_; | 144 bool gcm_started_; |
133 | 145 |
134 // Flag to indicate if GCM is enabled. | 146 // Flag to indicate if GCM is enabled. |
| 147 // TODO(jianli): Removed when we switch completely to support all users. |
135 bool gcm_enabled_; | 148 bool gcm_enabled_; |
136 | 149 |
137 // Flag to indicate the last known state of the GCM client. Because this | 150 // Flag to indicate the last known state of the GCM client. Because this |
138 // flag lives on the UI thread, while the GCM client lives on the IO thread, | 151 // flag lives on the UI thread, while the GCM client lives on the IO thread, |
139 // it may be out of date while connection changes are happening. | 152 // it may be out of date while connection changes are happening. |
140 bool connected_; | 153 bool connected_; |
141 | 154 |
142 // List of observers to notify when connection state changes. | 155 // List of observers to notify when connection state changes. |
143 // Makes sure list is empty on destruction. | 156 // Makes sure list is empty on destruction. |
144 ObserverList<GCMConnectionObserver, true> connection_observer_list_; | 157 ObserverList<GCMConnectionObserver, true> connection_observer_list_; |
(...skipping 12 matching lines...) Expand all Loading... |
157 | 170 |
158 // Used to pass a weak pointer to the IO worker. | 171 // Used to pass a weak pointer to the IO worker. |
159 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; | 172 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; |
160 | 173 |
161 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); | 174 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); |
162 }; | 175 }; |
163 | 176 |
164 } // namespace gcm | 177 } // namespace gcm |
165 | 178 |
166 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ | 179 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ |
OLD | NEW |