| 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" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 class GCMStoreImpl::Backend | 91 class GCMStoreImpl::Backend |
| 92 : public base::RefCountedThreadSafe<GCMStoreImpl::Backend> { | 92 : public base::RefCountedThreadSafe<GCMStoreImpl::Backend> { |
| 93 public: | 93 public: |
| 94 Backend(const base::FilePath& path, | 94 Backend(const base::FilePath& path, |
| 95 scoped_refptr<base::SequencedTaskRunner> foreground_runner); | 95 scoped_refptr<base::SequencedTaskRunner> foreground_runner); |
| 96 | 96 |
| 97 // Blocking implementations of GCMStoreImpl methods. | 97 // Blocking implementations of GCMStoreImpl methods. |
| 98 void Load(const LoadCallback& callback); | 98 void Load(const LoadCallback& callback); |
| 99 void Close(); |
| 99 void Destroy(const UpdateCallback& callback); | 100 void Destroy(const UpdateCallback& callback); |
| 100 void SetDeviceCredentials(uint64 device_android_id, | 101 void SetDeviceCredentials(uint64 device_android_id, |
| 101 uint64 device_security_token, | 102 uint64 device_security_token, |
| 102 const UpdateCallback& callback); | 103 const UpdateCallback& callback); |
| 103 void AddIncomingMessage(const std::string& persistent_id, | 104 void AddIncomingMessage(const std::string& persistent_id, |
| 104 const UpdateCallback& callback); | 105 const UpdateCallback& callback); |
| 105 void RemoveIncomingMessages(const PersistentIdList& persistent_ids, | 106 void RemoveIncomingMessages(const PersistentIdList& persistent_ids, |
| 106 const UpdateCallback& callback); | 107 const UpdateCallback& callback); |
| 107 void AddOutgoingMessage(const std::string& persistent_id, | 108 void AddOutgoingMessage(const std::string& persistent_id, |
| 108 const MCSMessage& message, | 109 const MCSMessage& message, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 << " unacknowledged incoming messages and " | 207 << " unacknowledged incoming messages and " |
| 207 << result->outgoing_messages.size() | 208 << result->outgoing_messages.size() |
| 208 << " unacknowledged outgoing messages."; | 209 << " unacknowledged outgoing messages."; |
| 209 result->success = true; | 210 result->success = true; |
| 210 foreground_task_runner_->PostTask(FROM_HERE, | 211 foreground_task_runner_->PostTask(FROM_HERE, |
| 211 base::Bind(callback, | 212 base::Bind(callback, |
| 212 base::Passed(&result))); | 213 base::Passed(&result))); |
| 213 return; | 214 return; |
| 214 } | 215 } |
| 215 | 216 |
| 217 void GCMStoreImpl::Backend::Close() { |
| 218 DVLOG(1) << "Closing GCM store."; |
| 219 db_.reset(); |
| 220 } |
| 221 |
| 216 void GCMStoreImpl::Backend::Destroy(const UpdateCallback& callback) { | 222 void GCMStoreImpl::Backend::Destroy(const UpdateCallback& callback) { |
| 217 DVLOG(1) << "Destroying GCM store."; | 223 DVLOG(1) << "Destroying GCM store."; |
| 218 db_.reset(); | 224 db_.reset(); |
| 219 const leveldb::Status s = | 225 const leveldb::Status s = |
| 220 leveldb::DestroyDB(path_.AsUTF8Unsafe(), leveldb::Options()); | 226 leveldb::DestroyDB(path_.AsUTF8Unsafe(), leveldb::Options()); |
| 221 if (s.ok()) { | 227 if (s.ok()) { |
| 222 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, true)); | 228 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, true)); |
| 223 return; | 229 return; |
| 224 } | 230 } |
| 225 LOG(ERROR) << "Destroy failed: " << s.ToString(); | 231 LOG(ERROR) << "Destroy failed: " << s.ToString(); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 void GCMStoreImpl::Load(const LoadCallback& callback) { | 633 void GCMStoreImpl::Load(const LoadCallback& callback) { |
| 628 blocking_task_runner_->PostTask( | 634 blocking_task_runner_->PostTask( |
| 629 FROM_HERE, | 635 FROM_HERE, |
| 630 base::Bind(&GCMStoreImpl::Backend::Load, | 636 base::Bind(&GCMStoreImpl::Backend::Load, |
| 631 backend_, | 637 backend_, |
| 632 base::Bind(&GCMStoreImpl::LoadContinuation, | 638 base::Bind(&GCMStoreImpl::LoadContinuation, |
| 633 weak_ptr_factory_.GetWeakPtr(), | 639 weak_ptr_factory_.GetWeakPtr(), |
| 634 callback))); | 640 callback))); |
| 635 } | 641 } |
| 636 | 642 |
| 643 void GCMStoreImpl::Close() { |
| 644 blocking_task_runner_->PostTask( |
| 645 FROM_HERE, |
| 646 base::Bind(&GCMStoreImpl::Backend::Close, backend_)); |
| 647 } |
| 648 |
| 637 void GCMStoreImpl::Destroy(const UpdateCallback& callback) { | 649 void GCMStoreImpl::Destroy(const UpdateCallback& callback) { |
| 638 blocking_task_runner_->PostTask( | 650 blocking_task_runner_->PostTask( |
| 639 FROM_HERE, | 651 FROM_HERE, |
| 640 base::Bind(&GCMStoreImpl::Backend::Destroy, backend_, callback)); | 652 base::Bind(&GCMStoreImpl::Backend::Destroy, backend_, callback)); |
| 641 } | 653 } |
| 642 | 654 |
| 643 void GCMStoreImpl::SetDeviceCredentials(uint64 device_android_id, | 655 void GCMStoreImpl::SetDeviceCredentials(uint64 device_android_id, |
| 644 uint64 device_security_token, | 656 uint64 device_security_token, |
| 645 const UpdateCallback& callback) { | 657 const UpdateCallback& callback) { |
| 646 blocking_task_runner_->PostTask( | 658 blocking_task_runner_->PostTask( |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 removed_message_counts.begin(); | 845 removed_message_counts.begin(); |
| 834 iter != removed_message_counts.end(); ++iter) { | 846 iter != removed_message_counts.end(); ++iter) { |
| 835 DCHECK_NE(app_message_counts_.count(iter->first), 0U); | 847 DCHECK_NE(app_message_counts_.count(iter->first), 0U); |
| 836 app_message_counts_[iter->first] -= iter->second; | 848 app_message_counts_[iter->first] -= iter->second; |
| 837 DCHECK_GE(app_message_counts_[iter->first], 0); | 849 DCHECK_GE(app_message_counts_[iter->first], 0); |
| 838 } | 850 } |
| 839 callback.Run(true); | 851 callback.Run(true); |
| 840 } | 852 } |
| 841 | 853 |
| 842 } // namespace gcm | 854 } // namespace gcm |
| OLD | NEW |