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 #include "components/gcm_driver/gcm_driver.h" | 5 #include "components/gcm_driver/gcm_driver.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "components/gcm_driver/gcm_app_handler.h" | 12 #include "components/gcm_driver/gcm_app_handler.h" |
12 | 13 |
13 namespace gcm { | 14 namespace gcm { |
14 | 15 |
15 namespace { | |
16 const size_t kMaxSenders = 100; | 16 const size_t kMaxSenders = 100; |
17 } // namespace | 17 |
18 // Directory in the GCM Store in which the encryption database will be stored. | |
19 const base::FilePath::CharType kEncryptionDirectoryName[] = | |
20 FILE_PATH_LITERAL("Encryption"); | |
18 | 21 |
19 InstanceIDHandler::InstanceIDHandler() { | 22 InstanceIDHandler::InstanceIDHandler() { |
20 } | 23 } |
21 | 24 |
22 InstanceIDHandler::~InstanceIDHandler() { | 25 InstanceIDHandler::~InstanceIDHandler() { |
23 } | 26 } |
24 | 27 |
25 void InstanceIDHandler::DeleteAllTokensForApp( | 28 void InstanceIDHandler::DeleteAllTokensForApp( |
26 const std::string& app_id, const DeleteTokenCallback& callback) { | 29 const std::string& app_id, const DeleteTokenCallback& callback) { |
27 DeleteToken(app_id, "*", "*", callback); | 30 DeleteToken(app_id, "*", "*", callback); |
28 } | 31 } |
29 | 32 |
30 GCMDriver::GCMDriver() : weak_ptr_factory_(this) { | 33 GCMDriver::GCMDriver( |
34 const base::FilePath& store_path, | |
35 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) | |
36 : weak_ptr_factory_(this) { | |
37 if (blocking_task_runner) { | |
jianli
2015/07/20 21:36:33
Please comment under what circumstance that blocki
Peter Beverloo
2015/07/21 14:11:30
Done.
| |
38 encryption_provider_.Init(store_path.Append(kEncryptionDirectoryName), | |
39 blocking_task_runner); | |
40 } | |
31 } | 41 } |
32 | 42 |
33 GCMDriver::~GCMDriver() { | 43 GCMDriver::~GCMDriver() { |
34 } | 44 } |
35 | 45 |
36 void GCMDriver::Register(const std::string& app_id, | 46 void GCMDriver::Register(const std::string& app_id, |
37 const std::vector<std::string>& sender_ids, | 47 const std::vector<std::string>& sender_ids, |
38 const RegisterCallback& callback) { | 48 const RegisterCallback& callback) { |
39 DCHECK(!app_id.empty()); | 49 DCHECK(!app_id.empty()); |
40 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders); | 50 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 if (send_callbacks_.find(key) != send_callbacks_.end()) { | 152 if (send_callbacks_.find(key) != send_callbacks_.end()) { |
143 callback.Run(message.id, GCMClient::INVALID_PARAMETER); | 153 callback.Run(message.id, GCMClient::INVALID_PARAMETER); |
144 return; | 154 return; |
145 } | 155 } |
146 | 156 |
147 send_callbacks_[key] = callback; | 157 send_callbacks_[key] = callback; |
148 | 158 |
149 SendImpl(app_id, receiver_id, message); | 159 SendImpl(app_id, receiver_id, message); |
150 } | 160 } |
151 | 161 |
162 void GCMDriver::GetPublicKey( | |
163 const std::string& app_id, | |
164 const GetPublicKeyCallback& callback) { | |
165 encryption_provider_.GetPublicKey(app_id, callback); | |
166 } | |
167 | |
152 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, | 168 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, |
153 const std::string& sender_id) { | 169 const std::string& sender_id) { |
154 NOTREACHED(); | 170 NOTREACHED(); |
155 } | 171 } |
156 | 172 |
157 void GCMDriver::RegisterFinished(const std::string& app_id, | 173 void GCMDriver::RegisterFinished(const std::string& app_id, |
158 const std::string& registration_id, | 174 const std::string& registration_id, |
159 GCMClient::Result result) { | 175 GCMClient::Result result) { |
160 std::map<std::string, RegisterCallback>::iterator callback_iter = | 176 std::map<std::string, RegisterCallback>::iterator callback_iter = |
161 register_callbacks_.find(app_id); | 177 register_callbacks_.find(app_id); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 GCMClient::Result result) { | 269 GCMClient::Result result) { |
254 // Invoke the original unregister callback. | 270 // Invoke the original unregister callback. |
255 unregister_callback.Run(result); | 271 unregister_callback.Run(result); |
256 | 272 |
257 // Trigger the pending registration. | 273 // Trigger the pending registration. |
258 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); | 274 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); |
259 RegisterImpl(app_id, normalized_sender_ids); | 275 RegisterImpl(app_id, normalized_sender_ids); |
260 } | 276 } |
261 | 277 |
262 } // namespace gcm | 278 } // namespace gcm |
OLD | NEW |