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 "google_apis/gcm/engine/gcm_store_impl.h" | 5 #include "google_apis/gcm/engine/gcm_store_impl.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
19 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
20 #include "components/encryptor/encryptor.h" | 20 #include "components/encryptor/os_crypt.h" |
21 #include "google_apis/gcm/base/mcs_message.h" | 21 #include "google_apis/gcm/base/mcs_message.h" |
22 #include "google_apis/gcm/base/mcs_util.h" | 22 #include "google_apis/gcm/base/mcs_util.h" |
23 #include "google_apis/gcm/protocol/mcs.pb.h" | 23 #include "google_apis/gcm/protocol/mcs.pb.h" |
24 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 24 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
25 | 25 |
26 namespace gcm { | 26 namespace gcm { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // Limit to the number of outstanding messages per app. | 30 // Limit to the number of outstanding messages per app. |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 if (!db_.get()) { | 234 if (!db_.get()) { |
235 LOG(ERROR) << "GCMStore db doesn't exist."; | 235 LOG(ERROR) << "GCMStore db doesn't exist."; |
236 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, false)); | 236 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, false)); |
237 return; | 237 return; |
238 } | 238 } |
239 | 239 |
240 leveldb::WriteOptions write_options; | 240 leveldb::WriteOptions write_options; |
241 write_options.sync = true; | 241 write_options.sync = true; |
242 | 242 |
243 std::string encrypted_token; | 243 std::string encrypted_token; |
244 Encryptor::EncryptString(base::Uint64ToString(device_security_token), | 244 OSCrypt::EncryptString(base::Uint64ToString(device_security_token), |
245 &encrypted_token); | 245 &encrypted_token); |
246 std::string android_id_str = base::Uint64ToString(device_android_id); | 246 std::string android_id_str = base::Uint64ToString(device_android_id); |
247 leveldb::Status s = | 247 leveldb::Status s = |
248 db_->Put(write_options, | 248 db_->Put(write_options, |
249 MakeSlice(kDeviceAIDKey), | 249 MakeSlice(kDeviceAIDKey), |
250 MakeSlice(android_id_str)); | 250 MakeSlice(android_id_str)); |
251 if (s.ok()) { | 251 if (s.ok()) { |
252 s = db_->Put( | 252 s = db_->Put( |
253 write_options, MakeSlice(kDeviceTokenKey), MakeSlice(encrypted_token)); | 253 write_options, MakeSlice(kDeviceTokenKey), MakeSlice(encrypted_token)); |
254 } | 254 } |
255 if (s.ok()) { | 255 if (s.ok()) { |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 if (s.ok()) { | 480 if (s.ok()) { |
481 if (!base::StringToUint64(result, android_id)) { | 481 if (!base::StringToUint64(result, android_id)) { |
482 LOG(ERROR) << "Failed to restore device id."; | 482 LOG(ERROR) << "Failed to restore device id."; |
483 return false; | 483 return false; |
484 } | 484 } |
485 result.clear(); | 485 result.clear(); |
486 s = db_->Get(read_options, MakeSlice(kDeviceTokenKey), &result); | 486 s = db_->Get(read_options, MakeSlice(kDeviceTokenKey), &result); |
487 } | 487 } |
488 if (s.ok()) { | 488 if (s.ok()) { |
489 std::string decrypted_token; | 489 std::string decrypted_token; |
490 Encryptor::DecryptString(result, &decrypted_token); | 490 OSCrypt::DecryptString(result, &decrypted_token); |
491 if (!base::StringToUint64(decrypted_token, security_token)) { | 491 if (!base::StringToUint64(decrypted_token, security_token)) { |
492 LOG(ERROR) << "Failed to restore security token."; | 492 LOG(ERROR) << "Failed to restore security token."; |
493 return false; | 493 return false; |
494 } | 494 } |
495 return true; | 495 return true; |
496 } | 496 } |
497 | 497 |
498 if (s.IsNotFound()) { | 498 if (s.IsNotFound()) { |
499 DVLOG(1) << "No credentials found."; | 499 DVLOG(1) << "No credentials found."; |
500 return true; | 500 return true; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 611 |
612 GCMStoreImpl::GCMStoreImpl( | 612 GCMStoreImpl::GCMStoreImpl( |
613 bool use_mock_keychain, | 613 bool use_mock_keychain, |
614 const base::FilePath& path, | 614 const base::FilePath& path, |
615 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) | 615 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) |
616 : backend_(new Backend(path, base::MessageLoopProxy::current())), | 616 : backend_(new Backend(path, base::MessageLoopProxy::current())), |
617 blocking_task_runner_(blocking_task_runner), | 617 blocking_task_runner_(blocking_task_runner), |
618 weak_ptr_factory_(this) { | 618 weak_ptr_factory_(this) { |
619 // On OSX, prevent the Keychain permissions popup during unit tests. | 619 // On OSX, prevent the Keychain permissions popup during unit tests. |
620 #if defined(OS_MACOSX) | 620 #if defined(OS_MACOSX) |
621 Encryptor::UseMockKeychain(use_mock_keychain); | 621 OSCrypt::UseMockKeychain(use_mock_keychain); |
622 #endif | 622 #endif |
623 } | 623 } |
624 | 624 |
625 GCMStoreImpl::~GCMStoreImpl() {} | 625 GCMStoreImpl::~GCMStoreImpl() {} |
626 | 626 |
627 void GCMStoreImpl::Load(const LoadCallback& callback) { | 627 void GCMStoreImpl::Load(const LoadCallback& callback) { |
628 blocking_task_runner_->PostTask( | 628 blocking_task_runner_->PostTask( |
629 FROM_HERE, | 629 FROM_HERE, |
630 base::Bind(&GCMStoreImpl::Backend::Load, | 630 base::Bind(&GCMStoreImpl::Backend::Load, |
631 backend_, | 631 backend_, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 removed_message_counts.begin(); | 833 removed_message_counts.begin(); |
834 iter != removed_message_counts.end(); ++iter) { | 834 iter != removed_message_counts.end(); ++iter) { |
835 DCHECK_NE(app_message_counts_.count(iter->first), 0U); | 835 DCHECK_NE(app_message_counts_.count(iter->first), 0U); |
836 app_message_counts_[iter->first] -= iter->second; | 836 app_message_counts_[iter->first] -= iter->second; |
837 DCHECK_GE(app_message_counts_[iter->first], 0); | 837 DCHECK_GE(app_message_counts_[iter->first], 0); |
838 } | 838 } |
839 callback.Run(true); | 839 callback.Run(true); |
840 } | 840 } |
841 | 841 |
842 } // namespace gcm | 842 } // namespace gcm |
OLD | NEW |