Commit a84cf0f9 authored by rsimha@chromium.org's avatar rsimha@chromium.org

[Sync] Avoid unnecessary DB rewrite for TokenService credentials that were just read from DB

When the token service is initialized, tokens are read from disk via LoadTokensFromDB. The callback for this function after the DB read completes is LoadTokensIntoMemory.

When LoadTokensIntoMemory is run, it calls UpdateCredentials, which implicitly rewrites the just-read credentials back to the DB. This DB write is unnecessary. An unintended side effect is that the credential caching service does an unnecessary file-write to "Sync Credentials" every single time Chrome is restarted, even though the sync credentials haven't changed in any way.

This patch modifies LoadTokensIntoMemory to merely update |credentials_|, the in-memory credentials object, without updating the DB too.

BUG=139263
TEST=unit_tests; Sign in to sync, restart chrome, and make sure TokenService credentials are not re-written to DB during initialization.


Review URL: https://chromiumcodereview.appspot.com/10829051

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148863 0039d316-1c4b-4281-b951-d872f2087c98
parent 9445d561
......@@ -347,6 +347,11 @@ void TokenService::OnWebDataServiceRequestDone(WebDataService::Handle h,
void TokenService::LoadTokensIntoMemory(
const std::map<std::string, std::string>& db_tokens,
std::map<std::string, std::string>* in_memory_tokens) {
// Ensure that there are no active fetchers at the time we first load
// tokens from the DB into memory.
for (size_t i = 0; i < arraysize(kServices); ++i) {
DCHECK(NULL == fetchers_[i].get());
}
for (size_t i = 0; i < arraysize(kServices); i++) {
LoadSingleTokenIntoMemory(db_tokens, in_memory_tokens, kServices[i]);
......@@ -369,10 +374,10 @@ void TokenService::LoadTokensIntoMemory(
sid = db_tokens.find(GaiaConstants::kGaiaSid)->second;
if (!lsid.empty() && !sid.empty()) {
UpdateCredentials(GaiaAuthConsumer::ClientLoginResult(sid,
lsid,
std::string(),
std::string()));
credentials_ = GaiaAuthConsumer::ClientLoginResult(sid,
lsid,
std::string(),
std::string());
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment