1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/protector/base_prefs_change.h"
#include "chrome/browser/protector/histograms.h"
#include "chrome/browser/protector/protector_service.h"
#include "chrome/browser/protector/protector_service_factory.h"
#include "chrome/common/pref_names.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace protector {
// Session startup settings change tracked by Protector.
class SessionStartupChange : public BasePrefsChange {
public:
SessionStartupChange(const SessionStartupPref& actual,
const SessionStartupPref& backup);
// BaseSettingChange overrides:
virtual bool Init(Profile* profile) OVERRIDE;
virtual void Apply(Browser* browser) OVERRIDE;
virtual void Discard(Browser* browser) OVERRIDE;
virtual void Timeout() OVERRIDE;
virtual int GetBadgeIconID() const OVERRIDE;
virtual int GetMenuItemIconID() const OVERRIDE;
virtual int GetBubbleIconID() const OVERRIDE;
virtual string16 GetBubbleTitle() const OVERRIDE;
virtual string16 GetBubbleMessage() const OVERRIDE;
virtual string16 GetApplyButtonText() const OVERRIDE;
virtual string16 GetDiscardButtonText() const OVERRIDE;
private:
virtual ~SessionStartupChange();
SessionStartupPref new_pref_;
SessionStartupPref backup_pref_;
DISALLOW_COPY_AND_ASSIGN(SessionStartupChange);
};
SessionStartupChange::SessionStartupChange(const SessionStartupPref& actual,
const SessionStartupPref& backup)
: new_pref_(actual),
backup_pref_(backup) {
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramStartupSettingsChanged,
actual.type,
SessionStartupPref::TYPE_COUNT);
}
SessionStartupChange::~SessionStartupChange() {
}
bool SessionStartupChange::Init(Profile* profile) {
if (!BasePrefsChange::Init(profile))
return false;
SessionStartupPref::SetStartupPref(profile, backup_pref_);
DismissOnPrefChange(prefs::kRestoreOnStartup);
DismissOnPrefChange(prefs::kURLsToRestoreOnStartup);
return true;
}
void SessionStartupChange::Apply(Browser* browser) {
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramStartupSettingsApplied,
new_pref_.type,
SessionStartupPref::TYPE_COUNT);
IgnorePrefChanges();
SessionStartupPref::SetStartupPref(profile(), new_pref_);
}
void SessionStartupChange::Discard(Browser* browser) {
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramStartupSettingsDiscarded,
new_pref_.type,
SessionStartupPref::TYPE_COUNT);
IgnorePrefChanges();
// Nothing to do here since |backup_pref_| was already made active by Init().
}
void SessionStartupChange::Timeout() {
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramStartupSettingsTimeout,
new_pref_.type,
SessionStartupPref::TYPE_COUNT);
}
int SessionStartupChange::GetBadgeIconID() const {
// Icons are the same for homepage and startup settings.
return IDR_HOMEPAGE_CHANGE_BADGE;
}
int SessionStartupChange::GetMenuItemIconID() const {
return IDR_HOMEPAGE_CHANGE_MENU;
}
int SessionStartupChange::GetBubbleIconID() const {
return IDR_HOMEPAGE_CHANGE_ALERT;
}
string16 SessionStartupChange::GetBubbleTitle() const {
return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_TITLE);
}
string16 SessionStartupChange::GetBubbleMessage() const {
return l10n_util::GetStringUTF16(IDS_STARTUP_SETTINGS_CHANGE_BUBBLE_MESSAGE);
}
string16 SessionStartupChange::GetApplyButtonText() const {
switch (new_pref_.type) {
case SessionStartupPref::DEFAULT:
return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP);
case SessionStartupPref::LAST:
return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_RESTORE);
case SessionStartupPref::URLS:
if (new_pref_.urls.empty()) {
return l10n_util::GetStringUTF16(IDS_CHANGE_STARTUP_SETTINGS_NTP);
} else {
string16 first_url = UTF8ToUTF16(new_pref_.urls[0].host());
return l10n_util::GetStringFUTF16(IDS_CHANGE_STARTUP_SETTINGS_URLS,
first_url);
}
default:
NOTREACHED();
return string16();
}
}
string16 SessionStartupChange::GetDiscardButtonText() const {
return l10n_util::GetStringUTF16(IDS_KEEP_SETTING);
}
BaseSettingChange* CreateSessionStartupChange(
const SessionStartupPref& actual,
const SessionStartupPref& backup) {
return new SessionStartupChange(actual, backup);
}
} // namespace protector
|