Index: chrome/browser/ui/webui/options/automatic_settings_reset_handler.cc |
diff --git a/chrome/browser/ui/webui/options/automatic_settings_reset_handler.cc b/chrome/browser/ui/webui/options/automatic_settings_reset_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8e011d56736e0ec923a3b234599065ad51eca4fb |
--- /dev/null |
+++ b/chrome/browser/ui/webui/options/automatic_settings_reset_handler.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/options/automatic_settings_reset_handler.h" |
+ |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/prefs/pref_service.h" |
+#include "base/time/time.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/common/pref_names.h" |
+#include "chrome/common/url_constants.h" |
+#include "content/public/browser/web_ui.h" |
+#include "grit/generated_resources.h" |
+ |
+namespace { |
+const int kBannerShowTimeInDays = 5; |
+} |
+ |
+namespace options { |
+ |
+AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {} |
+AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {} |
+ |
+void AutomaticSettingsResetHandler::InitializePage() { |
gab
2014/02/05 15:23:52
Log UMA stat about impression of this UI?
robertshield
2014/02/06 18:56:50
Already done. See JS file.
|
+ PrefService* local_state = g_browser_process->local_state(); |
gab
2014/02/05 15:23:52
const (or simply inline the call since you only ne
robertshield
2014/02/06 18:56:50
Done.
|
+ int64 reset_time = |
+ local_state->GetInt64(prefs::kProfilePreferenceResetTime); |
+ if (reset_time != 0) { |
+ base::Time now = base::Time::Now(); |
gab
2014/02/05 15:23:52
const
robertshield
2014/02/06 18:56:50
Done.
|
+ base::Time then = base::Time::FromInternalValue(reset_time); |
gab
2014/02/05 15:23:52
const
robertshield
2014/02/06 18:56:50
Done.
|
+ if ((now - then).InDays() < kBannerShowTimeInDays) { |
+ web_ui()->CallJavascriptFunction("AutomaticSettingsResetBanner.show"); |
+ } |
gab
2014/02/05 15:23:52
remove {}
robertshield
2014/02/06 18:56:50
Done.
|
+ } |
+} |
+ |
+void AutomaticSettingsResetHandler::GetLocalizedValues( |
+ base::DictionaryValue* localized_strings) { |
+ DCHECK(localized_strings); |
+ |
+ static OptionsStringResource resources[] = { |
gab
2014/02/05 15:23:52
static const
robertshield
2014/02/06 18:56:50
Done.
|
+ { "automaticSettingsResetBannerText", |
+ IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT }, |
gab
2014/02/05 15:23:52
Align flush with string above (same below); e.g. h
robertshield
2014/02/06 18:56:50
Done.
|
+ { "automaticSettingsResetLearnMoreUrl", |
+ IDS_AUTOMATIC_SETTINGS_RESET_LINK_LEARN_MORE }, |
+ }; |
+ |
+ RegisterStrings(localized_strings, resources, arraysize(resources)); |
+ localized_strings->SetString( |
+ "automaticSettingsResetLearnMoreUrl", |
+ chrome::kAutomaticSettingsResetLearnMoreURL); |
+} |
+ |
+void AutomaticSettingsResetHandler::RegisterMessages() { |
+ web_ui()->RegisterMessageCallback("onDismissedAutomaticSettingsResetBanner", |
+ base::Bind(&AutomaticSettingsResetHandler:: |
+ OnDismissedAutomaticSettingsResetBanner, |
gab
2014/02/05 15:23:52
This is a continuation of the above method name; e
robertshield
2014/02/06 18:56:50
Done.
|
+ base::Unretained(this))); |
gab
2014/02/05 15:23:52
This depends on the lifetime of this handler (whic
robertshield
2014/02/06 18:56:50
A nicer way is to use a weak ptr, which this was m
gab
2014/02/06 20:40:11
The weak ptr is not nicer than an anonymous method
robertshield
2014/02/07 04:36:19
Done.
|
+} |
+ |
+void AutomaticSettingsResetHandler::OnDismissedAutomaticSettingsResetBanner( |
+ const base::ListValue* value) { |
gab
2014/02/05 15:23:52
Log UMA stat here?
How would we log UMA for UI on
robertshield
2014/02/06 18:56:50
This is already logged via user action counts. See
|
+ PrefService* local_state = g_browser_process->local_state(); |
+ local_state->ClearPref(prefs::kProfilePreferenceResetTime); |
+} |
+ |
+} // namespace options |