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