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

Unified Diff: google_apis/gcm/engine/gcm_store_impl.cc

Issue 1183843002: Do not create GCM store if it is not needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback + fix test Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/gcm/engine/gcm_store_impl.h ('k') | google_apis/gcm/engine/gcm_store_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gcm/engine/gcm_store_impl.cc
diff --git a/google_apis/gcm/engine/gcm_store_impl.cc b/google_apis/gcm/engine/gcm_store_impl.cc
index b90630a0594a85ee85b54fae61ef238fbe5a2a7c..fe9a075bea59eba92fe63b92f10dd2a95b5c09b4 100644
--- a/google_apis/gcm/engine/gcm_store_impl.cc
+++ b/google_apis/gcm/engine/gcm_store_impl.cc
@@ -50,6 +50,7 @@ enum LoadStatus {
LOADING_LAST_TOKEN_TIME_FAILED,
LOADING_HEARTBEAT_INTERVALS_FAILED,
LOADING_INSTANCE_ID_DATA_FAILED,
+ STORE_DOES_NOT_EXIST,
// NOTE: always keep this entry at the end. Add new status types only
// immediately above this line. Make sure to update the corresponding
@@ -185,7 +186,7 @@ class GCMStoreImpl::Backend
scoped_ptr<Encryptor> encryptor);
// Blocking implementations of GCMStoreImpl methods.
- void Load(const LoadCallback& callback);
+ void Load(StoreOpenMode open_mode, const LoadCallback& callback);
void Close();
void Destroy(const UpdateCallback& callback);
void SetDeviceCredentials(uint64 device_android_id,
@@ -243,7 +244,7 @@ class GCMStoreImpl::Backend
friend class base::RefCountedThreadSafe<Backend>;
~Backend();
- LoadStatus OpenStoreAndLoadData(LoadResult* result);
+ LoadStatus OpenStoreAndLoadData(StoreOpenMode open_mode, LoadResult* result);
bool LoadDeviceCredentials(uint64* android_id, uint64* security_token);
bool LoadRegistrations(std::map<std::string, std::string>* registrations);
bool LoadIncomingMessages(std::vector<std::string>* incoming_messages);
@@ -275,15 +276,23 @@ GCMStoreImpl::Backend::Backend(
GCMStoreImpl::Backend::~Backend() {}
-LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(LoadResult* result) {
+LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(StoreOpenMode open_mode,
+ LoadResult* result) {
LoadStatus load_status;
if (db_.get()) {
LOG(ERROR) << "Attempting to reload open database.";
return RELOADING_OPEN_STORE;
}
+ // Checks if the store exists or not. Calling DB::Open with create_if_missing
+ // not set will still create a new directory if the store does not exist.
+ if (open_mode == DO_NOT_CREATE && !base::DirectoryExists(path_)) {
+ DVLOG(2) << "Database " << path_.value() << " does not exist";
+ return STORE_DOES_NOT_EXIST;
+ }
+
leveldb::Options options;
- options.create_if_missing = true;
+ options.create_if_missing = open_mode == CREATE_IF_MISSING;
options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
leveldb::DB* db;
leveldb::Status status =
@@ -325,12 +334,14 @@ LoadStatus GCMStoreImpl::Backend::OpenStoreAndLoadData(LoadResult* result) {
return LOADING_SUCCEEDED;
}
-void GCMStoreImpl::Backend::Load(const LoadCallback& callback) {
+void GCMStoreImpl::Backend::Load(StoreOpenMode open_mode,
+ const LoadCallback& callback) {
scoped_ptr<LoadResult> result(new LoadResult());
- LoadStatus load_status = OpenStoreAndLoadData(result.get());
+ LoadStatus load_status = OpenStoreAndLoadData(open_mode, result.get());
UMA_HISTOGRAM_ENUMERATION("GCM.LoadStatus", load_status, LOAD_STATUS_COUNT);
if (load_status != LOADING_SUCCEEDED) {
result->Reset();
+ result->store_does_not_exist = (load_status == STORE_DOES_NOT_EXIST);
foreground_task_runner_->PostTask(FROM_HERE,
base::Bind(callback,
base::Passed(&result)));
@@ -1156,11 +1167,12 @@ GCMStoreImpl::GCMStoreImpl(
GCMStoreImpl::~GCMStoreImpl() {}
-void GCMStoreImpl::Load(const LoadCallback& callback) {
+void GCMStoreImpl::Load(StoreOpenMode open_mode, const LoadCallback& callback) {
blocking_task_runner_->PostTask(
FROM_HERE,
base::Bind(&GCMStoreImpl::Backend::Load,
backend_,
+ open_mode,
base::Bind(&GCMStoreImpl::LoadContinuation,
weak_ptr_factory_.GetWeakPtr(),
callback)));
« no previous file with comments | « google_apis/gcm/engine/gcm_store_impl.h ('k') | google_apis/gcm/engine/gcm_store_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698