Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: google_apis/gcm/engine/gcm_store_impl.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Rebase; add comments to CHECK() Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 GCMStoreImpl::Backend::~Backend() {} 285 GCMStoreImpl::Backend::~Backend() {}
286 286
287 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(StoreOpenMode open_mode, 287 LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(StoreOpenMode open_mode,
288 LoadResult* result) { 288 LoadResult* result) {
289 LoadStatus load_status; 289 LoadStatus load_status;
290 if (db_.get()) { 290 if (db_.get()) {
291 LOG(ERROR) << "Attempting to reload open database."; 291 LOG(ERROR) << "Attempting to reload open database.";
292 return RELOADING_OPEN_STORE; 292 return RELOADING_OPEN_STORE;
293 } 293 }
294 294
295 // Checks if the store exists or not. Calling DB::Open with create_if_missing 295 // Checks if the store exists or not. Opening a db with create_if_missing
296 // not set will still create a new directory if the store does not exist. 296 // not set will still create a new directory if the store does not exist.
297 if (open_mode == DO_NOT_CREATE && !DatabaseExists(path_)) { 297 if (open_mode == DO_NOT_CREATE && !DatabaseExists(path_)) {
298 DVLOG(2) << "Database " << path_.value() << " does not exist"; 298 DVLOG(2) << "Database " << path_.value() << " does not exist";
299 return STORE_DOES_NOT_EXIST; 299 return STORE_DOES_NOT_EXIST;
300 } 300 }
301 301
302 leveldb::Options options; 302 leveldb::Options options;
303 options.create_if_missing = open_mode == CREATE_IF_MISSING; 303 options.create_if_missing = open_mode == CREATE_IF_MISSING;
304 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; 304 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
305 options.paranoid_checks = true; 305 options.paranoid_checks = true;
306 leveldb::DB* db;
307 leveldb::Status status = 306 leveldb::Status status =
308 leveldb::DB::Open(options, path_.AsUTF8Unsafe(), &db); 307 leveldb_env::OpenDB(options, path_.AsUTF8Unsafe(), &db_);
309 UMA_HISTOGRAM_ENUMERATION("GCM.Database.Open", 308 UMA_HISTOGRAM_ENUMERATION("GCM.Database.Open",
310 leveldb_env::GetLevelDBStatusUMAValue(status), 309 leveldb_env::GetLevelDBStatusUMAValue(status),
311 leveldb_env::LEVELDB_STATUS_MAX); 310 leveldb_env::LEVELDB_STATUS_MAX);
312 if (!status.ok()) { 311 if (!status.ok()) {
313 LOG(ERROR) << "Failed to open database " << path_.value() << ": " 312 LOG(ERROR) << "Failed to open database " << path_.value() << ": "
314 << status.ToString(); 313 << status.ToString();
315 return OPENING_STORE_FAILED; 314 return OPENING_STORE_FAILED;
316 } 315 }
317 316
318 db_.reset(db);
319 if (!LoadDeviceCredentials(&result->device_android_id, 317 if (!LoadDeviceCredentials(&result->device_android_id,
320 &result->device_security_token)) { 318 &result->device_security_token)) {
321 return LOADING_DEVICE_CREDENTIALS_FAILED; 319 return LOADING_DEVICE_CREDENTIALS_FAILED;
322 } 320 }
323 if (!LoadRegistrations(&result->registrations)) 321 if (!LoadRegistrations(&result->registrations))
324 return LOADING_REGISTRATION_FAILED; 322 return LOADING_REGISTRATION_FAILED;
325 if (!LoadIncomingMessages(&result->incoming_messages)) 323 if (!LoadIncomingMessages(&result->incoming_messages))
326 return LOADING_INCOMING_MESSAGES_FAILED; 324 return LOADING_INCOMING_MESSAGES_FAILED;
327 if (!LoadOutgoingMessages(&result->outgoing_messages)) 325 if (!LoadOutgoingMessages(&result->outgoing_messages))
328 return LOADING_OUTGOING_MESSAGES_FAILED; 326 return LOADING_OUTGOING_MESSAGES_FAILED;
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 removed_message_counts.begin(); 1479 removed_message_counts.begin();
1482 iter != removed_message_counts.end(); ++iter) { 1480 iter != removed_message_counts.end(); ++iter) {
1483 DCHECK_NE(app_message_counts_.count(iter->first), 0U); 1481 DCHECK_NE(app_message_counts_.count(iter->first), 0U);
1484 app_message_counts_[iter->first] -= iter->second; 1482 app_message_counts_[iter->first] -= iter->second;
1485 DCHECK_GE(app_message_counts_[iter->first], 0); 1483 DCHECK_GE(app_message_counts_[iter->first], 0);
1486 } 1484 }
1487 callback.Run(true); 1485 callback.Run(true);
1488 } 1486 }
1489 1487
1490 } // namespace gcm 1488 } // namespace gcm
OLDNEW
« no previous file with comments | « extensions/browser/value_store/leveldb_value_store.cc ('k') | storage/browser/fileapi/sandbox_directory_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698