summaryrefslogtreecommitdiffstats
path: root/chrome/browser/protector/prefs_backup_invalid_change.cc
blob: a9cb8393b081bdcdd8b9ded807f571dbce6a31ef (plain)
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
// 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/profiles/profile.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 "chrome/common/url_constants.h"
#include "googleurl/src/gurl.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 {

// Unknown change to Preferences with invalid backup.
class PrefsBackupInvalidChange : public BasePrefsChange {
 public:
  PrefsBackupInvalidChange();

  // BasePrefsChange 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 ~PrefsBackupInvalidChange();

  // Applies default settings values when appropriate.
  void ApplyDefaults(Profile* profile);

  // True if session startup prefs have been reset.
  bool startup_pref_reset_;

  DISALLOW_COPY_AND_ASSIGN(PrefsBackupInvalidChange);
};

PrefsBackupInvalidChange::PrefsBackupInvalidChange()
    : startup_pref_reset_(false) {
}

PrefsBackupInvalidChange::~PrefsBackupInvalidChange() {
}

bool PrefsBackupInvalidChange::Init(Profile* profile) {
  if (!BasePrefsChange::Init(profile))
    return false;
  ApplyDefaults(profile);
  DismissOnPrefChange(prefs::kHomePageIsNewTabPage);
  DismissOnPrefChange(prefs::kHomePage);
  DismissOnPrefChange(prefs::kShowHomeButton);
  DismissOnPrefChange(prefs::kRestoreOnStartup);
  DismissOnPrefChange(prefs::kURLsToRestoreOnStartup);
  DismissOnPrefChange(prefs::kPinnedTabs);
  return true;
}

void PrefsBackupInvalidChange::Apply(Browser* browser) {
  NOTREACHED();
}

void PrefsBackupInvalidChange::Discard(Browser* browser) {
  // TODO(ivankr): highlight the protected prefs on the settings page
  // (http://crbug.com/119088).
  ProtectorServiceFactory::GetForProfile(profile())->OpenTab(
      GURL(chrome::kChromeUISettingsURL), browser);
}

void PrefsBackupInvalidChange::Timeout() {
}

int PrefsBackupInvalidChange::GetBadgeIconID() const {
  return IDR_UPDATE_BADGE4;
}

int PrefsBackupInvalidChange::GetMenuItemIconID() const {
  return IDR_UPDATE_MENU4;
}

int PrefsBackupInvalidChange::GetBubbleIconID() const {
  return IDR_INPUT_ALERT;
}

string16 PrefsBackupInvalidChange::GetBubbleTitle() const {
  return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_NO_BACKUP_TITLE);
}

string16 PrefsBackupInvalidChange::GetBubbleMessage() const {
  return startup_pref_reset_ ?
      l10n_util::GetStringUTF16(
          IDS_SETTING_CHANGE_NO_BACKUP_STARTUP_RESET_BUBBLE_MESSAGE) :
      l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_NO_BACKUP_BUBBLE_MESSAGE);
}

string16 PrefsBackupInvalidChange::GetApplyButtonText() const {
  // Don't show this button.
  return string16();
}

string16 PrefsBackupInvalidChange::GetDiscardButtonText() const {
  return l10n_util::GetStringUTF16(IDS_EDIT_SETTINGS);
}

void PrefsBackupInvalidChange::ApplyDefaults(Profile* profile) {
  PrefService* prefs = profile->GetPrefs();
  SessionStartupPref startup_pref = SessionStartupPref::GetStartupPref(prefs);
  if (startup_pref.type != SessionStartupPref::LAST) {
    // If startup type is LAST, resetting it is dangerous (the whole previous
    // session will be lost).
    startup_pref.type = SessionStartupPref::GetDefaultStartupType();
    SessionStartupPref::SetStartupPref(prefs, startup_pref);
    startup_pref_reset_ = true;
  }
}

BaseSettingChange* CreatePrefsBackupInvalidChange() {
  return new PrefsBackupInvalidChange();
}

}  // namespace protector