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

Unified Diff: chrome/browser/signin/about_signin_internals.cc

Issue 14888003: [Sync] Log age of auth tokens on authentication failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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: chrome/browser/signin/about_signin_internals.cc
diff --git a/chrome/browser/signin/about_signin_internals.cc b/chrome/browser/signin/about_signin_internals.cc
index e58a013dd2e198286a570698047579962a3cce97..d88e116a029c9d6b9e9e4715af4c23f8e9223759 100644
--- a/chrome/browser/signin/about_signin_internals.cc
+++ b/chrome/browser/signin/about_signin_internals.cc
@@ -20,13 +20,22 @@
using namespace signin_internals_util;
+namespace {
+
+std::string TimeToFriendlyStr(base::Time time) {
tim (not reviewing) 2013/05/03 00:46:43 const& ?
Nicolas Zea 2013/05/03 01:31:41 Done.
+ if (time.is_null())
+ return "";
tim (not reviewing) 2013/05/03 00:46:43 prefer std::string()
Nicolas Zea 2013/05/03 01:31:41 Done.
+ return UTF16ToUTF8(base::TimeFormatFriendlyDate(time));
+}
+
+} // namespace
+
AboutSigninInternals::AboutSigninInternals() : profile_(NULL) {
// Initialize default values for tokens.
for (size_t i = 0; i < kNumTokenPrefs; ++i) {
signin_status_.token_info_map.insert(std::pair<std::string, TokenInfo>(
kTokenPrefsArray[i],
- TokenInfo(
- std::string(), "Not Loaded", std::string(), kTokenPrefsArray[i])));
+ TokenInfo("", "Not Loaded", "", 0, kTokenPrefsArray[i])));
tim (not reviewing) 2013/05/03 00:46:43 std::string() was a better choice than "".
Nicolas Zea 2013/05/03 01:31:41 Done.
}
}
@@ -66,15 +75,15 @@ void AboutSigninInternals::NotifySigninValueChanged(
DCHECK(field_index >= 0 &&
field_index < signin_status_.timed_signin_fields.size());
- std::string time_as_str = UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
- base::Time::NowFromSystemTime()));
+ base::Time now = base::Time::NowFromSystemTime();
tim (not reviewing) 2013/05/03 00:46:43 nit - there's a whole pile of base::Times in here.
Nicolas Zea 2013/05/03 01:31:41 Done.
+ std::string time_as_str = TimeToFriendlyStr(now);
TimedSigninStatusValue timed_value(value, time_as_str);
signin_status_.timed_signin_fields[field_index] = timed_value;
// Also persist these values in the prefs.
const std::string value_pref = SigninStatusFieldToString(field) + ".value";
- const std::string time_pref = SigninStatusFieldToString(field) + ".time";
+ const std::string time_pref = SigninStatusFieldToString(field) + ".time";
profile_->GetPrefs()->SetString(value_pref.c_str(), value);
profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str);
@@ -111,10 +120,12 @@ void AboutSigninInternals::RefreshSigninPrefs() {
const std::string value = pref + ".value";
const std::string status = pref + ".status";
const std::string time = pref + ".time";
+ const std::string time_internal = pref + ".time_internal";
tim (not reviewing) 2013/05/03 00:46:43 What's with the local consts :P
Nicolas Zea 2013/05/03 01:31:41 I was tempted to get rid of them!
TokenInfo token_info(pref_service->GetString(value.c_str()),
pref_service->GetString(status.c_str()),
pref_service->GetString(time.c_str()),
+ pref_service->GetInt64(time_internal.c_str()),
kTokenPrefsArray[i]);
signin_status_.token_info_map[kTokenPrefsArray[i]] = token_info;
@@ -137,16 +148,21 @@ void AboutSigninInternals::NotifyTokenReceivedSuccess(
// Also update preferences.
const std::string value_pref = TokenPrefPath(token_name) + ".value";
const std::string time_pref = TokenPrefPath(token_name) + ".time";
+ const std::string time_internal_pref =
+ TokenPrefPath(token_name) + ".time_internal";
const std::string status_pref = TokenPrefPath(token_name) + ".status";
profile_->GetPrefs()->SetString(value_pref.c_str(), token);
profile_->GetPrefs()->SetString(status_pref.c_str(), "Successful");
// Update timestamp if needed.
if (update_time) {
- const std::string time_as_str = UTF16ToUTF8(
- base::TimeFormatFriendlyDateAndTime(base::Time::NowFromSystemTime()));
+ base::Time now = base::Time::NowFromSystemTime();
+ int64 time_as_int = now.ToInternalValue();
+ const std::string time_as_str = TimeToFriendlyStr(now);
signin_status_.token_info_map[token_name].time = time_as_str;
+ signin_status_.token_info_map[token_name].time_internal = time_as_int;
profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str);
+ profile_->GetPrefs()->SetInt64(time_internal_pref.c_str(), time_as_int);
}
NotifyObservers();
@@ -156,9 +172,9 @@ void AboutSigninInternals::NotifyTokenReceivedSuccess(
void AboutSigninInternals::NotifyTokenReceivedFailure(
const std::string& token_name,
const std::string& error) {
- const std::string time_as_str =
- UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
- base::Time::NowFromSystemTime()));
+ base::Time now = base::Time::NowFromSystemTime();
+ int64 time_as_int = now.ToInternalValue();
+ const std::string time_as_str = TimeToFriendlyStr(now);
// This should have been initialized already.
DCHECK(signin_status_.token_info_map.count(token_name));
@@ -166,13 +182,17 @@ void AboutSigninInternals::NotifyTokenReceivedFailure(
signin_status_.token_info_map[token_name].token.clear();
signin_status_.token_info_map[token_name].status = error;
signin_status_.token_info_map[token_name].time = time_as_str;
+ signin_status_.token_info_map[token_name].time_internal = time_as_int;
// Also update preferences.
const std::string value_pref = TokenPrefPath(token_name) + ".value";
const std::string time_pref = TokenPrefPath(token_name) + ".time";
+ const std::string time_internal_pref =
+ TokenPrefPath(token_name) + ".time_internal";
const std::string status_pref = TokenPrefPath(token_name) + ".status";
profile_->GetPrefs()->SetString(value_pref.c_str(), std::string());
profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str);
+ profile_->GetPrefs()->SetInt64(time_internal_pref.c_str(), time_as_int);
profile_->GetPrefs()->SetString(status_pref.c_str(), error);
NotifyObservers();
@@ -220,3 +240,12 @@ void AboutSigninInternals::NotifyObservers() {
scoped_ptr<DictionaryValue> AboutSigninInternals::GetSigninStatus() {
return signin_status_.ToValue().Pass();
}
+
+base::Time AboutSigninInternals::GetTokenTime(
+ const std::string& token_name) const {
+ TokenInfoMap::const_iterator iter =
+ signin_status_.token_info_map.find(token_name);
+ if (iter == signin_status_.token_info_map.end())
+ return base::Time();
+ return base::Time::FromInternalValue(iter->second.time_internal);
+}

Powered by Google App Engine
This is Rietveld 408576698