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

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

Issue 378643002: [GCM] Check-in with signed in accounts associates device to user (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing compilation issue on android Created 6 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 side-by-side diff with in-line comments
Download patch
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 e27e82e6ce273b4fa8f2805185e4b29364418801..ce6a219a9f6ed191f6d81215bf67264540dafc98 100644
--- a/google_apis/gcm/engine/gcm_store_impl.cc
+++ b/google_apis/gcm/engine/gcm_store_impl.cc
@@ -63,6 +63,8 @@ const char kGServiceSettingKeyStart[] = "gservice1-";
const char kGServiceSettingKeyEnd[] = "gservice2-";
// Key for digest of the last G-services settings update.
const char kGServiceSettingsDigestKey[] = "gservices_digest";
+// Key used to indicate how many accounts were last checked in with this device.
+const char kLastCheckinAccountsKey[] = "last_checkin_accounts_count";
// Key used to timestamp last checkin (marked with G services settings update).
const char kLastCheckinTimeKey[] = "last_checkin_time";
@@ -138,7 +140,8 @@ class GCMStoreImpl::Backend
const UpdateCallback& callback);
void RemoveUserSerialNumber(const std::string& username,
const UpdateCallback& callback);
- void SetLastCheckinTime(const base::Time& last_checkin_time,
+ void SetLastCheckinInfo(const base::Time& last_checkin_time,
+ uint64 accounts_count,
const UpdateCallback& callback);
void SetGServicesSettings(
const std::map<std::string, std::string>& settings,
@@ -153,7 +156,8 @@ class GCMStoreImpl::Backend
bool LoadRegistrations(RegistrationInfoMap* registrations);
bool LoadIncomingMessages(std::vector<std::string>* incoming_messages);
bool LoadOutgoingMessages(OutgoingMessageMap* outgoing_messages);
- bool LoadLastCheckinTime(base::Time* last_checkin_time);
+ bool LoadLastCheckinInfo(base::Time* last_checkin_time,
+ uint64* accounts_count);
bool LoadGServicesSettings(std::map<std::string, std::string>* settings,
std::string* digest);
@@ -206,7 +210,8 @@ void GCMStoreImpl::Backend::Load(const LoadCallback& callback) {
!LoadRegistrations(&result->registrations) ||
!LoadIncomingMessages(&result->incoming_messages) ||
!LoadOutgoingMessages(&result->outgoing_messages) ||
- !LoadLastCheckinTime(&result->last_checkin_time) ||
+ !LoadLastCheckinInfo(&result->last_checkin_time,
+ &result->accounts_count) ||
!LoadGServicesSettings(&result->gservices_settings,
&result->gservices_digest)) {
result->device_android_id = 0;
@@ -485,20 +490,25 @@ void GCMStoreImpl::Backend::RemoveOutgoingMessages(
AppIdToMessageCountMap()));
}
-void GCMStoreImpl::Backend::SetLastCheckinTime(
+void GCMStoreImpl::Backend::SetLastCheckinInfo(
const base::Time& last_checkin_time,
+ uint64 accounts_count,
const UpdateCallback& callback) {
- leveldb::WriteOptions write_options;
- write_options.sync = true;
+ leveldb::WriteBatch write_batch;
int64 last_checkin_time_internal = last_checkin_time.ToInternalValue();
- const leveldb::Status s =
- db_->Put(write_options,
- MakeSlice(kLastCheckinTimeKey),
- MakeSlice(base::Int64ToString(last_checkin_time_internal)));
+ write_batch.Put(MakeSlice(kLastCheckinTimeKey),
+ MakeSlice(base::Int64ToString(last_checkin_time_internal)));
+
+ write_batch.Put(MakeSlice(kLastCheckinAccountsKey),
+ MakeSlice(base::Uint64ToString(accounts_count)));
+
+ leveldb::WriteOptions write_options;
+ write_options.sync = true;
+ const leveldb::Status s = db_->Write(write_options, &write_batch);
if (!s.ok())
- LOG(ERROR) << "LevelDB set last checkin time failed: " << s.ToString();
+ LOG(ERROR) << "LevelDB set last checkin info failed: " << s.ToString();
foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, s.ok()));
}
@@ -655,8 +665,8 @@ bool GCMStoreImpl::Backend::LoadOutgoingMessages(
return true;
}
-bool GCMStoreImpl::Backend::LoadLastCheckinTime(
- base::Time* last_checkin_time) {
+bool GCMStoreImpl::Backend::LoadLastCheckinInfo(base::Time* last_checkin_time,
+ uint64* accounts_count) {
leveldb::ReadOptions read_options;
read_options.verify_checksums = true;
@@ -672,6 +682,12 @@ bool GCMStoreImpl::Backend::LoadLastCheckinTime(
// want that situation to cause the whole load to fail.
*last_checkin_time = base::Time::FromInternalValue(time_internal);
+ s = db_->Get(read_options, MakeSlice(kLastCheckinAccountsKey), &result);
+ if (s.ok() && !base::StringToUint64(result, accounts_count)) {
+ DVLOG(1) << "Last account count not set. Defaulting to 0.";
+ *accounts_count = 0;
+ }
+
return true;
}
@@ -877,13 +893,15 @@ void GCMStoreImpl::RemoveOutgoingMessages(
callback)));
}
-void GCMStoreImpl::SetLastCheckinTime(const base::Time& last_checkin_time,
+void GCMStoreImpl::SetLastCheckinInfo(const base::Time& last_checkin_time,
+ uint64 accounts_count,
const UpdateCallback& callback) {
blocking_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&GCMStoreImpl::Backend::SetLastCheckinTime,
+ base::Bind(&GCMStoreImpl::Backend::SetLastCheckinInfo,
backend_,
last_checkin_time,
+ accounts_count,
callback));
}

Powered by Google App Engine
This is Rietveld 408576698