| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return leveldb::Slice(s.begin(), s.size()); | 178 return leveldb::Slice(s.begin(), s.size()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 } // namespace | 181 } // namespace |
| 182 | 182 |
| 183 class GCMStoreImpl::Backend | 183 class GCMStoreImpl::Backend |
| 184 : public base::RefCountedThreadSafe<GCMStoreImpl::Backend> { | 184 : public base::RefCountedThreadSafe<GCMStoreImpl::Backend> { |
| 185 public: | 185 public: |
| 186 Backend(const base::FilePath& path, | 186 Backend(const base::FilePath& path, |
| 187 scoped_refptr<base::SequencedTaskRunner> foreground_runner, | 187 scoped_refptr<base::SequencedTaskRunner> foreground_runner, |
| 188 scoped_ptr<Encryptor> encryptor); | 188 std::unique_ptr<Encryptor> encryptor); |
| 189 | 189 |
| 190 // Blocking implementations of GCMStoreImpl methods. | 190 // Blocking implementations of GCMStoreImpl methods. |
| 191 void Load(StoreOpenMode open_mode, const LoadCallback& callback); | 191 void Load(StoreOpenMode open_mode, const LoadCallback& callback); |
| 192 void Close(); | 192 void Close(); |
| 193 void Destroy(const UpdateCallback& callback); | 193 void Destroy(const UpdateCallback& callback); |
| 194 void SetDeviceCredentials(uint64_t device_android_id, | 194 void SetDeviceCredentials(uint64_t device_android_id, |
| 195 uint64_t device_security_token, | 195 uint64_t device_security_token, |
| 196 const UpdateCallback& callback); | 196 const UpdateCallback& callback); |
| 197 void AddRegistration(const std::string& serialized_key, | 197 void AddRegistration(const std::string& serialized_key, |
| 198 const std::string& serialized_value, | 198 const std::string& serialized_value, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 std::set<std::string>* accounts); | 255 std::set<std::string>* accounts); |
| 256 bool LoadGServicesSettings(std::map<std::string, std::string>* settings, | 256 bool LoadGServicesSettings(std::map<std::string, std::string>* settings, |
| 257 std::string* digest); | 257 std::string* digest); |
| 258 bool LoadAccountMappingInfo(AccountMappings* account_mappings); | 258 bool LoadAccountMappingInfo(AccountMappings* account_mappings); |
| 259 bool LoadLastTokenFetchTime(base::Time* last_token_fetch_time); | 259 bool LoadLastTokenFetchTime(base::Time* last_token_fetch_time); |
| 260 bool LoadHeartbeatIntervals(std::map<std::string, int>* heartbeat_intervals); | 260 bool LoadHeartbeatIntervals(std::map<std::string, int>* heartbeat_intervals); |
| 261 bool LoadInstanceIDData(std::map<std::string, std::string>* instance_id_data); | 261 bool LoadInstanceIDData(std::map<std::string, std::string>* instance_id_data); |
| 262 | 262 |
| 263 const base::FilePath path_; | 263 const base::FilePath path_; |
| 264 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; | 264 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; |
| 265 scoped_ptr<Encryptor> encryptor_; | 265 std::unique_ptr<Encryptor> encryptor_; |
| 266 | 266 |
| 267 scoped_ptr<leveldb::DB> db_; | 267 std::unique_ptr<leveldb::DB> db_; |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 GCMStoreImpl::Backend::Backend( | 270 GCMStoreImpl::Backend::Backend( |
| 271 const base::FilePath& path, | 271 const base::FilePath& path, |
| 272 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner, | 272 scoped_refptr<base::SequencedTaskRunner> foreground_task_runner, |
| 273 scoped_ptr<Encryptor> encryptor) | 273 std::unique_ptr<Encryptor> encryptor) |
| 274 : path_(path), | 274 : path_(path), |
| 275 foreground_task_runner_(foreground_task_runner), | 275 foreground_task_runner_(foreground_task_runner), |
| 276 encryptor_(std::move(encryptor)) {} | 276 encryptor_(std::move(encryptor)) {} |
| 277 | 277 |
| 278 GCMStoreImpl::Backend::~Backend() {} | 278 GCMStoreImpl::Backend::~Backend() {} |
| 279 | 279 |
| 280 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(StoreOpenMode open_mode, | 280 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(StoreOpenMode open_mode, |
| 281 LoadResult* result) { | 281 LoadResult* result) { |
| 282 LoadStatus load_status; | 282 LoadStatus load_status; |
| 283 if (db_.get()) { | 283 if (db_.get()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 if (!LoadHeartbeatIntervals(&result->heartbeat_intervals)) | 334 if (!LoadHeartbeatIntervals(&result->heartbeat_intervals)) |
| 335 return LOADING_HEARTBEAT_INTERVALS_FAILED; | 335 return LOADING_HEARTBEAT_INTERVALS_FAILED; |
| 336 if (!LoadInstanceIDData(&result->instance_id_data)) | 336 if (!LoadInstanceIDData(&result->instance_id_data)) |
| 337 return LOADING_INSTANCE_ID_DATA_FAILED; | 337 return LOADING_INSTANCE_ID_DATA_FAILED; |
| 338 | 338 |
| 339 return LOADING_SUCCEEDED; | 339 return LOADING_SUCCEEDED; |
| 340 } | 340 } |
| 341 | 341 |
| 342 void GCMStoreImpl::Backend::Load(StoreOpenMode open_mode, | 342 void GCMStoreImpl::Backend::Load(StoreOpenMode open_mode, |
| 343 const LoadCallback& callback) { | 343 const LoadCallback& callback) { |
| 344 scoped_ptr<LoadResult> result(new LoadResult()); | 344 std::unique_ptr<LoadResult> result(new LoadResult()); |
| 345 LoadStatus load_status = OpenStoreAndLoadData(open_mode, result.get()); | 345 LoadStatus load_status = OpenStoreAndLoadData(open_mode, result.get()); |
| 346 UMA_HISTOGRAM_ENUMERATION("GCM.LoadStatus", load_status, LOAD_STATUS_COUNT); | 346 UMA_HISTOGRAM_ENUMERATION("GCM.LoadStatus", load_status, LOAD_STATUS_COUNT); |
| 347 if (load_status != LOADING_SUCCEEDED) { | 347 if (load_status != LOADING_SUCCEEDED) { |
| 348 result->Reset(); | 348 result->Reset(); |
| 349 result->store_does_not_exist = (load_status == STORE_DOES_NOT_EXIST); | 349 result->store_does_not_exist = (load_status == STORE_DOES_NOT_EXIST); |
| 350 foreground_task_runner_->PostTask(FROM_HERE, | 350 foreground_task_runner_->PostTask(FROM_HERE, |
| 351 base::Bind(callback, | 351 base::Bind(callback, |
| 352 base::Passed(&result))); | 352 base::Passed(&result))); |
| 353 return; | 353 return; |
| 354 } | 354 } |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 687 |
| 688 void GCMStoreImpl::Backend::SetGServicesSettings( | 688 void GCMStoreImpl::Backend::SetGServicesSettings( |
| 689 const std::map<std::string, std::string>& settings, | 689 const std::map<std::string, std::string>& settings, |
| 690 const std::string& settings_digest, | 690 const std::string& settings_digest, |
| 691 const UpdateCallback& callback) { | 691 const UpdateCallback& callback) { |
| 692 leveldb::WriteBatch write_batch; | 692 leveldb::WriteBatch write_batch; |
| 693 | 693 |
| 694 // Remove all existing settings. | 694 // Remove all existing settings. |
| 695 leveldb::ReadOptions read_options; | 695 leveldb::ReadOptions read_options; |
| 696 read_options.verify_checksums = true; | 696 read_options.verify_checksums = true; |
| 697 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 697 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 698 for (iter->Seek(MakeSlice(kGServiceSettingKeyStart)); | 698 for (iter->Seek(MakeSlice(kGServiceSettingKeyStart)); |
| 699 iter->Valid() && iter->key().ToString() < kGServiceSettingKeyEnd; | 699 iter->Valid() && iter->key().ToString() < kGServiceSettingKeyEnd; |
| 700 iter->Next()) { | 700 iter->Next()) { |
| 701 write_batch.Delete(iter->key()); | 701 write_batch.Delete(iter->key()); |
| 702 } | 702 } |
| 703 | 703 |
| 704 // Add the new settings. | 704 // Add the new settings. |
| 705 for (std::map<std::string, std::string>::const_iterator iter = | 705 for (std::map<std::string, std::string>::const_iterator iter = |
| 706 settings.begin(); | 706 settings.begin(); |
| 707 iter != settings.end(); ++iter) { | 707 iter != settings.end(); ++iter) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 | 932 |
| 933 LOG(ERROR) << "Error reading credentials from store."; | 933 LOG(ERROR) << "Error reading credentials from store."; |
| 934 return false; | 934 return false; |
| 935 } | 935 } |
| 936 | 936 |
| 937 bool GCMStoreImpl::Backend::LoadRegistrations( | 937 bool GCMStoreImpl::Backend::LoadRegistrations( |
| 938 std::map<std::string, std::string>* registrations) { | 938 std::map<std::string, std::string>* registrations) { |
| 939 leveldb::ReadOptions read_options; | 939 leveldb::ReadOptions read_options; |
| 940 read_options.verify_checksums = true; | 940 read_options.verify_checksums = true; |
| 941 | 941 |
| 942 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 942 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 943 for (iter->Seek(MakeSlice(kRegistrationKeyStart)); | 943 for (iter->Seek(MakeSlice(kRegistrationKeyStart)); |
| 944 iter->Valid() && iter->key().ToString() < kRegistrationKeyEnd; | 944 iter->Valid() && iter->key().ToString() < kRegistrationKeyEnd; |
| 945 iter->Next()) { | 945 iter->Next()) { |
| 946 leveldb::Slice s = iter->value(); | 946 leveldb::Slice s = iter->value(); |
| 947 if (s.size() <= 1) { | 947 if (s.size() <= 1) { |
| 948 LOG(ERROR) << "Error reading registration with key " << s.ToString(); | 948 LOG(ERROR) << "Error reading registration with key " << s.ToString(); |
| 949 return false; | 949 return false; |
| 950 } | 950 } |
| 951 std::string app_id = ParseRegistrationKey(iter->key().ToString()); | 951 std::string app_id = ParseRegistrationKey(iter->key().ToString()); |
| 952 DVLOG(1) << "Found registration with app id " << app_id; | 952 DVLOG(1) << "Found registration with app id " << app_id; |
| 953 (*registrations)[app_id] = iter->value().ToString(); | 953 (*registrations)[app_id] = iter->value().ToString(); |
| 954 } | 954 } |
| 955 | 955 |
| 956 return true; | 956 return true; |
| 957 } | 957 } |
| 958 | 958 |
| 959 bool GCMStoreImpl::Backend::LoadIncomingMessages( | 959 bool GCMStoreImpl::Backend::LoadIncomingMessages( |
| 960 std::vector<std::string>* incoming_messages) { | 960 std::vector<std::string>* incoming_messages) { |
| 961 leveldb::ReadOptions read_options; | 961 leveldb::ReadOptions read_options; |
| 962 read_options.verify_checksums = true; | 962 read_options.verify_checksums = true; |
| 963 | 963 |
| 964 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 964 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 965 for (iter->Seek(MakeSlice(kIncomingMsgKeyStart)); | 965 for (iter->Seek(MakeSlice(kIncomingMsgKeyStart)); |
| 966 iter->Valid() && iter->key().ToString() < kIncomingMsgKeyEnd; | 966 iter->Valid() && iter->key().ToString() < kIncomingMsgKeyEnd; |
| 967 iter->Next()) { | 967 iter->Next()) { |
| 968 leveldb::Slice s = iter->value(); | 968 leveldb::Slice s = iter->value(); |
| 969 if (s.empty()) { | 969 if (s.empty()) { |
| 970 LOG(ERROR) << "Error reading incoming message with key " | 970 LOG(ERROR) << "Error reading incoming message with key " |
| 971 << iter->key().ToString(); | 971 << iter->key().ToString(); |
| 972 return false; | 972 return false; |
| 973 } | 973 } |
| 974 DVLOG(1) << "Found incoming message with id " << s.ToString(); | 974 DVLOG(1) << "Found incoming message with id " << s.ToString(); |
| 975 incoming_messages->push_back(s.ToString()); | 975 incoming_messages->push_back(s.ToString()); |
| 976 } | 976 } |
| 977 | 977 |
| 978 return true; | 978 return true; |
| 979 } | 979 } |
| 980 | 980 |
| 981 bool GCMStoreImpl::Backend::LoadOutgoingMessages( | 981 bool GCMStoreImpl::Backend::LoadOutgoingMessages( |
| 982 OutgoingMessageMap* outgoing_messages) { | 982 OutgoingMessageMap* outgoing_messages) { |
| 983 leveldb::ReadOptions read_options; | 983 leveldb::ReadOptions read_options; |
| 984 read_options.verify_checksums = true; | 984 read_options.verify_checksums = true; |
| 985 | 985 |
| 986 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 986 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 987 for (iter->Seek(MakeSlice(kOutgoingMsgKeyStart)); | 987 for (iter->Seek(MakeSlice(kOutgoingMsgKeyStart)); |
| 988 iter->Valid() && iter->key().ToString() < kOutgoingMsgKeyEnd; | 988 iter->Valid() && iter->key().ToString() < kOutgoingMsgKeyEnd; |
| 989 iter->Next()) { | 989 iter->Next()) { |
| 990 leveldb::Slice s = iter->value(); | 990 leveldb::Slice s = iter->value(); |
| 991 if (s.size() <= 1) { | 991 if (s.size() <= 1) { |
| 992 LOG(ERROR) << "Error reading incoming message with key " << s.ToString(); | 992 LOG(ERROR) << "Error reading incoming message with key " << s.ToString(); |
| 993 return false; | 993 return false; |
| 994 } | 994 } |
| 995 uint8_t tag = iter->value().data()[0]; | 995 uint8_t tag = iter->value().data()[0]; |
| 996 std::string id = ParseOutgoingKey(iter->key().ToString()); | 996 std::string id = ParseOutgoingKey(iter->key().ToString()); |
| 997 scoped_ptr<google::protobuf::MessageLite> message( | 997 std::unique_ptr<google::protobuf::MessageLite> message( |
| 998 BuildProtobufFromTag(tag)); | 998 BuildProtobufFromTag(tag)); |
| 999 if (!message.get() || | 999 if (!message.get() || |
| 1000 !message->ParseFromString(iter->value().ToString().substr(1))) { | 1000 !message->ParseFromString(iter->value().ToString().substr(1))) { |
| 1001 LOG(ERROR) << "Failed to parse outgoing message with id " << id | 1001 LOG(ERROR) << "Failed to parse outgoing message with id " << id |
| 1002 << " and tag " << tag; | 1002 << " and tag " << tag; |
| 1003 return false; | 1003 return false; |
| 1004 } | 1004 } |
| 1005 DVLOG(1) << "Found outgoing message with id " << id << " of type " | 1005 DVLOG(1) << "Found outgoing message with id " << id << " of type " |
| 1006 << base::UintToString(tag); | 1006 << base::UintToString(tag); |
| 1007 (*outgoing_messages)[id] = make_linked_ptr(message.release()); | 1007 (*outgoing_messages)[id] = make_linked_ptr(message.release()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 return true; | 1042 return true; |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 bool GCMStoreImpl::Backend::LoadGServicesSettings( | 1045 bool GCMStoreImpl::Backend::LoadGServicesSettings( |
| 1046 std::map<std::string, std::string>* settings, | 1046 std::map<std::string, std::string>* settings, |
| 1047 std::string* digest) { | 1047 std::string* digest) { |
| 1048 leveldb::ReadOptions read_options; | 1048 leveldb::ReadOptions read_options; |
| 1049 read_options.verify_checksums = true; | 1049 read_options.verify_checksums = true; |
| 1050 | 1050 |
| 1051 // Load all of the GServices settings. | 1051 // Load all of the GServices settings. |
| 1052 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 1052 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 1053 for (iter->Seek(MakeSlice(kGServiceSettingKeyStart)); | 1053 for (iter->Seek(MakeSlice(kGServiceSettingKeyStart)); |
| 1054 iter->Valid() && iter->key().ToString() < kGServiceSettingKeyEnd; | 1054 iter->Valid() && iter->key().ToString() < kGServiceSettingKeyEnd; |
| 1055 iter->Next()) { | 1055 iter->Next()) { |
| 1056 std::string value = iter->value().ToString(); | 1056 std::string value = iter->value().ToString(); |
| 1057 if (value.empty()) { | 1057 if (value.empty()) { |
| 1058 LOG(ERROR) << "Error reading GService Settings " << value; | 1058 LOG(ERROR) << "Error reading GService Settings " << value; |
| 1059 return false; | 1059 return false; |
| 1060 } | 1060 } |
| 1061 std::string id = ParseGServiceSettingKey(iter->key().ToString()); | 1061 std::string id = ParseGServiceSettingKey(iter->key().ToString()); |
| 1062 (*settings)[id] = value; | 1062 (*settings)[id] = value; |
| 1063 DVLOG(1) << "Found G Service setting with key: " << id | 1063 DVLOG(1) << "Found G Service setting with key: " << id |
| 1064 << ", and value: " << value; | 1064 << ", and value: " << value; |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 // Load the settings digest. It's ok if it is empty. | 1067 // Load the settings digest. It's ok if it is empty. |
| 1068 db_->Get(read_options, MakeSlice(kGServiceSettingsDigestKey), digest); | 1068 db_->Get(read_options, MakeSlice(kGServiceSettingsDigestKey), digest); |
| 1069 | 1069 |
| 1070 return true; | 1070 return true; |
| 1071 } | 1071 } |
| 1072 | 1072 |
| 1073 bool GCMStoreImpl::Backend::LoadAccountMappingInfo( | 1073 bool GCMStoreImpl::Backend::LoadAccountMappingInfo( |
| 1074 AccountMappings* account_mappings) { | 1074 AccountMappings* account_mappings) { |
| 1075 leveldb::ReadOptions read_options; | 1075 leveldb::ReadOptions read_options; |
| 1076 read_options.verify_checksums = true; | 1076 read_options.verify_checksums = true; |
| 1077 | 1077 |
| 1078 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 1078 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 1079 for (iter->Seek(MakeSlice(kAccountKeyStart)); | 1079 for (iter->Seek(MakeSlice(kAccountKeyStart)); |
| 1080 iter->Valid() && iter->key().ToString() < kAccountKeyEnd; | 1080 iter->Valid() && iter->key().ToString() < kAccountKeyEnd; |
| 1081 iter->Next()) { | 1081 iter->Next()) { |
| 1082 AccountMapping account_mapping; | 1082 AccountMapping account_mapping; |
| 1083 account_mapping.account_id = ParseAccountKey(iter->key().ToString()); | 1083 account_mapping.account_id = ParseAccountKey(iter->key().ToString()); |
| 1084 if (!account_mapping.ParseFromString(iter->value().ToString())) { | 1084 if (!account_mapping.ParseFromString(iter->value().ToString())) { |
| 1085 DVLOG(1) << "Failed to parse account info with ID: " | 1085 DVLOG(1) << "Failed to parse account info with ID: " |
| 1086 << account_mapping.account_id; | 1086 << account_mapping.account_id; |
| 1087 return false; | 1087 return false; |
| 1088 } | 1088 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1112 *last_token_fetch_time = base::Time::FromInternalValue(time_internal); | 1112 *last_token_fetch_time = base::Time::FromInternalValue(time_internal); |
| 1113 | 1113 |
| 1114 return true; | 1114 return true; |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 bool GCMStoreImpl::Backend::LoadHeartbeatIntervals( | 1117 bool GCMStoreImpl::Backend::LoadHeartbeatIntervals( |
| 1118 std::map<std::string, int>* heartbeat_intervals) { | 1118 std::map<std::string, int>* heartbeat_intervals) { |
| 1119 leveldb::ReadOptions read_options; | 1119 leveldb::ReadOptions read_options; |
| 1120 read_options.verify_checksums = true; | 1120 read_options.verify_checksums = true; |
| 1121 | 1121 |
| 1122 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 1122 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 1123 for (iter->Seek(MakeSlice(kHeartbeatKeyStart)); | 1123 for (iter->Seek(MakeSlice(kHeartbeatKeyStart)); |
| 1124 iter->Valid() && iter->key().ToString() < kHeartbeatKeyEnd; | 1124 iter->Valid() && iter->key().ToString() < kHeartbeatKeyEnd; |
| 1125 iter->Next()) { | 1125 iter->Next()) { |
| 1126 std::string scope = ParseHeartbeatKey(iter->key().ToString()); | 1126 std::string scope = ParseHeartbeatKey(iter->key().ToString()); |
| 1127 int interval_ms; | 1127 int interval_ms; |
| 1128 if (!base::StringToInt(iter->value().ToString(), &interval_ms)) { | 1128 if (!base::StringToInt(iter->value().ToString(), &interval_ms)) { |
| 1129 DVLOG(1) << "Failed to parse heartbeat interval info with scope: " | 1129 DVLOG(1) << "Failed to parse heartbeat interval info with scope: " |
| 1130 << scope; | 1130 << scope; |
| 1131 return false; | 1131 return false; |
| 1132 } | 1132 } |
| 1133 DVLOG(1) << "Found heartbeat interval with scope: " << scope | 1133 DVLOG(1) << "Found heartbeat interval with scope: " << scope |
| 1134 << " interval: " << interval_ms << "ms."; | 1134 << " interval: " << interval_ms << "ms."; |
| 1135 (*heartbeat_intervals)[scope] = interval_ms; | 1135 (*heartbeat_intervals)[scope] = interval_ms; |
| 1136 } | 1136 } |
| 1137 | 1137 |
| 1138 return true; | 1138 return true; |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 bool GCMStoreImpl::Backend::LoadInstanceIDData( | 1141 bool GCMStoreImpl::Backend::LoadInstanceIDData( |
| 1142 std::map<std::string, std::string>* instance_id_data) { | 1142 std::map<std::string, std::string>* instance_id_data) { |
| 1143 leveldb::ReadOptions read_options; | 1143 leveldb::ReadOptions read_options; |
| 1144 read_options.verify_checksums = true; | 1144 read_options.verify_checksums = true; |
| 1145 | 1145 |
| 1146 scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); | 1146 std::unique_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); |
| 1147 for (iter->Seek(MakeSlice(kInstanceIDKeyStart)); | 1147 for (iter->Seek(MakeSlice(kInstanceIDKeyStart)); |
| 1148 iter->Valid() && iter->key().ToString() < kInstanceIDKeyEnd; | 1148 iter->Valid() && iter->key().ToString() < kInstanceIDKeyEnd; |
| 1149 iter->Next()) { | 1149 iter->Next()) { |
| 1150 leveldb::Slice s = iter->value(); | 1150 leveldb::Slice s = iter->value(); |
| 1151 if (s.size() <= 1) { | 1151 if (s.size() <= 1) { |
| 1152 LOG(ERROR) << "Error reading IID data with key " << s.ToString(); | 1152 LOG(ERROR) << "Error reading IID data with key " << s.ToString(); |
| 1153 return false; | 1153 return false; |
| 1154 } | 1154 } |
| 1155 std::string app_id = ParseInstanceIDKey(iter->key().ToString()); | 1155 std::string app_id = ParseInstanceIDKey(iter->key().ToString()); |
| 1156 DVLOG(1) << "Found IID data with app id " << app_id; | 1156 DVLOG(1) << "Found IID data with app id " << app_id; |
| 1157 (*instance_id_data)[app_id] = s.ToString(); | 1157 (*instance_id_data)[app_id] = s.ToString(); |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 return true; | 1160 return true; |
| 1161 } | 1161 } |
| 1162 | 1162 |
| 1163 GCMStoreImpl::GCMStoreImpl( | 1163 GCMStoreImpl::GCMStoreImpl( |
| 1164 const base::FilePath& path, | 1164 const base::FilePath& path, |
| 1165 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 1165 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
| 1166 scoped_ptr<Encryptor> encryptor) | 1166 std::unique_ptr<Encryptor> encryptor) |
| 1167 : backend_(new Backend(path, | 1167 : backend_(new Backend(path, |
| 1168 base::ThreadTaskRunnerHandle::Get(), | 1168 base::ThreadTaskRunnerHandle::Get(), |
| 1169 std::move(encryptor))), | 1169 std::move(encryptor))), |
| 1170 blocking_task_runner_(blocking_task_runner), | 1170 blocking_task_runner_(blocking_task_runner), |
| 1171 weak_ptr_factory_(this) {} | 1171 weak_ptr_factory_(this) {} |
| 1172 | 1172 |
| 1173 GCMStoreImpl::~GCMStoreImpl() {} | 1173 GCMStoreImpl::~GCMStoreImpl() {} |
| 1174 | 1174 |
| 1175 void GCMStoreImpl::Load(StoreOpenMode open_mode, const LoadCallback& callback) { | 1175 void GCMStoreImpl::Load(StoreOpenMode open_mode, const LoadCallback& callback) { |
| 1176 blocking_task_runner_->PostTask( | 1176 blocking_task_runner_->PostTask( |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 blocking_task_runner_->PostTask( | 1417 blocking_task_runner_->PostTask( |
| 1418 FROM_HERE, | 1418 FROM_HERE, |
| 1419 base::Bind(&GCMStoreImpl::Backend::SetValue, | 1419 base::Bind(&GCMStoreImpl::Backend::SetValue, |
| 1420 backend_, | 1420 backend_, |
| 1421 key, | 1421 key, |
| 1422 value, | 1422 value, |
| 1423 callback)); | 1423 callback)); |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 void GCMStoreImpl::LoadContinuation(const LoadCallback& callback, | 1426 void GCMStoreImpl::LoadContinuation(const LoadCallback& callback, |
| 1427 scoped_ptr<LoadResult> result) { | 1427 std::unique_ptr<LoadResult> result) { |
| 1428 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1428 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
| 1429 tracked_objects::ScopedTracker tracking_profile( | 1429 tracked_objects::ScopedTracker tracking_profile( |
| 1430 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1430 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1431 "477117 GCMStoreImpl::LoadContinuation")); | 1431 "477117 GCMStoreImpl::LoadContinuation")); |
| 1432 if (!result->success) { | 1432 if (!result->success) { |
| 1433 callback.Run(std::move(result)); | 1433 callback.Run(std::move(result)); |
| 1434 return; | 1434 return; |
| 1435 } | 1435 } |
| 1436 int num_throttled_apps = 0; | 1436 int num_throttled_apps = 0; |
| 1437 for (OutgoingMessageMap::const_iterator | 1437 for (OutgoingMessageMap::const_iterator |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 removed_message_counts.begin(); | 1474 removed_message_counts.begin(); |
| 1475 iter != removed_message_counts.end(); ++iter) { | 1475 iter != removed_message_counts.end(); ++iter) { |
| 1476 DCHECK_NE(app_message_counts_.count(iter->first), 0U); | 1476 DCHECK_NE(app_message_counts_.count(iter->first), 0U); |
| 1477 app_message_counts_[iter->first] -= iter->second; | 1477 app_message_counts_[iter->first] -= iter->second; |
| 1478 DCHECK_GE(app_message_counts_[iter->first], 0); | 1478 DCHECK_GE(app_message_counts_[iter->first], 0); |
| 1479 } | 1479 } |
| 1480 callback.Run(true); | 1480 callback.Run(true); |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 } // namespace gcm | 1483 } // namespace gcm |
| OLD | NEW |