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

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

Issue 9748016: [protector] Added UI for invalid Preferences backup case. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix unit-test. 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
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/profiles/profile.h"
12 #include "chrome/browser/protector/base_prefs_change.h"
13 #include "chrome/browser/protector/histograms.h"
14 #include "chrome/browser/protector/protector_service.h"
15 #include "chrome/browser/protector/protector_service_factory.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/common/url_constants.h"
18 #include "googleurl/src/gurl.h"
19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 namespace protector {
25
26 // Unknown change to Preferences with invalid backup.
27 class PrefsBackupInvalidChange : public BasePrefsChange {
28 public:
29 PrefsBackupInvalidChange();
30
31 // BasePrefsChange overrides:
32 virtual bool Init(Profile* profile) OVERRIDE;
33 virtual void Apply(Browser* browser) OVERRIDE;
34 virtual void Discard(Browser* browser) OVERRIDE;
35 virtual void Timeout() OVERRIDE;
36 virtual int GetBadgeIconID() const OVERRIDE;
37 virtual int GetMenuItemIconID() const OVERRIDE;
38 virtual int GetBubbleIconID() const OVERRIDE;
39 virtual string16 GetBubbleTitle() const OVERRIDE;
40 virtual string16 GetBubbleMessage() const OVERRIDE;
41 virtual string16 GetApplyButtonText() const OVERRIDE;
42 virtual string16 GetDiscardButtonText() const OVERRIDE;
43
44 private:
45 virtual ~PrefsBackupInvalidChange();
46
47 // Applies default settings values when appropriate.
48 void ApplyDefaults(Profile* profile);
49
50 DISALLOW_COPY_AND_ASSIGN(PrefsBackupInvalidChange);
51 };
52
53 PrefsBackupInvalidChange::PrefsBackupInvalidChange() {
54 }
55
56 PrefsBackupInvalidChange::~PrefsBackupInvalidChange() {
57 }
58
59 bool PrefsBackupInvalidChange::Init(Profile* profile) {
60 if (!BasePrefsChange::Init(profile))
61 return false;
62 ApplyDefaults(profile);
63 DismissOnPrefChange(prefs::kHomePageIsNewTabPage);
64 DismissOnPrefChange(prefs::kHomePage);
65 DismissOnPrefChange(prefs::kShowHomeButton);
66 DismissOnPrefChange(prefs::kRestoreOnStartup);
67 DismissOnPrefChange(prefs::kURLsToRestoreOnStartup);
68 return true;
69 }
70
71 void PrefsBackupInvalidChange::Apply(Browser* browser) {
72 NOTREACHED();
73 }
74
75 void PrefsBackupInvalidChange::Discard(Browser* browser) {
76 // TODO(ivankr): highlight the protected prefs on the settings page
77 // (http://crbug.com/119088).
78 ProtectorServiceFactory::GetForProfile(profile())->OpenTab(
79 GURL(chrome::kChromeUISettingsURL), browser);
80 }
81
82 void PrefsBackupInvalidChange::Timeout() {
83 }
84
85 int PrefsBackupInvalidChange::GetBadgeIconID() const {
86 // Use icons for startup settings change.
87 return IDR_HOMEPAGE_CHANGE_BADGE;
88 }
89
90 int PrefsBackupInvalidChange::GetMenuItemIconID() const {
91 return IDR_HOMEPAGE_CHANGE_MENU;
92 }
93
94 int PrefsBackupInvalidChange::GetBubbleIconID() const {
95 return IDR_HOMEPAGE_CHANGE_ALERT;
96 }
97
98 string16 PrefsBackupInvalidChange::GetBubbleTitle() const {
99 return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_NO_BACKUP_TITLE);
100 }
101
102 string16 PrefsBackupInvalidChange::GetBubbleMessage() const {
103 return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_NO_BACKUP_BUBBLE_MESSAGE);
104 }
105
106 string16 PrefsBackupInvalidChange::GetApplyButtonText() const {
107 // Don't show this button.
108 return string16();
109 }
110
111 string16 PrefsBackupInvalidChange::GetDiscardButtonText() const {
112 return l10n_util::GetStringUTF16(IDS_EDIT_SETTINGS);
113 }
114
115 void PrefsBackupInvalidChange::ApplyDefaults(Profile* profile) {
116 PrefService* prefs = profile->GetPrefs();
117 SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref(prefs);
118 if (startup_pref.type != SessionStartupPref::LAST) {
119 // If startup type is LAST, resetting it is dangerous (the whole previous
120 // session will be lost).
121 startup_pref.type = SessionStartupPref::GetDefaultStartupType();
122 SessionStartupPref::SetStartupPref(prefs, startup_pref);
123 }
124 }
125
126 BaseSettingChange* CreatePrefsBackupInvalidChange() {
127 return new PrefsBackupInvalidChange();
128 }
129
130 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/base_setting_change.h ('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