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/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" 15 16 namespace { 17 18 void OnDismissedAutomaticSettingsResetBanner(Profile* profile, 19 const base::ListValue* value) { 20 chrome_prefs::ClearResetTime(profile); 21 } 22 23 } // namespace 24 25 namespace options { 26 27 AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {} 28 AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {} 29 30 void AutomaticSettingsResetHandler::InitializePage() { 31 static const int kBannerShowTimeInDays = 5; 32 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"); 39 } 40 } 41 42 void AutomaticSettingsResetHandler::GetLocalizedValues( 43 base::DictionaryValue* localized_strings) { 44 DCHECK(localized_strings); 45 46 static const OptionsStringResource resources[] = { 47 { "automaticSettingsResetBannerText", 48 IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT }, 49 { "automaticSettingsResetLearnMoreUrl", 50 IDS_LEARN_MORE }, 51 }; 52 53 RegisterStrings(localized_strings, resources, arraysize(resources)); 54 localized_strings->SetString( 55 "automaticSettingsResetLearnMoreUrl", 56 chrome::kAutomaticSettingsResetLearnMoreURL); 57 } 58 59 void AutomaticSettingsResetHandler::RegisterMessages() { 60 web_ui()->RegisterMessageCallback( 61 "onDismissedAutomaticSettingsResetBanner", 62 base::Bind(&OnDismissedAutomaticSettingsResetBanner, 63 Profile::FromWebUI(web_ui()))); 64 } 65 66 } // namespace options 67