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

Side by Side Diff: chrome/browser/protector/session_startup_change.cc

Issue 9688002: [protector] Added SessionStartupChange for representing changes in SessionStartupPref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments. Created 8 years, 9 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 (c) 2012 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 "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/prefs/session_startup_pref.h"
11 #include "chrome/browser/protector/base_setting_change.h"
12 #include "chrome/browser/protector/histograms.h"
13 #include "chrome/browser/protector/protector_service.h"
14 #include "chrome/browser/protector/protector_service_factory.h"
15 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
19
20 namespace protector {
21
22 // STARTUP_SETTING and session startup settings change tracked by Protector.
23 class SessionStartupChange : public BaseSettingChange {
24 public:
25 SessionStartupChange(const SessionStartupPref& actual,
26 const SessionStartupPref& backup);
27
28 // BaseSettingChange overrides:
29 virtual bool Init(Profile* profile) OVERRIDE;
30 virtual void Apply(Browser* browser) OVERRIDE;
31 virtual void Discard(Browser* browser) OVERRIDE;
32 virtual void Timeout() OVERRIDE;
33 virtual int GetBadgeIconID() const OVERRIDE;
34 virtual int GetMenuItemIconID() const OVERRIDE;
35 virtual int GetBubbleIconID() const OVERRIDE;
36 virtual string16 GetBubbleTitle() const OVERRIDE;
37 virtual string16 GetBubbleMessage() const OVERRIDE;
38 virtual string16 GetApplyButtonText() const OVERRIDE;
39 virtual string16 GetDiscardButtonText() const OVERRIDE;
40
41 private:
42 virtual ~SessionStartupChange();
43
44 SessionStartupPref new_pref_;
45 SessionStartupPref backup_pref_;
46
47 DISALLOW_COPY_AND_ASSIGN(SessionStartupChange);
48 };
49
50 SessionStartupChange::SessionStartupChange(const SessionStartupPref& actual,
51 const SessionStartupPref& backup)
52 : new_pref_(actual),
53 backup_pref_(backup) {
54 UMA_HISTOGRAM_ENUMERATION(
55 kProtectorHistogramStartupSettingsChanged,
56 actual.type,
57 SessionStartupPref::TYPE_COUNT);
58 }
59
60 SessionStartupChange::~SessionStartupChange() {
61 }
62
63 bool SessionStartupChange::Init(Profile* profile) {
64 if (!BaseSettingChange::Init(profile))
65 return false;
66 SessionStartupPref::SetStartupPref(profile, backup_pref_);
67 return true;
68 }
69
70 void SessionStartupChange::Apply(Browser* browser) {
71 UMA_HISTOGRAM_ENUMERATION(
72 kProtectorHistogramStartupSettingsApplied,
73 new_pref_.type,
74 SessionStartupPref::TYPE_COUNT);
75 SessionStartupPref::SetStartupPref(profile(), new_pref_);
76 }
77
78 void SessionStartupChange::Discard(Browser* browser) {
79 UMA_HISTOGRAM_ENUMERATION(
80 kProtectorHistogramStartupSettingsDiscarded,
81 new_pref_.type,
82 SessionStartupPref::TYPE_COUNT);
83 // Nothing to do here since |backup_pref_| was already made active by Init().
84 }
85
86 void SessionStartupChange::Timeout() {
87 UMA_HISTOGRAM_ENUMERATION(
88 kProtectorHistogramStartupSettingsTimeout,
89 new_pref_.type,
90 SessionStartupPref::TYPE_COUNT);
91 }
92
93 int SessionStartupChange::GetBadgeIconID() const {
94 // Icons are the same for homepage and startup settings.
95 return IDR_HOMEPAGE_CHANGE_BADGE;
96 }
97
98 int SessionStartupChange::GetMenuItemIconID() const {
99 return IDR_HOMEPAGE_CHANGE_MENU;
100 }
101
102 int SessionStartupChange::GetBubbleIconID() const {
103 return IDR_HOMEPAGE_CHANGE_ALERT;
104 }
105
106 string16 SessionStartupChange::GetBubbleTitle() const {
107 return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_TITLE);
108 }
109
110 string16 SessionStartupChange::GetBubbleMessage() const {
111 return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_BUBBLE_MESSAGE);
112 }
113
114 string16 SessionStartupChange::GetApplyButtonText() const {
115 switch (new_pref_.type) {
116 case SessionStartupPref::DEFAULT:
117 return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP);
118
119 case SessionStartupPref::LAST:
120 return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_RESTORE);
121
122 case SessionStartupPref::URLS:
123 if (new_pref_.urls.empty()) {
124 return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP);
125 } else {
126 string16 first_url = UTF8ToUTF16(new_pref_.urls[0].host());
127 return l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS,
128 first_url);
129 }
130
131 default:
132 NOTREACHED();
133 return string16();
134 }
135 }
136
137 string16 SessionStartupChange::GetDiscardButtonText() const {
138 switch (backup_pref_.type) {
139 case SessionStartupPref::DEFAULT:
140 return l10n_util::GetStringUTF16(IDS_KEEP_STARTUP_SETTINGS_NTP);
141
142 case SessionStartupPref::LAST:
143 return l10n_util::GetStringUTF16(IDS_KEEP_STARTUP_SETTINGS_RESTORE);
144
145 case SessionStartupPref::URLS:
146 if (backup_pref_.urls.empty()) {
147 return l10n_util::GetStringUTF16(IDS_KEEP_STARTUP_SETTINGS_NTP);
148 } else {
149 string16 first_url = UTF8ToUTF16(backup_pref_.urls[0].host());
150 return l10n_util::GetStringFUTF16(IDS_KEEP_STARTUP_SETTINGS_URLS,
151 first_url);
152 }
153
154 default:
155 NOTREACHED();
156 return string16();
157 }
158 }
159
160 BaseSettingChange* CreateSessionStartupChange(
161 const SessionStartupPref& actual,
162 const SessionStartupPref& backup) {
163 return new SessionStartupChange(actual, backup);
164 }
165
166 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/histograms.cc ('k') | chrome/browser/protector/session_startup_change_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698