Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: chrome/browser/ui/webui/options/automatic_settings_reset_handler.cc

Issue 151003004: Add an automatic settings reset banner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pre-review cleanup. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 options {
22
23 AutomaticSettingsResetHandler::AutomaticSettingsResetHandler() {}
24 AutomaticSettingsResetHandler::~AutomaticSettingsResetHandler() {}
25
26 void AutomaticSettingsResetHandler::InitializePage() {
gab 2014/02/05 15:23:52 Log UMA stat about impression of this UI?
robertshield 2014/02/06 18:56:50 Already done. See JS file.
27 PrefService* local_state = g_browser_process->local_state();
gab 2014/02/05 15:23:52 const (or simply inline the call since you only ne
robertshield 2014/02/06 18:56:50 Done.
28 int64 reset_time =
29 local_state->GetInt64(prefs::kProfilePreferenceResetTime);
30 if (reset_time != 0) {
31 base::Time now = base::Time::Now();
gab 2014/02/05 15:23:52 const
robertshield 2014/02/06 18:56:50 Done.
32 base::Time then = base::Time::FromInternalValue(reset_time);
gab 2014/02/05 15:23:52 const
robertshield 2014/02/06 18:56:50 Done.
33 if ((now - then).InDays() < kBannerShowTimeInDays) {
34 web_ui()->CallJavascriptFunction("AutomaticSettingsResetBanner.show");
35 }
gab 2014/02/05 15:23:52 remove {}
robertshield 2014/02/06 18:56:50 Done.
36 }
37 }
38
39 void AutomaticSettingsResetHandler::GetLocalizedValues(
40 base::DictionaryValue* localized_strings) {
41 DCHECK(localized_strings);
42
43 static OptionsStringResource resources[] = {
gab 2014/02/05 15:23:52 static const
robertshield 2014/02/06 18:56:50 Done.
44 { "automaticSettingsResetBannerText",
45 IDS_AUTOMATIC_SETTINGS_RESET_BANNER_TEXT },
gab 2014/02/05 15:23:52 Align flush with string above (same below); e.g. h
robertshield 2014/02/06 18:56:50 Done.
46 { "automaticSettingsResetLearnMoreUrl",
47 IDS_AUTOMATIC_SETTINGS_RESET_LINK_LEARN_MORE },
48 };
49
50 RegisterStrings(localized_strings, resources, arraysize(resources));
51 localized_strings->SetString(
52 "automaticSettingsResetLearnMoreUrl",
53 chrome::kAutomaticSettingsResetLearnMoreURL);
54 }
55
56 void AutomaticSettingsResetHandler::RegisterMessages() {
57 web_ui()->RegisterMessageCallback("onDismissedAutomaticSettingsResetBanner",
58 base::Bind(&AutomaticSettingsResetHandler::
59 OnDismissedAutomaticSettingsResetBanner,
gab 2014/02/05 15:23:52 This is a continuation of the above method name; e
robertshield 2014/02/06 18:56:50 Done.
60 base::Unretained(this)));
gab 2014/02/05 15:23:52 This depends on the lifetime of this handler (whic
robertshield 2014/02/06 18:56:50 A nicer way is to use a weak ptr, which this was m
gab 2014/02/06 20:40:11 The weak ptr is not nicer than an anonymous method
robertshield 2014/02/07 04:36:19 Done.
61 }
62
63 void AutomaticSettingsResetHandler::OnDismissedAutomaticSettingsResetBanner(
64 const base::ListValue* value) {
gab 2014/02/05 15:23:52 Log UMA stat here? How would we log UMA for UI on
robertshield 2014/02/06 18:56:50 This is already logged via user action counts. See
65 PrefService* local_state = g_browser_process->local_state();
66 local_state->ClearPref(prefs::kProfilePreferenceResetTime);
67 }
68
69 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698