| 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/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
| 14 #include "base/metrics/histogram.h" |
| 13 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 14 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 17 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
| 18 #include "components/webdata/encryptor/encryptor.h" | 20 #include "components/webdata/encryptor/encryptor.h" |
| 19 #include "google_apis/gcm/base/mcs_message.h" | 21 #include "google_apis/gcm/base/mcs_message.h" |
| 20 #include "google_apis/gcm/base/mcs_util.h" | 22 #include "google_apis/gcm/base/mcs_util.h" |
| 21 #include "google_apis/gcm/protocol/mcs.pb.h" | 23 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 22 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 24 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 GCMStoreImpl::Backend::~Backend() {} | 136 GCMStoreImpl::Backend::~Backend() {} |
| 135 | 137 |
| 136 void GCMStoreImpl::Backend::Load(const LoadCallback& callback) { | 138 void GCMStoreImpl::Backend::Load(const LoadCallback& callback) { |
| 137 LoadResult result; | 139 LoadResult result; |
| 138 | 140 |
| 139 leveldb::Options options; | 141 leveldb::Options options; |
| 140 options.create_if_missing = true; | 142 options.create_if_missing = true; |
| 141 leveldb::DB* db; | 143 leveldb::DB* db; |
| 142 leveldb::Status status = | 144 leveldb::Status status = |
| 143 leveldb::DB::Open(options, path_.AsUTF8Unsafe(), &db); | 145 leveldb::DB::Open(options, path_.AsUTF8Unsafe(), &db); |
| 146 UMA_HISTOGRAM_BOOLEAN("GCM.LoadSucceeded", status.ok()); |
| 144 if (!status.ok()) { | 147 if (!status.ok()) { |
| 145 LOG(ERROR) << "Failed to open database " << path_.value() << ": " | 148 LOG(ERROR) << "Failed to open database " << path_.value() << ": " |
| 146 << status.ToString(); | 149 << status.ToString(); |
| 147 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); | 150 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 148 return; | 151 return; |
| 149 } | 152 } |
| 150 db_.reset(db); | 153 db_.reset(db); |
| 151 | 154 |
| 152 if (!LoadDeviceCredentials(&result.device_android_id, | 155 if (!LoadDeviceCredentials(&result.device_android_id, |
| 153 &result.device_security_token) || | 156 &result.device_security_token) || |
| 154 !LoadIncomingMessages(&result.incoming_messages) || | 157 !LoadIncomingMessages(&result.incoming_messages) || |
| 155 !LoadOutgoingMessages(&result.outgoing_messages) || | 158 !LoadOutgoingMessages(&result.outgoing_messages) || |
| 156 !LoadNextSerialNumber(&result.next_serial_number) || | 159 !LoadNextSerialNumber(&result.next_serial_number) || |
| 157 !LoadUserSerialNumberMap(&result.user_serial_numbers)) { | 160 !LoadUserSerialNumberMap(&result.user_serial_numbers)) { |
| 158 result.device_android_id = 0; | 161 result.device_android_id = 0; |
| 159 result.device_security_token = 0; | 162 result.device_security_token = 0; |
| 160 result.incoming_messages.clear(); | 163 result.incoming_messages.clear(); |
| 161 STLDeleteContainerPairSecondPointers(result.outgoing_messages.begin(), | 164 STLDeleteContainerPairSecondPointers(result.outgoing_messages.begin(), |
| 162 result.outgoing_messages.end()); | 165 result.outgoing_messages.end()); |
| 163 result.outgoing_messages.clear(); | 166 result.outgoing_messages.clear(); |
| 164 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); | 167 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 165 return; | 168 return; |
| 166 } | 169 } |
| 167 | 170 |
| 171 // Only record histograms if GCM had already been set up for this device. |
| 172 if (result.device_android_id != 0 && result.device_security_token != 0) { |
| 173 int64 file_size = 0; |
| 174 if (base::GetFileSize(path_, &file_size)) { |
| 175 UMA_HISTOGRAM_COUNTS("GCM.StoreSizeKB", |
| 176 static_cast<int>(file_size / 1024)); |
| 177 } |
| 178 UMA_HISTOGRAM_COUNTS("GCM.RestoredOutgoingMessages", |
| 179 result.outgoing_messages.size()); |
| 180 UMA_HISTOGRAM_COUNTS("GCM.RestoredIncomingMessages", |
| 181 result.incoming_messages.size()); |
| 182 UMA_HISTOGRAM_COUNTS("GCM.NumUsers", result.user_serial_numbers.size()); |
| 183 } |
| 184 |
| 185 |
| 168 DVLOG(1) << "Succeeded in loading " << result.incoming_messages.size() | 186 DVLOG(1) << "Succeeded in loading " << result.incoming_messages.size() |
| 169 << " unacknowledged incoming messages and " | 187 << " unacknowledged incoming messages and " |
| 170 << result.outgoing_messages.size() | 188 << result.outgoing_messages.size() |
| 171 << " unacknowledged outgoing messages."; | 189 << " unacknowledged outgoing messages."; |
| 172 result.success = true; | 190 result.success = true; |
| 173 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); | 191 foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, result)); |
| 174 return; | 192 return; |
| 175 } | 193 } |
| 176 | 194 |
| 177 void GCMStoreImpl::Backend::Destroy(const UpdateCallback& callback) { | 195 void GCMStoreImpl::Backend::Destroy(const UpdateCallback& callback) { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 const UpdateCallback& callback) { | 629 const UpdateCallback& callback) { |
| 612 blocking_task_runner_->PostTask( | 630 blocking_task_runner_->PostTask( |
| 613 FROM_HERE, | 631 FROM_HERE, |
| 614 base::Bind(&GCMStoreImpl::Backend::RemoveUserSerialNumber, | 632 base::Bind(&GCMStoreImpl::Backend::RemoveUserSerialNumber, |
| 615 backend_, | 633 backend_, |
| 616 username, | 634 username, |
| 617 callback)); | 635 callback)); |
| 618 } | 636 } |
| 619 | 637 |
| 620 } // namespace gcm | 638 } // namespace gcm |
| OLD | NEW |