375ff5ac32b36f86e023fa27bd7d6af434443585
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / automatic_settings_reset_handler.cc
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       { "automaticSettingsResetBannerResetButtonText",
48         IDS_AUTOMATIC_SETTINGS_RESET_BANNER_RESET_BUTTON_TEXT },
49       { "automaticSettingsResetBannerText",
50         IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT },
51       { "automaticSettingsResetLearnMoreUrl",
52         IDS_LEARN_MORE },
53   };
54
55   RegisterStrings(localized_strings, resources, arraysize(resources));
56   localized_strings->SetString(
57       "automaticSettingsResetLearnMoreUrl",
58       chrome::kAutomaticSettingsResetLearnMoreURL);
59 }
60
61 void AutomaticSettingsResetHandler::RegisterMessages() {
62   web_ui()->RegisterMessageCallback(
63       "onDismissedAutomaticSettingsResetBanner",
64       base::Bind(&OnDismissedAutomaticSettingsResetBanner,
65                  Profile::FromWebUI(web_ui())));
66 }
67
68 }  // namespace options