Upstream version 5.34.104.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/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
19 const int kBannerShowTimeInDays = 5;
20
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);
25 }
26
27 }  // namespace
28
29 namespace options {
30
31 AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {}
32 AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {}
33
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");
43   }
44 }
45
46 void AutomaticSettingsResetHandler::GetLocalizedValues(
47     base::DictionaryValue* localized_strings) {
48   DCHECK(localized_strings);
49
50   static const OptionsStringResource resources[] = {
51       { "automaticSettingsResetBannerText",
52         IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT },
53       { "automaticSettingsResetLearnMoreUrl",
54         IDS_LEARN_MORE },
55   };
56
57   RegisterStrings(localized_strings, resources, arraysize(resources));
58   localized_strings->SetString(
59       "automaticSettingsResetLearnMoreUrl",
60       chrome::kAutomaticSettingsResetLearnMoreURL);
61 }
62
63 void AutomaticSettingsResetHandler::RegisterMessages() {
64   web_ui()->RegisterMessageCallback("onDismissedAutomaticSettingsResetBanner",
65       base::Bind(&OnDismissedAutomaticSettingsResetBanner));
66 }
67
68 }  // namespace options