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

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

Issue 9968007: [protector] Support for collapsing multiple changes into a single one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tried to compile after merge. Created 8 years, 8 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 | 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 "chrome/browser/protector/composite_settings_change.h"
6
7 #include "grit/generated_resources.h"
8 #include "ui/base/l10n/l10n_util.h"
9
10 namespace protector {
11
12
13 CompositeSettingsChange::CompositeSettingsChange() {
14 }
15
16 CompositeSettingsChange::~CompositeSettingsChange() {
17 }
18
19 CompositeSettingsChange* CompositeSettingsChange::MergeWith(
20 BaseSettingChange* other) {
21 DCHECK(profile());
22 changes_.push_back(other);
whywhat 2012/04/06 16:28:32 Check for NULL?
Ivan Korotkov 2012/04/09 14:46:47 Done.
23 apply_names_.push(other->GetApplyDisplayName());
24 return this;
25 }
26
27 bool CompositeSettingsChange::Contains(const BaseSettingChange* other) const {
28 return this == other ||
29 std::find(changes_.begin(), changes_.end(), other) != changes_.end();
30 }
31
32 void CompositeSettingsChange::Apply(Browser* browser) {
33 DVLOG(1) << "Apply all changes";
34 for (size_t i = 0; i < changes_.size(); ++i)
35 changes_[i]->Apply(browser);
whywhat 2012/04/06 16:28:32 I think we should be careful about applying/discar
Ivan Korotkov 2012/04/09 14:46:47 It shouldn't with the current *Change classes. The
36 }
37
38 void CompositeSettingsChange::Discard(Browser* browser) {
39 DVLOG(1) << "Discard all changes";
40 for (size_t i = 0; i < changes_.size(); ++i)
41 changes_[i]->Discard(browser);
42 }
43
44 void CompositeSettingsChange::Timeout() {
45 DVLOG(1) << "Timeout all changes";
46 for (size_t i = 0; i < changes_.size(); ++i)
47 changes_[i]->Timeout();
48 }
49
50 int CompositeSettingsChange::GetBadgeIconID() const {
51 DCHECK(changes_.size());
52 // Use icons from the first change.
53 // TODO(ivankr): need something better, maybe a special icon.
54 return changes_[0]->GetBadgeIconID();
55 }
56
57 int CompositeSettingsChange::GetMenuItemIconID() const {
58 DCHECK(changes_.size());
59 return changes_[0]->GetMenuItemIconID();
60 }
61
62 int CompositeSettingsChange::GetBubbleIconID() const {
63 DCHECK(changes_.size());
64 return changes_[0]->GetBubbleIconID();
65 }
66
67 string16 CompositeSettingsChange::GetBubbleTitle() const {
68 return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_TITLE);
69 }
70
71 string16 CompositeSettingsChange::GetBubbleMessage() const {
72 // TODO(ivankr): indicate what kind of changes happened (i.e., "something
73 // tried to change your search engine, startup pages, etc.").
74 return l10n_util::GetStringUTF16(IDS_SETTING_CHANGE_BUBBLE_MESSAGE);
75 }
76
77 string16 CompositeSettingsChange::GetApplyButtonText() const {
78 DCHECK(apply_names_.size());
79 string16 apply_text = apply_names_.top().second;
80 return apply_text.empty() ?
81 l10n_util::GetStringUTF16(IDS_CHANGE_SETTING_NO_NAME) :
82 l10n_util::GetStringFUTF16(IDS_CHANGE_SETTING, apply_text);
83 }
84
85 string16 CompositeSettingsChange::GetDiscardButtonText() const {
86 return l10n_util::GetStringUTF16(IDS_KEEP_SETTING);
87 }
88
89 BaseSettingChange::DisplayName
90 CompositeSettingsChange::GetApplyDisplayName() const {
91 // CompositeSettingsChange should never be put inside another one.
whywhat 2012/04/06 16:28:32 Maybe this means the class hierarchy is wrong? May
Ivan Korotkov 2012/04/09 14:46:47 I guess you're right but that sounds a little too
92 NOTREACHED();
93 return DisplayName(kDefaultNamePriority, string16());
94 }
95
96 std::string CompositeSettingsChange::GetApplyKeyword() const {
97 DCHECK(changes_.size());
98 return changes_[0]->GetApplyKeyword();
99 }
100
101 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698