summaryrefslogtreecommitdiffstats
path: root/chrome/browser/protector/composite_settings_change.cc
blob: a907047c915153237d6d60c48b17e569333d975c (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
// 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 "chrome/browser/protector/composite_settings_change.h"

#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"

namespace protector {


CompositeSettingsChange::CompositeSettingsChange() {
}

CompositeSettingsChange::~CompositeSettingsChange() {
}

CompositeSettingsChange* CompositeSettingsChange::MergeWith(
    BaseSettingChange* other) {
  DCHECK(profile());
  DCHECK(other);
  changes_.push_back(other);
  apply_names_.push(other->GetApplyDisplayName());
  return this;
}

bool CompositeSettingsChange::Contains(const BaseSettingChange* other) const {
  return this == other ||
      std::find(changes_.begin(), changes_.end(), other) != changes_.end();
}

// Apart from PrefsBackupInvalidChange, which should never appear with other
// Preferences-related changes together, the Apply/Discard logic of change
// classes does not overlap, so it's safe to call them in any order.

void CompositeSettingsChange::Apply(Browser* browser) {
  DVLOG(1) << "Apply all changes";
  for (size_t i = 0; i < changes_.size(); ++i)
    changes_[i]->Apply(browser);
}

void CompositeSettingsChange::Discard(Browser* browser) {
  DVLOG(1) << "Discard all changes";
  for (size_t i = 0; i < changes_.size(); ++i)
    changes_[i]->Discard(browser);
}

void CompositeSettingsChange::Timeout() {
  DVLOG(1) << "Timeout all changes";
  for (size_t i = 0; i < changes_.size(); ++i)
    changes_[i]->Timeout();
}

int CompositeSettingsChange::GetBadgeIconID() const {
  DCHECK(changes_.size());
  // Use icons from the first change.
  // TODO(ivankr): need something better, maybe a special icon.
  return changes_[0]->GetBadgeIconID();
}

int CompositeSettingsChange::GetMenuItemIconID() const {
  DCHECK(changes_.size());
  return changes_[0]->GetMenuItemIconID();
}

int CompositeSettingsChange::GetBubbleIconID() const {
  DCHECK(changes_.size());
  return changes_[0]->GetBubbleIconID();
}

string16 CompositeSettingsChange::GetBubbleTitle() const {
  return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_TITLE);
}

string16 CompositeSettingsChange::GetBubbleMessage() const {
  // TODO(ivankr): indicate what kind of changes happened (i.e., "something
  // tried to change your search engine, startup pages, etc.").
  return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_BUBBLE_MESSAGE);
}

string16 CompositeSettingsChange::GetApplyButtonText() const {
  DCHECK(apply_names_.size());
  string16 apply_text = apply_names_.top().second;
  return apply_text.empty() ?
      l10n_util::GetStringUTF16(IDS_CHANGE_SETTING_NO_NAME) :
      l10n_util::GetStringFUTF16(IDS_CHANGE_SETTING, apply_text);
}

string16 CompositeSettingsChange::GetDiscardButtonText() const {
  return l10n_util::GetStringUTF16(IDS_KEEP_SETTING);
}

BaseSettingChange::DisplayName
CompositeSettingsChange::GetApplyDisplayName() const {
  // CompositeSettingsChange should never be put inside another one.
  NOTREACHED();
  return BaseSettingChange::GetApplyDisplayName();
}

GURL CompositeSettingsChange::GetNewSettingURL() const {
  DCHECK(changes_.size());
  return changes_[0]->GetNewSettingURL();
}

bool CompositeSettingsChange::CanBeMerged() const {
  // We did that already, why not do it again.
  return true;
}

}  // namespace protector