Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: components/gcm_driver/gcm_driver_desktop.h

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass InstanceID to requests Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/tuple.h"
18 #include "components/gcm_driver/gcm_channel_status_syncer.h" 19 #include "components/gcm_driver/gcm_channel_status_syncer.h"
19 #include "components/gcm_driver/gcm_client.h" 20 #include "components/gcm_driver/gcm_client.h"
20 #include "components/gcm_driver/gcm_connection_observer.h" 21 #include "components/gcm_driver/gcm_connection_observer.h"
21 #include "components/gcm_driver/gcm_driver.h" 22 #include "components/gcm_driver/gcm_driver.h"
22 23
23 class PrefService; 24 class PrefService;
24 25
25 namespace base { 26 namespace base {
26 class FilePath; 27 class FilePath;
27 class SequencedTaskRunner; 28 class SequencedTaskRunner;
28 } 29 }
29 30
30 namespace extensions { 31 namespace extensions {
31 class ExtensionGCMAppHandlerTest; 32 class ExtensionGCMAppHandlerTest;
32 } 33 }
33 34
34 namespace net { 35 namespace net {
35 class URLRequestContextGetter; 36 class URLRequestContextGetter;
36 } 37 }
37 38
38 namespace gcm { 39 namespace gcm {
39 40
40 class GCMAccountMapper; 41 class GCMAccountMapper;
41 class GCMAppHandler; 42 class GCMAppHandler;
42 class GCMClientFactory; 43 class GCMClientFactory;
43 class GCMDelayedTaskController; 44 class GCMDelayedTaskController;
44 45
45 // GCMDriver implementation for desktop and Chrome OS, using GCMClient. 46 // GCMDriver implementation for desktop and Chrome OS, using GCMClient.
46 class GCMDriverDesktop : public GCMDriver, 47 class GCMDriverDesktop : public GCMDriver,
47 public InstanceIDStore { 48 public InstanceIDHandler {
48 public: 49 public:
49 GCMDriverDesktop( 50 GCMDriverDesktop(
50 scoped_ptr<GCMClientFactory> gcm_client_factory, 51 scoped_ptr<GCMClientFactory> gcm_client_factory,
51 const GCMClient::ChromeBuildInfo& chrome_build_info, 52 const GCMClient::ChromeBuildInfo& chrome_build_info,
52 const std::string& channel_status_request_url, 53 const std::string& channel_status_request_url,
53 const std::string& user_agent, 54 const std::string& user_agent,
54 PrefService* prefs, 55 PrefService* prefs,
55 const base::FilePath& store_path, 56 const base::FilePath& store_path,
56 const scoped_refptr<net::URLRequestContextGetter>& request_context, 57 const scoped_refptr<net::URLRequestContextGetter>& request_context,
57 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 58 const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
(...skipping 19 matching lines...) Expand all
77 bool clear_logs) override; 78 bool clear_logs) override;
78 void SetGCMRecording(const GetGCMStatisticsCallback& callback, 79 void SetGCMRecording(const GetGCMStatisticsCallback& callback,
79 bool recording) override; 80 bool recording) override;
80 void SetAccountTokens( 81 void SetAccountTokens(
81 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) override; 82 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) override;
82 void UpdateAccountMapping(const AccountMapping& account_mapping) override; 83 void UpdateAccountMapping(const AccountMapping& account_mapping) override;
83 void RemoveAccountMapping(const std::string& account_id) override; 84 void RemoveAccountMapping(const std::string& account_id) override;
84 base::Time GetLastTokenFetchTime() override; 85 base::Time GetLastTokenFetchTime() override;
85 void SetLastTokenFetchTime(const base::Time& time) override; 86 void SetLastTokenFetchTime(const base::Time& time) override;
86 void WakeFromSuspendForHeartbeat(bool wake) override; 87 void WakeFromSuspendForHeartbeat(bool wake) override;
87 InstanceIDStore* GetInstanceIDStore() override; 88 InstanceIDHandler* GetInstanceIDHandler() override;
88 89
89 // InstanceIDStore overrides: 90 // InstanceIDHandler overrides:
91 void GetToken(const std::string& app_id,
92 const std::string& authorized_entity,
93 const std::string& scope,
94 const std::map<std::string, std::string>& options,
95 const GetTokenCallback& callback) override;
96 void DeleteToken(const std::string& app_id,
97 const std::string& authorized_entity,
98 const std::string& scope,
99 const DeleteTokenCallback& callback) override;
90 void AddInstanceIDData(const std::string& app_id, 100 void AddInstanceIDData(const std::string& app_id,
91 const std::string& instance_id_data) override; 101 const std::string& instance_id,
102 const std::string& extra_data) override;
92 void RemoveInstanceIDData(const std::string& app_id) override; 103 void RemoveInstanceIDData(const std::string& app_id) override;
93 void GetInstanceIDData(const std::string& app_id, 104 void GetInstanceIDData(const std::string& app_id,
94 const GetInstanceIDDataCallback& callback) override; 105 const GetInstanceIDDataCallback& callback) override;
95 106
96 // Exposed for testing purpose. 107 // Exposed for testing purpose.
97 bool gcm_enabled() const { return gcm_enabled_; } 108 bool gcm_enabled() const { return gcm_enabled_; }
98 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() { 109 GCMChannelStatusSyncer* gcm_channel_status_syncer_for_testing() {
99 return gcm_channel_status_syncer_.get(); 110 return gcm_channel_status_syncer_.get();
100 } 111 }
101 112
102 protected: 113 protected:
103 // GCMDriver implementation: 114 // GCMDriver implementation:
104 GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) override; 115 GCMClient::Result EnsureStarted(GCMClient::StartMode start_mode) override;
105 void RegisterImpl(const std::string& app_id, 116 void RegisterImpl(const std::string& app_id,
106 const std::vector<std::string>& sender_ids) override; 117 const std::vector<std::string>& sender_ids) override;
107 void UnregisterImpl(const std::string& app_id) override; 118 void UnregisterImpl(const std::string& app_id) override;
108 void SendImpl(const std::string& app_id, 119 void SendImpl(const std::string& app_id,
109 const std::string& receiver_id, 120 const std::string& receiver_id,
110 const GCMClient::OutgoingMessage& message) override; 121 const GCMClient::OutgoingMessage& message) override;
111 122
112 private: 123 private:
113 class IOWorker; 124 class IOWorker;
114 125
126 typedef Tuple<std::string, std::string, std::string> TokenTuple;
127 struct TokenTupleComparer {
128 bool operator()(const TokenTuple& a, const TokenTuple& b) const;
129 };
130
115 // Stops the GCM service. It can be restarted by calling EnsureStarted again. 131 // Stops the GCM service. It can be restarted by calling EnsureStarted again.
116 void Stop(); 132 void Stop();
117 133
118 // Remove cached data when GCM service is stopped. 134 // Remove cached data when GCM service is stopped.
119 void RemoveCachedData(); 135 void RemoveCachedData();
120 136
121 void DoRegister(const std::string& app_id, 137 void DoRegister(const std::string& app_id,
122 const std::vector<std::string>& sender_ids); 138 const std::vector<std::string>& sender_ids);
123 void DoUnregister(const std::string& app_id); 139 void DoUnregister(const std::string& app_id);
124 void DoSend(const std::string& app_id, 140 void DoSend(const std::string& app_id,
125 const std::string& receiver_id, 141 const std::string& receiver_id,
126 const GCMClient::OutgoingMessage& message); 142 const GCMClient::OutgoingMessage& message);
127 143
128 // Callbacks posted from IO thread to UI thread. 144 // Callbacks posted from IO thread to UI thread.
129 void MessageReceived(const std::string& app_id, 145 void MessageReceived(const std::string& app_id,
130 const GCMClient::IncomingMessage& message); 146 const GCMClient::IncomingMessage& message);
131 void MessagesDeleted(const std::string& app_id); 147 void MessagesDeleted(const std::string& app_id);
132 void MessageSendError(const std::string& app_id, 148 void MessageSendError(const std::string& app_id,
133 const GCMClient::SendErrorDetails& send_error_details); 149 const GCMClient::SendErrorDetails& send_error_details);
134 void SendAcknowledged(const std::string& app_id, 150 void SendAcknowledged(const std::string& app_id,
135 const std::string& message_id); 151 const std::string& message_id);
136 void GCMClientReady(const std::vector<AccountMapping>& account_mappings, 152 void GCMClientReady(const std::vector<AccountMapping>& account_mappings,
137 const base::Time& last_token_fetch_time); 153 const base::Time& last_token_fetch_time);
138 void OnConnected(const net::IPEndPoint& ip_endpoint); 154 void OnConnected(const net::IPEndPoint& ip_endpoint);
139 void OnDisconnected(); 155 void OnDisconnected();
140 156
141 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats); 157 void GetGCMStatisticsFinished(const GCMClient::GCMStatistics& stats);
142 void GetInstanceIDDataFinished(const std::string& app_id, 158 void GetInstanceIDDataFinished(const std::string& app_id,
143 const std::string& instance_id_data); 159 const std::string& instance_id,
160 const std::string& extra_data);
161 void GetTokenFinished(const std::string& app_id,
162 const std::string& authorized_entity,
163 const std::string& scope,
164 const std::string& token,
165 GCMClient::Result result);
166 void DeleteTokenFinished(const std::string& app_id,
167 const std::string& authorized_entity,
168 const std::string& scope,
169 GCMClient::Result result);
144 170
145 scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_; 171 scoped_ptr<GCMChannelStatusSyncer> gcm_channel_status_syncer_;
146 172
147 // Flag to indicate whether the user is signed in to a GAIA account. 173 // Flag to indicate whether the user is signed in to a GAIA account.
148 bool signed_in_; 174 bool signed_in_;
149 175
150 // Flag to indicate if GCM is started. 176 // Flag to indicate if GCM is started.
151 bool gcm_started_; 177 bool gcm_started_;
152 178
153 // Flag to indicate if GCM is enabled. 179 // Flag to indicate if GCM is enabled.
(...skipping 26 matching lines...) Expand all
180 // thread. 206 // thread.
181 scoped_ptr<IOWorker> io_worker_; 207 scoped_ptr<IOWorker> io_worker_;
182 208
183 // Callback for GetGCMStatistics. 209 // Callback for GetGCMStatistics.
184 GetGCMStatisticsCallback request_gcm_statistics_callback_; 210 GetGCMStatisticsCallback request_gcm_statistics_callback_;
185 211
186 // Callbacks for GetInstanceIDData. 212 // Callbacks for GetInstanceIDData.
187 std::map<std::string, GetInstanceIDDataCallback> 213 std::map<std::string, GetInstanceIDDataCallback>
188 get_instance_id_data_callbacks_; 214 get_instance_id_data_callbacks_;
189 215
216 // Callbacks for GetToken/DeleteToken.
217 std::map<TokenTuple, GetTokenCallback, TokenTupleComparer>
218 get_token_callbacks_;
219 std::map<TokenTuple, DeleteTokenCallback, TokenTupleComparer>
220 delete_token_callbacks_;
221
190 // Used to pass a weak pointer to the IO worker. 222 // Used to pass a weak pointer to the IO worker.
191 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_; 223 base::WeakPtrFactory<GCMDriverDesktop> weak_ptr_factory_;
192 224
193 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop); 225 DISALLOW_COPY_AND_ASSIGN(GCMDriverDesktop);
194 }; 226 };
195 227
196 } // namespace gcm 228 } // namespace gcm
197 229
198 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_ 230 #endif // COMPONENTS_GCM_DRIVER_GCM_DRIVER_DESKTOP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698