| 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 // The |blocking_task_runner| can be NULL for tests that do not need the |
| 38 // encryption capabilities of the GCMDriver class. |
| 39 if (blocking_task_runner) { |
| 40 DCHECK(!store_path.empty()); |
| 41 encryption_provider_.Init(store_path.Append(kEncryptionDirectoryName), |
| 42 blocking_task_runner); |
| 43 } |
| 31 } | 44 } |
| 32 | 45 |
| 33 GCMDriver::~GCMDriver() { | 46 GCMDriver::~GCMDriver() { |
| 34 } | 47 } |
| 35 | 48 |
| 36 void GCMDriver::Register(const std::string& app_id, | 49 void GCMDriver::Register(const std::string& app_id, |
| 37 const std::vector<std::string>& sender_ids, | 50 const std::vector<std::string>& sender_ids, |
| 38 const RegisterCallback& callback) { | 51 const RegisterCallback& callback) { |
| 39 DCHECK(!app_id.empty()); | 52 DCHECK(!app_id.empty()); |
| 40 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders); | 53 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()) { | 155 if (send_callbacks_.find(key) != send_callbacks_.end()) { |
| 143 callback.Run(message.id, GCMClient::INVALID_PARAMETER); | 156 callback.Run(message.id, GCMClient::INVALID_PARAMETER); |
| 144 return; | 157 return; |
| 145 } | 158 } |
| 146 | 159 |
| 147 send_callbacks_[key] = callback; | 160 send_callbacks_[key] = callback; |
| 148 | 161 |
| 149 SendImpl(app_id, receiver_id, message); | 162 SendImpl(app_id, receiver_id, message); |
| 150 } | 163 } |
| 151 | 164 |
| 165 void GCMDriver::GetPublicKey( |
| 166 const std::string& app_id, |
| 167 const GetPublicKeyCallback& callback) { |
| 168 encryption_provider_.GetPublicKey(app_id, callback); |
| 169 } |
| 170 |
| 152 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, | 171 void GCMDriver::UnregisterWithSenderIdImpl(const std::string& app_id, |
| 153 const std::string& sender_id) { | 172 const std::string& sender_id) { |
| 154 NOTREACHED(); | 173 NOTREACHED(); |
| 155 } | 174 } |
| 156 | 175 |
| 157 void GCMDriver::RegisterFinished(const std::string& app_id, | 176 void GCMDriver::RegisterFinished(const std::string& app_id, |
| 158 const std::string& registration_id, | 177 const std::string& registration_id, |
| 159 GCMClient::Result result) { | 178 GCMClient::Result result) { |
| 160 std::map<std::string, RegisterCallback>::iterator callback_iter = | 179 std::map<std::string, RegisterCallback>::iterator callback_iter = |
| 161 register_callbacks_.find(app_id); | 180 register_callbacks_.find(app_id); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 GCMClient::Result result) { | 272 GCMClient::Result result) { |
| 254 // Invoke the original unregister callback. | 273 // Invoke the original unregister callback. |
| 255 unregister_callback.Run(result); | 274 unregister_callback.Run(result); |
| 256 | 275 |
| 257 // Trigger the pending registration. | 276 // Trigger the pending registration. |
| 258 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); | 277 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); |
| 259 RegisterImpl(app_id, normalized_sender_ids); | 278 RegisterImpl(app_id, normalized_sender_ids); |
| 260 } | 279 } |
| 261 | 280 |
| 262 } // namespace gcm | 281 } // namespace gcm |
| OLD | NEW |