Upstream version 11.40.277.0
[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 "chrome/grit/generated_resources.h"
14 #include "content/public/browser/web_ui.h"
15 #include "grit/components_strings.h"
16
17 namespace {
18
19 void OnDismissedAutomaticSettingsResetBanner(Profile* profile,
20                                              const base::ListValue* value) {
21   chrome_prefs::ClearResetTime(profile);
22 }
23
24 }  // namespace
25
26 namespace options {
27
28 AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {}
29 AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {}
30
31 void AutomaticSettingsResetHandler::InitializePage() {
32   static const int kBannerShowTimeInDays = 5;
33
34   const base::Time then =
35       chrome_prefs::GetResetTime(Profile::FromWebUI(web_ui()));
36   if (!then.is_null()) {
37     const base::Time now = base::Time::Now();
38     if ((now - then).InDays() < kBannerShowTimeInDays)
39       web_ui()->CallJavascriptFunction("AutomaticSettingsResetBanner.show");
40   }
41 }
42
43 void AutomaticSettingsResetHandler::GetLocalizedValues(
44     base::DictionaryValue* localized_strings) {
45   DCHECK(localized_strings);
46
47   static const OptionsStringResource resources[] = {
48       { "automaticSettingsResetBannerResetButtonText",
49         IDS_AUTOMATIC_SETTINGS_RESET_BANNER_RESET_BUTTON_TEXT },
50       { "automaticSettingsResetBannerText",
51         IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT },
52       { "automaticSettingsResetLearnMoreUrl",
53         IDS_LEARN_MORE },
54   };
55
56   RegisterStrings(localized_strings, resources, arraysize(resources));
57   localized_strings->SetString(
58       "automaticSettingsResetLearnMoreUrl",
59       chrome::kAutomaticSettingsResetLearnMoreURL);
60 }
61
62 void AutomaticSettingsResetHandler::RegisterMessages() {
63   web_ui()->RegisterMessageCallback(
64       "onDismissedAutomaticSettingsResetBanner",
65       base::Bind(&OnDismissedAutomaticSettingsResetBanner,
66                  Profile::FromWebUI(web_ui())));
67 }
68
69 }  // namespace options