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/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.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_macros.h" | 14 #include "base/metrics/histogram_macros.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/strings/string_tokenizer.h" | 19 #include "base/strings/string_tokenizer.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/tracked_objects.h" | 21 #include "base/tracked_objects.h" |
22 #include "google_apis/gcm/base/encryptor.h" | 22 #include "google_apis/gcm/base/encryptor.h" |
23 #include "google_apis/gcm/base/mcs_message.h" | 23 #include "google_apis/gcm/base/mcs_message.h" |
24 #include "google_apis/gcm/base/mcs_util.h" | 24 #include "google_apis/gcm/base/mcs_util.h" |
25 #include "google_apis/gcm/protocol/mcs.pb.h" | 25 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 26 #include "third_party/leveldatabase/env_chromium.h" |
26 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 27 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
27 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" | 28 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
28 | 29 |
29 namespace gcm { | 30 namespace gcm { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // This enum is used in an UMA histogram (GCMLoadStatus enum defined in | 34 // This enum is used in an UMA histogram (GCMLoadStatus enum defined in |
34 // tools/metrics/histograms/histogram.xml). Hence the entries here shouldn't | 35 // tools/metrics/histograms/histogram.xml). Hence the entries here shouldn't |
35 // be deleted or re-ordered and new ones should be added to the end. | 36 // be deleted or re-ordered and new ones should be added to the end. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 233 |
233 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(LoadResult* result) { | 234 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(LoadResult* result) { |
234 LoadStatus load_status; | 235 LoadStatus load_status; |
235 if (db_.get()) { | 236 if (db_.get()) { |
236 LOG(ERROR) << "Attempting to reload open database."; | 237 LOG(ERROR) << "Attempting to reload open database."; |
237 return RELOADING_OPEN_STORE; | 238 return RELOADING_OPEN_STORE; |
238 } | 239 } |
239 | 240 |
240 leveldb::Options options; | 241 leveldb::Options options; |
241 options.create_if_missing = true; | 242 options.create_if_missing = true; |
| 243 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; |
242 leveldb::DB* db; | 244 leveldb::DB* db; |
243 leveldb::Status status = | 245 leveldb::Status status = |
244 leveldb::DB::Open(options, path_.AsUTF8Unsafe(), &db); | 246 leveldb::DB::Open(options, path_.AsUTF8Unsafe(), &db); |
245 if (!status.ok()) { | 247 if (!status.ok()) { |
246 LOG(ERROR) << "Failed to open database " << path_.value() << ": " | 248 LOG(ERROR) << "Failed to open database " << path_.value() << ": " |
247 << status.ToString(); | 249 << status.ToString(); |
248 return OPENING_STORE_FAILED; | 250 return OPENING_STORE_FAILED; |
249 } | 251 } |
250 | 252 |
251 db_.reset(db); | 253 db_.reset(db); |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 removed_message_counts.begin(); | 1217 removed_message_counts.begin(); |
1216 iter != removed_message_counts.end(); ++iter) { | 1218 iter != removed_message_counts.end(); ++iter) { |
1217 DCHECK_NE(app_message_counts_.count(iter->first), 0U); | 1219 DCHECK_NE(app_message_counts_.count(iter->first), 0U); |
1218 app_message_counts_[iter->first] -= iter->second; | 1220 app_message_counts_[iter->first] -= iter->second; |
1219 DCHECK_GE(app_message_counts_[iter->first], 0); | 1221 DCHECK_GE(app_message_counts_[iter->first], 0); |
1220 } | 1222 } |
1221 callback.Run(true); | 1223 callback.Run(true); |
1222 } | 1224 } |
1223 | 1225 |
1224 } // namespace gcm | 1226 } // namespace gcm |
OLD | NEW |