summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorjianli <jianli@chromium.org>2015-06-16 12:39:34 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-16 19:40:12 +0000
commit9f9a73672ab60c3da17bd4ff2660ce3a113cd8fa (patch)
treeda3b365af1fc7db09c5447c8937b33b5de45c566 /google_apis
parent345aa4682f6e2c41892ad1d16a0e0a9b2be37d26 (diff)
downloadchromium_src-9f9a73672ab60c3da17bd4ff2660ce3a113cd8fa.zip
chromium_src-9f9a73672ab60c3da17bd4ff2660ce3a113cd8fa.tar.gz
chromium_src-9f9a73672ab60c3da17bd4ff2660ce3a113cd8fa.tar.bz2
Do not create GCM store if it is not needed
BUG=499006 TEST=new tests Review URL: https://codereview.chromium.org/1183843002 Cr-Commit-Position: refs/heads/master@{#334661}
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/gcm/engine/gcm_store.cc2
-rw-r--r--google_apis/gcm/engine/gcm_store.h8
-rw-r--r--google_apis/gcm/engine/gcm_store_impl.cc26
-rw-r--r--google_apis/gcm/engine/gcm_store_impl.h2
-rw-r--r--google_apis/gcm/engine/gcm_store_impl_unittest.cc220
-rw-r--r--google_apis/gcm/engine/mcs_client_unittest.cc2
-rw-r--r--google_apis/gcm/tools/mcs_probe.cc3
7 files changed, 122 insertions, 141 deletions
diff --git a/google_apis/gcm/engine/gcm_store.cc b/google_apis/gcm/engine/gcm_store.cc
index c698528..a1871b9 100644
--- a/google_apis/gcm/engine/gcm_store.cc
+++ b/google_apis/gcm/engine/gcm_store.cc
@@ -8,6 +8,7 @@ namespace gcm {
GCMStore::LoadResult::LoadResult()
: success(false),
+ store_does_not_exist(false),
device_android_id(0),
device_security_token(0) {
}
@@ -28,6 +29,7 @@ void GCMStore::LoadResult::Reset() {
account_mappings.clear();
heartbeat_intervals.clear();
success = false;
+ store_does_not_exist = false;
instance_id_data.clear();
}
diff --git a/google_apis/gcm/engine/gcm_store.h b/google_apis/gcm/engine/gcm_store.h
index 83ec73d..9375882 100644
--- a/google_apis/gcm/engine/gcm_store.h
+++ b/google_apis/gcm/engine/gcm_store.h
@@ -29,6 +29,11 @@ class MCSMessage;
// as well as store device and user checkin information.
class GCM_EXPORT GCMStore {
public:
+ enum StoreOpenMode {
+ DO_NOT_CREATE,
+ CREATE_IF_MISSING
+ };
+
// Map of message id to message data for outgoing messages.
typedef std::map<std::string, linked_ptr<google::protobuf::MessageLite> >
OutgoingMessageMap;
@@ -44,6 +49,7 @@ class GCM_EXPORT GCMStore {
void Reset();
bool success;
+ bool store_does_not_exist;
uint64 device_android_id;
uint64 device_security_token;
std::map<std::string, std::string> registrations;
@@ -68,7 +74,7 @@ class GCM_EXPORT GCMStore {
// Load the data from persistent store and pass the initial state back to
// caller.
- virtual void Load(const LoadCallback& callback) = 0;
+ virtual void Load(StoreOpenMode open_mode, const LoadCallback& callback) = 0;
// Close the persistent store.
virtual void Close() = 0;
diff --git a/google_apis/gcm/engine/gcm_store_impl.cc b/google_apis/gcm/engine/gcm_store_impl.cc
index 1743d13..3b9dd0a 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)));
diff --git a/google_apis/gcm/engine/gcm_store_impl.h b/google_apis/gcm/engine/gcm_store_impl.h
index 8feebff..af89cff 100644
--- a/google_apis/gcm/engine/gcm_store_impl.h
+++ b/google_apis/gcm/engine/gcm_store_impl.h
@@ -31,7 +31,7 @@ class GCM_EXPORT GCMStoreImpl : public GCMStore {
~GCMStoreImpl() override;
// Load the directory and pass the initial state back to caller.
- void Load(const LoadCallback& callback) override;
+ void Load(StoreOpenMode open_mode, const LoadCallback& callback) override;
// Closes the GCM store.
void Close() override;
diff --git a/google_apis/gcm/engine/gcm_store_impl_unittest.cc b/google_apis/gcm/engine/gcm_store_impl_unittest.cc
index 2fe64b4..2b0c401 100644
--- a/google_apis/gcm/engine/gcm_store_impl_unittest.cc
+++ b/google_apis/gcm/engine/gcm_store_impl_unittest.cc
@@ -47,6 +47,8 @@ class GCMStoreImplTest : public testing::Test {
~GCMStoreImplTest() override;
scoped_ptr<GCMStoreImpl> BuildGCMStore();
+ void LoadGCMStore(
+ GCMStoreImpl* gcm_store, scoped_ptr<GCMStore::LoadResult>* result_dst);
std::string GetNextPersistentId();
@@ -54,6 +56,8 @@ class GCMStoreImplTest : public testing::Test {
void LoadCallback(scoped_ptr<GCMStore::LoadResult>* result_dst,
scoped_ptr<GCMStore::LoadResult> result);
+ void LoadWithoutCheckCallback(scoped_ptr<GCMStore::LoadResult>* result_dst,
+ scoped_ptr<GCMStore::LoadResult> result);
void UpdateCallback(bool success);
protected:
@@ -75,11 +79,24 @@ GCMStoreImplTest::~GCMStoreImplTest() {}
scoped_ptr<GCMStoreImpl> GCMStoreImplTest::BuildGCMStore() {
return scoped_ptr<GCMStoreImpl>(new GCMStoreImpl(
- temp_directory_.path(),
+ // Pass an non-existent directory as store path to match the exact
+ // behavior in the production code. Currently GCMStoreImpl checks if
+ // the directory exist or not to determine the store existence.
+ temp_directory_.path().Append(FILE_PATH_LITERAL("GCM Store")),
message_loop_.message_loop_proxy(),
make_scoped_ptr<Encryptor>(new FakeEncryptor)));
}
+void GCMStoreImplTest::LoadGCMStore(
+ GCMStoreImpl* gcm_store, scoped_ptr<GCMStore::LoadResult>* result_dst) {
+ gcm_store->Load(
+ GCMStore::CREATE_IF_MISSING,
+ base::Bind(&GCMStoreImplTest::LoadCallback,
+ base::Unretained(this),
+ result_dst));
+ PumpLoop();
+}
+
std::string GCMStoreImplTest::GetNextPersistentId() {
return base::Uint64ToString(next_persistent_id_++);
}
@@ -90,6 +107,12 @@ void GCMStoreImplTest::LoadCallback(
scoped_ptr<GCMStore::LoadResult>* result_dst,
scoped_ptr<GCMStore::LoadResult> result) {
ASSERT_TRUE(result->success);
+ LoadWithoutCheckCallback(result_dst, result.Pass());
+}
+
+void GCMStoreImplTest::LoadWithoutCheckCallback(
+ scoped_ptr<GCMStore::LoadResult>* result_dst,
+ scoped_ptr<GCMStore::LoadResult> result) {
*result_dst = result.Pass();
run_loop_->Quit();
run_loop_.reset(new base::RunLoop());
@@ -101,11 +124,9 @@ void GCMStoreImplTest::UpdateCallback(bool success) {
// Verify creating a new database and loading it.
TEST_F(GCMStoreImplTest, LoadNew) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(0U, load_result->device_android_id);
EXPECT_EQ(0U, load_result->device_security_token);
@@ -115,13 +136,26 @@ TEST_F(GCMStoreImplTest, LoadNew) {
EXPECT_EQ(base::Time::FromInternalValue(0LL), load_result->last_checkin_time);
}
-TEST_F(GCMStoreImplTest, DeviceCredentials) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+// Verify new database is not created when DO_NOT_CREATE_NEW_STORE is passed.
+TEST_F(GCMStoreImplTest, LoadWithoutCreatingNewStore) {
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
+ gcm_store->Load(
+ GCMStore::DO_NOT_CREATE,
+ base::Bind(&GCMStoreImplTest::LoadWithoutCheckCallback,
+ base::Unretained(this),
+ &load_result));
PumpLoop();
+ EXPECT_FALSE(load_result->success);
+ EXPECT_TRUE(load_result->store_does_not_exist);
+}
+
+TEST_F(GCMStoreImplTest, DeviceCredentials) {
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStore::LoadResult> load_result;
+ LoadGCMStore(gcm_store.get(), &load_result);
+
gcm_store->SetDeviceCredentials(
kDeviceId,
kDeviceToken,
@@ -129,9 +163,7 @@ TEST_F(GCMStoreImplTest, DeviceCredentials) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(kDeviceId, load_result->device_android_id);
ASSERT_EQ(kDeviceToken, load_result->device_security_token);
@@ -140,9 +172,7 @@ TEST_F(GCMStoreImplTest, DeviceCredentials) {
TEST_F(GCMStoreImplTest, LastCheckinInfo) {
scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
base::Time last_checkin_time = base::Time::Now();
std::set<std::string> accounts;
@@ -156,9 +186,7 @@ TEST_F(GCMStoreImplTest, LastCheckinInfo) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(last_checkin_time, load_result->last_checkin_time);
ASSERT_EQ(accounts, load_result->last_checkin_accounts);
@@ -170,18 +198,14 @@ TEST_F(GCMStoreImplTest, LastCheckinInfo) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(base::Time(), load_result->last_checkin_time);
}
TEST_F(GCMStoreImplTest, GServicesSettings_ProtocolV2) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
std::map<std::string, std::string> settings;
settings["checkin_interval"] = "12345";
@@ -196,9 +220,7 @@ TEST_F(GCMStoreImplTest, GServicesSettings_ProtocolV2) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(settings, load_result->gservices_settings);
ASSERT_EQ(digest, load_result->gservices_digest);
@@ -216,20 +238,16 @@ TEST_F(GCMStoreImplTest, GServicesSettings_ProtocolV2) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(settings, load_result->gservices_settings);
ASSERT_EQ(digest, load_result->gservices_digest);
}
TEST_F(GCMStoreImplTest, Registrations) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
// Add one registration with one sender.
std::string registration = "sender1=registration1";
@@ -248,9 +266,7 @@ TEST_F(GCMStoreImplTest, Registrations) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(2u, load_result->registrations.size());
ASSERT_TRUE(load_result->registrations.find(kAppName) !=
@@ -266,9 +282,7 @@ TEST_F(GCMStoreImplTest, Registrations) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(1u, load_result->registrations.size());
ASSERT_TRUE(load_result->registrations.find(kAppName) !=
@@ -279,11 +293,9 @@ TEST_F(GCMStoreImplTest, Registrations) {
// Verify saving some incoming messages, reopening the directory, and then
// removing those incoming messages.
TEST_F(GCMStoreImplTest, IncomingMessages) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
std::vector<std::string> persistent_ids;
for (int i = 0; i < kNumPersistentIds; ++i) {
@@ -295,9 +307,7 @@ TEST_F(GCMStoreImplTest, IncomingMessages) {
}
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(persistent_ids, load_result->incoming_messages);
ASSERT_TRUE(load_result->outgoing_messages.empty());
@@ -309,9 +319,7 @@ TEST_F(GCMStoreImplTest, IncomingMessages) {
gcm_store = BuildGCMStore().Pass();
load_result->incoming_messages.clear();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_TRUE(load_result->incoming_messages.empty());
ASSERT_TRUE(load_result->outgoing_messages.empty());
@@ -320,11 +328,9 @@ TEST_F(GCMStoreImplTest, IncomingMessages) {
// Verify saving some outgoing messages, reopening the directory, and then
// removing those outgoing messages.
TEST_F(GCMStoreImplTest, OutgoingMessages) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
std::vector<std::string> persistent_ids;
const int kNumPersistentIds = 10;
@@ -341,9 +347,7 @@ TEST_F(GCMStoreImplTest, OutgoingMessages) {
}
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_TRUE(load_result->incoming_messages.empty());
ASSERT_EQ(load_result->outgoing_messages.size(), persistent_ids.size());
@@ -364,9 +368,7 @@ TEST_F(GCMStoreImplTest, OutgoingMessages) {
gcm_store = BuildGCMStore().Pass();
load_result->outgoing_messages.clear();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_TRUE(load_result->incoming_messages.empty());
ASSERT_TRUE(load_result->outgoing_messages.empty());
@@ -374,11 +376,9 @@ TEST_F(GCMStoreImplTest, OutgoingMessages) {
// Verify incoming and outgoing messages don't conflict.
TEST_F(GCMStoreImplTest, IncomingAndOutgoingMessages) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
std::vector<std::string> persistent_ids;
const int kNumPersistentIds = 10;
@@ -400,9 +400,7 @@ TEST_F(GCMStoreImplTest, IncomingAndOutgoingMessages) {
}
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(persistent_ids, load_result->incoming_messages);
ASSERT_EQ(load_result->outgoing_messages.size(), persistent_ids.size());
@@ -428,9 +426,7 @@ TEST_F(GCMStoreImplTest, IncomingAndOutgoingMessages) {
gcm_store = BuildGCMStore().Pass();
load_result->incoming_messages.clear();
load_result->outgoing_messages.clear();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_TRUE(load_result->incoming_messages.empty());
ASSERT_TRUE(load_result->outgoing_messages.empty());
@@ -439,11 +435,9 @@ TEST_F(GCMStoreImplTest, IncomingAndOutgoingMessages) {
// Test that per-app message limits are enforced, persisted across restarts,
// and updated as messages are removed.
TEST_F(GCMStoreImplTest, PerAppMessageLimits) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
- base::Unretained(this),
- &load_result));
+ LoadGCMStore(gcm_store.get(), &load_result);
// Add the initial (below app limit) messages.
for (int i = 0; i < kNumMessagesPerApp; ++i) {
@@ -473,10 +467,7 @@ TEST_F(GCMStoreImplTest, PerAppMessageLimits) {
// Tear down and restore the database.
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
- base::Unretained(this),
- &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
// Adding more messages should still fail.
for (int i = 0; i < kNumMessagesPerApp; ++i) {
@@ -515,10 +506,9 @@ TEST_F(GCMStoreImplTest, PerAppMessageLimits) {
}
TEST_F(GCMStoreImplTest, AccountMapping) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
+ LoadGCMStore(gcm_store.get(), &load_result);
// Add account mappings.
AccountMapping account_mapping1;
@@ -548,9 +538,7 @@ TEST_F(GCMStoreImplTest, AccountMapping) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(2UL, load_result->account_mappings.size());
GCMStore::AccountMappings::iterator iter =
@@ -577,9 +565,7 @@ TEST_F(GCMStoreImplTest, AccountMapping) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(1UL, load_result->account_mappings.size());
iter = load_result->account_mappings.begin();
@@ -593,10 +579,9 @@ TEST_F(GCMStoreImplTest, AccountMapping) {
}
TEST_F(GCMStoreImplTest, HeartbeatInterval) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
+ LoadGCMStore(gcm_store.get(), &load_result);
std::string scope1 = "scope1";
std::string scope2 = "scope2";
@@ -615,9 +600,7 @@ TEST_F(GCMStoreImplTest, HeartbeatInterval) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(2UL, load_result->heartbeat_intervals.size());
ASSERT_TRUE(load_result->heartbeat_intervals.find(scope1) !=
@@ -633,9 +616,7 @@ TEST_F(GCMStoreImplTest, HeartbeatInterval) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(1UL, load_result->heartbeat_intervals.size());
ASSERT_TRUE(load_result->heartbeat_intervals.find(scope1) !=
@@ -647,12 +628,9 @@ TEST_F(GCMStoreImplTest, HeartbeatInterval) {
// same time, they per-app message counts should not go up, as failures should
// result in decrementing the counts.
TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
- base::Unretained(this),
- &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
gcm_store->Destroy(base::Bind(&GCMStoreImplTest::UpdateCallback,
base::Unretained(this)));
PumpLoop();
@@ -673,28 +651,20 @@ TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) {
}
TEST_F(GCMStoreImplTest, ReloadAfterClose) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
- base::Unretained(this),
- &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
gcm_store->Close();
PumpLoop();
- gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
- base::Unretained(this),
- &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
}
TEST_F(GCMStoreImplTest, LastTokenFetchTime) {
scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(base::Time(), load_result->last_token_fetch_time);
base::Time last_token_fetch_time = base::Time::Now();
@@ -704,9 +674,7 @@ TEST_F(GCMStoreImplTest, LastTokenFetchTime) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(last_token_fetch_time, load_result->last_token_fetch_time);
// Negative cases, where the value read is gibberish.
@@ -717,18 +685,14 @@ TEST_F(GCMStoreImplTest, LastTokenFetchTime) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
EXPECT_EQ(base::Time(), load_result->last_token_fetch_time);
}
TEST_F(GCMStoreImplTest, InstanceIDData) {
- scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStoreImpl> gcm_store(BuildGCMStore());
scoped_ptr<GCMStore::LoadResult> load_result;
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
std::string instance_id_data("Foo");
gcm_store->AddInstanceIDData(
@@ -745,9 +709,7 @@ TEST_F(GCMStoreImplTest, InstanceIDData) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(2u, load_result->instance_id_data.size());
ASSERT_TRUE(load_result->instance_id_data.find(kAppName) !=
@@ -763,9 +725,7 @@ TEST_F(GCMStoreImplTest, InstanceIDData) {
PumpLoop();
gcm_store = BuildGCMStore().Pass();
- gcm_store->Load(base::Bind(
- &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result));
- PumpLoop();
+ LoadGCMStore(gcm_store.get(), &load_result);
ASSERT_EQ(1u, load_result->instance_id_data.size());
ASSERT_TRUE(load_result->instance_id_data.find(kAppName2) !=
diff --git a/google_apis/gcm/engine/mcs_client_unittest.cc b/google_apis/gcm/engine/mcs_client_unittest.cc
index 644c702..44d8bc3 100644
--- a/google_apis/gcm/engine/mcs_client_unittest.cc
+++ b/google_apis/gcm/engine/mcs_client_unittest.cc
@@ -198,7 +198,7 @@ void MCSClientTest::BuildMCSClient() {
}
void MCSClientTest::InitializeClient() {
- gcm_store_->Load(base::Bind(
+ gcm_store_->Load(GCMStore::CREATE_IF_MISSING, base::Bind(
&MCSClient::Initialize,
base::Unretained(mcs_client_.get()),
base::Bind(&MCSClientTest::ErrorCallback,
diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc
index 8121f7c..e1bd244 100644
--- a/google_apis/gcm/tools/mcs_probe.cc
+++ b/google_apis/gcm/tools/mcs_probe.cc
@@ -307,7 +307,8 @@ void MCSProbe::Start() {
gcm_store_.get(),
&recorder_));
run_loop_.reset(new base::RunLoop());
- gcm_store_->Load(base::Bind(&MCSProbe::LoadCallback,
+ gcm_store_->Load(GCMStore::CREATE_IF_MISSING,
+ base::Bind(&MCSProbe::LoadCallback,
base::Unretained(this)));
run_loop_->Run();
}