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

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

Issue 11493003: Remove the protector service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix implicit ExtensionSystem -> TemplateURLService dependency Created 8 years 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/pref_service.h"
11 #include "chrome/browser/prefs/session_startup_pref.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/protector/base_prefs_change.h"
14 #include "chrome/browser/protector/histograms.h"
15 #include "chrome/browser/protector/protector_service.h"
16 #include "chrome/browser/protector/protector_service_factory.h"
17 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h"
19 #include "googleurl/src/gurl.h"
20 #include "grit/chromium_strings.h"
21 #include "grit/generated_resources.h"
22 #include "grit/theme_resources.h"
23 #include "ui/base/l10n/l10n_util.h"
24
25 namespace protector {
26
27 // Unknown change to Preferences with invalid backup.
28 class PrefsBackupInvalidChange : public BasePrefsChange {
29 public:
30 PrefsBackupInvalidChange();
31
32 // BasePrefsChange overrides:
33 virtual bool Init(Profile* profile) OVERRIDE;
34 virtual void InitWhenDisabled(Profile* profile) OVERRIDE;
35 virtual void Apply(Browser* browser) OVERRIDE;
36 virtual void Discard(Browser* browser) OVERRIDE;
37 virtual void Timeout() OVERRIDE;
38 virtual int GetBadgeIconID() const OVERRIDE;
39 virtual int GetMenuItemIconID() const OVERRIDE;
40 virtual int GetBubbleIconID() const OVERRIDE;
41 virtual string16 GetBubbleTitle() const OVERRIDE;
42 virtual string16 GetBubbleMessage() const OVERRIDE;
43 virtual string16 GetApplyButtonText() const OVERRIDE;
44 virtual string16 GetDiscardButtonText() const OVERRIDE;
45 virtual bool CanBeMerged() const OVERRIDE;
46
47 private:
48 virtual ~PrefsBackupInvalidChange();
49
50 // Applies default settings values when appropriate.
51 void ApplyDefaults(Profile* profile);
52
53 // True if session startup prefs have been reset.
54 bool startup_pref_reset_;
55
56 DISALLOW_COPY_AND_ASSIGN(PrefsBackupInvalidChange);
57 };
58
59 PrefsBackupInvalidChange::PrefsBackupInvalidChange()
60 : startup_pref_reset_(false) {
61 }
62
63 PrefsBackupInvalidChange::~PrefsBackupInvalidChange() {
64 }
65
66 bool PrefsBackupInvalidChange::Init(Profile* profile) {
67 if (!BasePrefsChange::Init(profile))
68 return false;
69 ApplyDefaults(profile);
70 DismissOnPrefChange(prefs::kHomePageIsNewTabPage);
71 DismissOnPrefChange(prefs::kHomePage);
72 DismissOnPrefChange(prefs::kShowHomeButton);
73 DismissOnPrefChange(prefs::kRestoreOnStartup);
74 DismissOnPrefChange(prefs::kURLsToRestoreOnStartup);
75 DismissOnPrefChange(prefs::kPinnedTabs);
76 return true;
77 }
78
79 void PrefsBackupInvalidChange::InitWhenDisabled(Profile* profile) {
80 // Nothing to do here since the backup has been already reset.
81 }
82
83 void PrefsBackupInvalidChange::Apply(Browser* browser) {
84 NOTREACHED();
85 }
86
87 void PrefsBackupInvalidChange::Discard(Browser* browser) {
88 // TODO(ivankr): highlight the protected prefs on the settings page
89 // (http://crbug.com/119088).
90 ProtectorServiceFactory::GetForProfile(profile())->OpenTab(
91 GURL(chrome::kChromeUISettingsURL), browser);
92 }
93
94 void PrefsBackupInvalidChange::Timeout() {
95 }
96
97 int PrefsBackupInvalidChange::GetBadgeIconID() const {
98 return IDR_UPDATE_BADGE4;
99 }
100
101 int PrefsBackupInvalidChange::GetMenuItemIconID() const {
102 return IDR_UPDATE_MENU4;
103 }
104
105 int PrefsBackupInvalidChange::GetBubbleIconID() const {
106 return IDR_INPUT_ALERT;
107 }
108
109 string16 PrefsBackupInvalidChange::GetBubbleTitle() const {
110 return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_TITLE);
111 }
112
113 string16 PrefsBackupInvalidChange::GetBubbleMessage() const {
114 return startup_pref_reset_ ?
115 l10n_util::GetStringUTF16(
116 IDS_SETTING_CHANGE_NO_BACKUP_STARTUP_RESET_BUBBLE_MESSAGE) :
117 l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_BUBBLE_MESSAGE);
118 }
119
120 string16 PrefsBackupInvalidChange::GetApplyButtonText() const {
121 // Don't show this button.
122 return string16();
123 }
124
125 string16 PrefsBackupInvalidChange::GetDiscardButtonText() const {
126 return l10n_util::GetStringUTF16(IDS_EDIT_SETTINGS);
127 }
128
129 void PrefsBackupInvalidChange::ApplyDefaults(Profile* profile) {
130 PrefService* prefs = profile->GetPrefs();
131 SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref(prefs);
132 if (startup_pref.type != SessionStartupPref::LAST) {
133 // If startup type is LAST, resetting it is dangerous (the whole previous
134 // session will be lost).
135 prefs->ClearPref(prefs::kRestoreOnStartup);
136 startup_pref_reset_ = true;
137 }
138 prefs->ClearPref(prefs::kHomePageIsNewTabPage);
139 prefs->ClearPref(prefs::kHomePage);
140 prefs->ClearPref(prefs::kShowHomeButton);
141 }
142
143 bool PrefsBackupInvalidChange::CanBeMerged() const {
144 return false;
145 }
146
147 BaseSettingChange* CreatePrefsBackupInvalidChange() {
148 return new PrefsBackupInvalidChange();
149 }
150
151 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/mock_setting_change.cc ('k') | chrome/browser/protector/prefs_backup_invalid_change_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698