OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/webui/options/automatic_settings_reset_handler.h" |
| 6 |
| 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" |
| 16 |
| 17 namespace { |
| 18 const int kBannerShowTimeInDays = 5; |
| 19 } |
| 20 |
| 21 namespace { |
| 22 |
| 23 // Called when the user dismisses the automatic settings reset banner. |
| 24 void OnDismissedAutomaticSettingsResetBanner(const base::ListValue* value) { |
| 25 PrefService* local_state = g_browser_process->local_state(); |
| 26 local_state->ClearPref(prefs::kProfilePreferenceResetTime); |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 namespace options { |
| 32 |
| 33 AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {} |
| 34 AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {} |
| 35 |
| 36 void AutomaticSettingsResetHandler::InitializePage() { |
| 37 const int64 reset_time = |
| 38 g_browser_process->local_state()->GetInt64( |
| 39 prefs::kProfilePreferenceResetTime); |
| 40 if (reset_time != 0) { |
| 41 const base::Time now = base::Time::Now(); |
| 42 const base::Time then = base::Time::FromInternalValue(reset_time); |
| 43 if ((now - then).InDays() < kBannerShowTimeInDays) |
| 44 web_ui()->CallJavascriptFunction("AutomaticSettingsResetBanner.show"); |
| 45 } |
| 46 } |
| 47 |
| 48 void AutomaticSettingsResetHandler::GetLocalizedValues( |
| 49 base::DictionaryValue* localized_strings) { |
| 50 DCHECK(localized_strings); |
| 51 |
| 52 static const OptionsStringResource resources[] = { |
| 53 { "automaticSettingsResetBannerText", |
| 54 IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT }, |
| 55 { "automaticSettingsResetLearnMoreUrl", |
| 56 IDS_LEARN_MORE }, |
| 57 }; |
| 58 |
| 59 RegisterStrings(localized_strings, resources, arraysize(resources)); |
| 60 localized_strings->SetString( |
| 61 "automaticSettingsResetLearnMoreUrl", |
| 62 chrome::kAutomaticSettingsResetLearnMoreURL); |
| 63 } |
| 64 |
| 65 void AutomaticSettingsResetHandler::RegisterMessages() { |
| 66 web_ui()->RegisterMessageCallback("onDismissedAutomaticSettingsResetBanner", |
| 67 base::Bind(&OnDismissedAutomaticSettingsResetBanner)); |
| 68 } |
| 69 |
| 70 } // namespace options |
OLD | NEW |