NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / automatic_settings_reset_handler.cc
blob8c71de6888ad6e2f2129ca2777fd4c479c781e14
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"
7 #include "base/bind.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"
17 namespace {
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);
27 } // namespace
29 namespace options {
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",
54 IDS_LEARN_MORE },
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