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/prefs/pref_service.h"
10 #include "base/time/time.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/web_ui.h"
15 #include "grit/generated_resources.h"
19 const int kBannerShowTimeInDays
= 5;
21 // Called when the user dismisses the automatic settings reset banner.
22 void OnDismissedAutomaticSettingsResetBanner(const base::ListValue
* value
) {
23 PrefService
* local_state
= g_browser_process
->local_state();
24 local_state
->ClearPref(prefs::kProfilePreferenceResetTime
);
31 AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {}
32 AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {}
34 void AutomaticSettingsResetHandler::InitializePage() {
35 const int64 reset_time
=
36 g_browser_process
->local_state()->GetInt64(
37 prefs::kProfilePreferenceResetTime
);
38 if (reset_time
!= 0) {
39 const base::Time now
= base::Time::Now();
40 const base::Time then
= base::Time::FromInternalValue(reset_time
);
41 if ((now
- then
).InDays() < kBannerShowTimeInDays
)
42 web_ui()->CallJavascriptFunction("AutomaticSettingsResetBanner.show");
46 void AutomaticSettingsResetHandler::GetLocalizedValues(
47 base::DictionaryValue
* localized_strings
) {
48 DCHECK(localized_strings
);
50 static const OptionsStringResource resources
[] = {
51 { "automaticSettingsResetBannerText",
52 IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT
},
53 { "automaticSettingsResetLearnMoreUrl",
57 RegisterStrings(localized_strings
, resources
, arraysize(resources
));
58 localized_strings
->SetString(
59 "automaticSettingsResetLearnMoreUrl",
60 chrome::kAutomaticSettingsResetLearnMoreURL
);
63 void AutomaticSettingsResetHandler::RegisterMessages() {
64 web_ui()->RegisterMessageCallback("onDismissedAutomaticSettingsResetBanner",
65 base::Bind(&OnDismissedAutomaticSettingsResetBanner
));
68 } // namespace options