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

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

Issue 8558020: Protector strings and bubble/SettingsChange code refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: This time it really should compile. Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/protector/settings_change_global_error.h" 5 #include "chrome/browser/protector/settings_change_global_error.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/protector/settings_change_global_error_delegate.h" 13 #include "chrome/browser/protector/settings_change_global_error_delegate.h"
14 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/global_error_service.h" 15 #include "chrome/browser/ui/global_error_service.h"
16 #include "chrome/browser/ui/global_error_service_factory.h" 16 #include "chrome/browser/ui/global_error_service_factory.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
21 18
22 using content::BrowserThread; 19 using content::BrowserThread;
23 20
24 namespace protector { 21 namespace protector {
25 22
26 namespace { 23 namespace {
27 24
28 // Timeout before the global error is removed (wrench menu item disappears). 25 // Timeout before the global error is removed (wrench menu item disappears).
29 const int kMenuItemDisplayPeriodMs = 10*60*1000; // 10 min 26 const int kMenuItemDisplayPeriodMs = 10*60*1000; // 10 min
30 27
31 // IDs of menu item labels.
32 const int kMenuItemLabelIDs[] = {
33 IDS_SEARCH_ENGINE_CHANGE_WRENCH_MENU_ITEM,
34 IDS_HOMEPAGE_CHANGE_WRENCH_MENU_ITEM
35 };
36
37 // IDs of bubble title messages.
38 const int kBubbleTitleIDs[] = {
39 IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TITLE,
40 IDS_HOMEPAGE_CHANGE_BUBBLE_TITLE
41 };
42
43 // IDs of bubble text messages.
44 const int kBubbleMessageIDs[] = {
45 IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TEXT,
46 IDS_HOMEPAGE_CHANGE_BUBBLE_TEXT
47 };
48
49 // IDs of bubble text messages when the old setting is unknown.
50 const int kBubbleMessageOldUnknownIDs[] = {
51 IDS_SEARCH_ENGINE_CHANGE_UNKNOWN_BUBBLE_TEXT,
52 IDS_HOMEPAGE_CHANGE_UNKNOWN_BUBBLE_TEXT
53 };
54
55 // IDs of "Keep Setting" button titles.
56 const int kBubbleKeepSettingIDs[] = {
57 IDS_SEARCH_ENGINE_CHANGE_RESTORE,
58 IDS_HOMEPAGE_CHANGE_RESTORE
59 };
60
61 // IDs of "Change Setting" button titles.
62 const int kBubbleChangeSettingIDs[] = {
63 IDS_SEARCH_ENGINE_CHANGE_APPLY,
64 IDS_HOMEPAGE_CHANGE_APPLY
65 };
66
67 } // namespace 28 } // namespace
68 29
69 SettingsChangeGlobalError::SettingsChangeGlobalError( 30 SettingsChangeGlobalError::SettingsChangeGlobalError(
70 const SettingChangeVector& changes, 31 BaseSettingChange* change,
71 SettingsChangeGlobalErrorDelegate* delegate) 32 SettingsChangeGlobalErrorDelegate* delegate)
72 : changes_(changes), 33 : change_(change),
73 delegate_(delegate), 34 delegate_(delegate),
74 profile_(NULL), 35 profile_(NULL),
75 browser_(NULL), 36 browser_(NULL),
76 closed_by_button_(false), 37 closed_by_button_(false),
77 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
78 DCHECK(changes.size() > 0); 39 DCHECK(delegate_);
79 } 40 }
80 41
81 SettingsChangeGlobalError::~SettingsChangeGlobalError() { 42 SettingsChangeGlobalError::~SettingsChangeGlobalError() {
82 STLDeleteElements(&changes_);
83 } 43 }
84 44
85 bool SettingsChangeGlobalError::HasBadge() { 45 bool SettingsChangeGlobalError::HasBadge() {
86 return true; 46 return true;
87 } 47 }
88 48
89 bool SettingsChangeGlobalError::HasMenuItem() { 49 bool SettingsChangeGlobalError::HasMenuItem() {
90 return true; 50 return true;
91 } 51 }
92 52
93 int SettingsChangeGlobalError::MenuItemCommandID() { 53 int SettingsChangeGlobalError::MenuItemCommandID() {
94 return IDC_SHOW_SETTINGS_CHANGES; 54 return IDC_SHOW_SETTINGS_CHANGES;
95 } 55 }
96 56
97 // TODO(ivankr): Currently the menu item/bubble only displays a warning about
98 // the first change. We want to fix this so that a single menu item/bubble
99 // can display warning about multiple changes.
100
101 string16 SettingsChangeGlobalError::MenuItemLabel() { 57 string16 SettingsChangeGlobalError::MenuItemLabel() {
102 return l10n_util::GetStringUTF16(kMenuItemLabelIDs[changes_.front()->type()]); 58 return change_->GetBubbleTitle();
103 } 59 }
104 60
105 void SettingsChangeGlobalError::ExecuteMenuItem(Browser* browser) { 61 void SettingsChangeGlobalError::ExecuteMenuItem(Browser* browser) {
106 // Cancel previously posted tasks. 62 // Cancel previously posted tasks.
107 weak_factory_.InvalidateWeakPtrs(); 63 weak_factory_.InvalidateWeakPtrs();
108 browser_ = browser; 64 browser_ = browser;
109 ShowBubbleView(browser_); 65 ShowBubbleView(browser_);
110 } 66 }
111 67
112 bool SettingsChangeGlobalError::HasBubbleView() { 68 bool SettingsChangeGlobalError::HasBubbleView() {
113 return true; 69 return true;
114 } 70 }
115 71
116 string16 SettingsChangeGlobalError::GetBubbleViewTitle() { 72 string16 SettingsChangeGlobalError::GetBubbleViewTitle() {
117 return l10n_util::GetStringUTF16(kBubbleTitleIDs[changes_.front()->type()]); 73 return change_->GetBubbleTitle();
118 } 74 }
119 75
120 string16 SettingsChangeGlobalError::GetBubbleViewMessage() { 76 string16 SettingsChangeGlobalError::GetBubbleViewMessage() {
121 SettingChange* change = changes_.front(); 77 return change_->GetBubbleMessage();
122 const string16& old_setting = change->GetOldSetting();
123 if (old_setting.empty()) {
124 return l10n_util::GetStringFUTF16(
125 kBubbleMessageOldUnknownIDs[change->type()],
126 change->GetNewSetting());
127 } else {
128 return l10n_util::GetStringFUTF16(
129 kBubbleMessageIDs[change->type()],
130 old_setting,
131 change->GetNewSetting());
132 }
133 } 78 }
134 79
80 // The Accept and Revert buttons are swapped like the 'server' and 'client'
81 // concepts in X11. Accept button (the default one) discards changes
82 // (keeps using previous setting) while cancel button applies changes
83 // (switches to the new setting). This is sick and blows my mind. - ivankr
84
135 string16 SettingsChangeGlobalError::GetBubbleViewAcceptButtonLabel() { 85 string16 SettingsChangeGlobalError::GetBubbleViewAcceptButtonLabel() {
136 SettingChange* change = changes_.front(); 86 return change_->GetDiscardButtonText();
137 string16 old_setting = change->GetOldSetting();
138 if (old_setting.empty()) {
139 return l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_OPEN_SETTINGS);
140 } else {
141 return l10n_util::GetStringFUTF16(
142 kBubbleKeepSettingIDs[change->type()],
143 old_setting);
144 }
145 } 87 }
146 88
147 string16 SettingsChangeGlobalError::GetBubbleViewCancelButtonLabel() { 89 string16 SettingsChangeGlobalError::GetBubbleViewCancelButtonLabel() {
148 SettingChange* change = changes_.front(); 90 return change_->GetApplyButtonText();
149 return l10n_util::GetStringFUTF16(kBubbleChangeSettingIDs[change->type()],
150 change->GetNewSetting());
151 } 91 }
152 92
153 void SettingsChangeGlobalError::BubbleViewAcceptButtonPressed() { 93 void SettingsChangeGlobalError::BubbleViewAcceptButtonPressed() {
154 closed_by_button_ = true; 94 closed_by_button_ = true;
155 DCHECK(delegate_); 95 delegate_->OnDiscardChange();
156 VLOG(1) << "Discard changes";
157 delegate_->OnDiscardChanges();
158 } 96 }
159 97
160 void SettingsChangeGlobalError::BubbleViewCancelButtonPressed() { 98 void SettingsChangeGlobalError::BubbleViewCancelButtonPressed() {
161 closed_by_button_ = true; 99 closed_by_button_ = true;
162 DCHECK(delegate_); 100 delegate_->OnApplyChange();
163 VLOG(1) << "Apply changes";
164 delegate_->OnApplyChanges();
165 } 101 }
166 102
167 void SettingsChangeGlobalError::RemoveFromProfile() { 103 void SettingsChangeGlobalError::RemoveFromProfile() {
168 DCHECK(delegate_);
169 if (profile_) 104 if (profile_)
170 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this); 105 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this);
171 if (!closed_by_button_) 106 if (!closed_by_button_)
172 delegate_->OnDecisionTimeout(); 107 delegate_->OnDecisionTimeout();
173 delegate_->OnRemovedFromProfile(); 108 delegate_->OnRemovedFromProfile();
174 } 109 }
175 110
176 void SettingsChangeGlobalError::BubbleViewDidClose() { 111 void SettingsChangeGlobalError::BubbleViewDidClose() {
177 browser_ = NULL; 112 browser_ = NULL;
178 if (!closed_by_button_) { 113 if (!closed_by_button_) {
(...skipping 28 matching lines...) Expand all
207 142
208 void SettingsChangeGlobalError::Show() { 143 void SettingsChangeGlobalError::Show() {
209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
210 DCHECK(profile_); 145 DCHECK(profile_);
211 browser_ = BrowserList::GetLastActiveWithProfile(profile_); 146 browser_ = BrowserList::GetLastActiveWithProfile(profile_);
212 if (browser_) 147 if (browser_)
213 ShowBubbleView(browser_); 148 ShowBubbleView(browser_);
214 } 149 }
215 150
216 } // namespace protector 151 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698