1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/automatic_settings_reset_handler.h"
8 #include "base/bind_helpers.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/web_ui.h"
14 #include "grit/generated_resources.h"
18 void OnDismissedAutomaticSettingsResetBanner(Profile* profile,
19 const base::ListValue* value) {
20 chrome_prefs::ClearResetTime(profile);
27 AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {}
28 AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {}
30 void AutomaticSettingsResetHandler::InitializePage() {
31 static const int kBannerShowTimeInDays = 5;
33 const base::Time then =
34 chrome_prefs::GetResetTime(Profile::FromWebUI(web_ui()));
35 if (!then.is_null()) {
36 const base::Time now = base::Time::Now();
37 if ((now - then).InDays() < kBannerShowTimeInDays)
38 web_ui()->CallJavascriptFunction("AutomaticSettingsResetBanner.show");
42 void AutomaticSettingsResetHandler::GetLocalizedValues(
43 base::DictionaryValue* localized_strings) {
44 DCHECK(localized_strings);
46 static const OptionsStringResource resources[] = {
47 { "automaticSettingsResetBannerResetButtonText",
48 IDS_AUTOMATIC_SETTINGS_RESET_BANNER_RESET_BUTTON_TEXT },
49 { "automaticSettingsResetBannerText",
50 IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT },
51 { "automaticSettingsResetLearnMoreUrl",
55 RegisterStrings(localized_strings, resources, arraysize(resources));
56 localized_strings->SetString(
57 "automaticSettingsResetLearnMoreUrl",
58 chrome::kAutomaticSettingsResetLearnMoreURL);
61 void AutomaticSettingsResetHandler::RegisterMessages() {
62 web_ui()->RegisterMessageCallback(
63 "onDismissedAutomaticSettingsResetBanner",
64 base::Bind(&OnDismissedAutomaticSettingsResetBanner,
65 Profile::FromWebUI(web_ui())));
68 } // namespace options