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

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

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed merge conflict. Set default search engine when old setting is lost Created 9 years, 2 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
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/logging.h"
8 #include "base/task.h" 9 #include "base/task.h"
9 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/global_error_service.h" 14 #include "chrome/browser/ui/global_error_service.h"
14 #include "chrome/browser/ui/global_error_service_factory.h" 15 #include "chrome/browser/ui/global_error_service_factory.h"
15 #include "grit/chromium_strings.h" 16 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
18 19
20 namespace protector {
21
19 namespace { 22 namespace {
20 23
21 // Timeout before the global error is removed (wrench menu item disappears). 24 // Timeout before the global error is removed (wrench menu item disappears).
22 const int kMenuItemDisplayPeriodMs = 10*60*1000; // 10 min 25 const int kMenuItemDisplayPeriodMs = 10*60*1000; // 10 min
26
23 // IDs of menu item labels. 27 // IDs of menu item labels.
24 const int kMenuItemLabelIDs[] = { 28 const int kMenuItemLabelIDs[] = {
25 IDS_SEARCH_ENGINE_CHANGE_WRENCH_MENU_ITEM, 29 IDS_SEARCH_ENGINE_CHANGE_WRENCH_MENU_ITEM,
26 IDS_HOMEPAGE_CHANGE_WRENCH_MENU_ITEM 30 IDS_HOMEPAGE_CHANGE_WRENCH_MENU_ITEM
27 }; 31 };
32
28 // IDs of bubble title messages. 33 // IDs of bubble title messages.
29 const int kBubbleTitleIDs[] = { 34 const int kBubbleTitleIDs[] = {
30 IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TITLE, 35 IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TITLE,
31 IDS_HOMEPAGE_CHANGE_BUBBLE_TITLE 36 IDS_HOMEPAGE_CHANGE_BUBBLE_TITLE
32 }; 37 };
38
33 // IDs of bubble text messages. 39 // IDs of bubble text messages.
34 const int kBubbleMessageIDs[] = { 40 const int kBubbleMessageIDs[] = {
35 IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TEXT, 41 IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TEXT,
36 IDS_HOMEPAGE_CHANGE_BUBBLE_TEXT 42 IDS_HOMEPAGE_CHANGE_BUBBLE_TEXT
37 }; 43 };
44
38 // IDs of bubble text messages when the old setting is unknown. 45 // IDs of bubble text messages when the old setting is unknown.
39 const int kBubbleMessageOldUnknownIDs[] = { 46 const int kBubbleMessageOldUnknownIDs[] = {
40 IDS_SEARCH_ENGINE_CHANGE_UNKNOWN_BUBBLE_TEXT, 47 IDS_SEARCH_ENGINE_CHANGE_UNKNOWN_BUBBLE_TEXT,
41 IDS_HOMEPAGE_CHANGE_UNKNOWN_BUBBLE_TEXT 48 IDS_HOMEPAGE_CHANGE_UNKNOWN_BUBBLE_TEXT
42 }; 49 };
50
43 // IDs of "Keep Setting" button titles. 51 // IDs of "Keep Setting" button titles.
44 const int kBubbleKeepSettingIDs[] = { 52 const int kBubbleKeepSettingIDs[] = {
45 IDS_SEARCH_ENGINE_CHANGE_RESTORE, 53 IDS_SEARCH_ENGINE_CHANGE_RESTORE,
46 IDS_HOMEPAGE_CHANGE_RESTORE 54 IDS_HOMEPAGE_CHANGE_RESTORE
47 }; 55 };
56
48 // IDs of "Change Setting" button titles. 57 // IDs of "Change Setting" button titles.
49 const int kBubbleChangeSettingIDs[] = { 58 const int kBubbleChangeSettingIDs[] = {
50 IDS_SEARCH_ENGINE_CHANGE_APPLY, 59 IDS_SEARCH_ENGINE_CHANGE_APPLY,
51 IDS_HOMEPAGE_CHANGE_APPLY 60 IDS_HOMEPAGE_CHANGE_APPLY
52 }; 61 };
53 62
54 } // namespace 63 } // namespace
55 64
56 SettingsChangeGlobalError::SettingsChangeGlobalError( 65 SettingsChangeGlobalError::SettingsChangeGlobalError(
57 const ChangesVector& changes, 66 const ChangesVector& changes,
(...skipping 21 matching lines...) Expand all
79 88
80 int SettingsChangeGlobalError::MenuItemCommandID() { 89 int SettingsChangeGlobalError::MenuItemCommandID() {
81 return IDC_SHOW_SETTINGS_CHANGES; 90 return IDC_SHOW_SETTINGS_CHANGES;
82 } 91 }
83 92
84 // TODO(ivankr): Currently the menu item/bubble only displays a warning about 93 // TODO(ivankr): Currently the menu item/bubble only displays a warning about
85 // the first change. We want to fix this so that a single menu item/bubble 94 // the first change. We want to fix this so that a single menu item/bubble
86 // can display warning about multiple changes. 95 // can display warning about multiple changes.
87 96
88 string16 SettingsChangeGlobalError::MenuItemLabel() { 97 string16 SettingsChangeGlobalError::MenuItemLabel() {
89 return l10n_util::GetStringUTF16(kMenuItemLabelIDs[changes_.front().type]); 98 return l10n_util::GetStringUTF16(kMenuItemLabelIDs[changes_.front()->type()]);
90 } 99 }
91 100
92 void SettingsChangeGlobalError::ExecuteMenuItem(Browser* browser) { 101 void SettingsChangeGlobalError::ExecuteMenuItem(Browser* browser) {
93 weak_factory_.InvalidateWeakPtrs(); // Cancel previously posted tasks. 102 weak_factory_.InvalidateWeakPtrs(); // Cancel previously posted tasks.
94 ShowBubbleView(browser); 103 browser_ = browser;
104 ShowBubbleView(browser_);
95 } 105 }
96 106
97 bool SettingsChangeGlobalError::HasBubbleView() { 107 bool SettingsChangeGlobalError::HasBubbleView() {
98 return true; 108 return true;
99 } 109 }
100 110
101 string16 SettingsChangeGlobalError::GetBubbleViewTitle() { 111 string16 SettingsChangeGlobalError::GetBubbleViewTitle() {
102 return l10n_util::GetStringUTF16(kBubbleTitleIDs[changes_.front().type]); 112 return l10n_util::GetStringUTF16(kBubbleTitleIDs[changes_.front()->type()]);
103 } 113 }
104 114
105 string16 SettingsChangeGlobalError::GetBubbleViewMessage() { 115 string16 SettingsChangeGlobalError::GetBubbleViewMessage() {
106 const Change& change = changes_.front(); 116 scoped_refptr<SettingChange> change = changes_.front();
107 return change.old_setting.empty() ? 117 const string16& old_setting = change->GetOldSetting();
108 l10n_util::GetStringFUTF16(kBubbleMessageOldUnknownIDs[change.type], 118 if (old_setting.empty()) {
109 change.new_setting) : 119 return l10n_util::GetStringFUTF16(
110 l10n_util::GetStringFUTF16(kBubbleMessageIDs[change.type], 120 kBubbleMessageOldUnknownIDs[change->type()],
111 change.old_setting, change.new_setting); 121 change->GetNewSetting());
122 } else {
123 return l10n_util::GetStringFUTF16(
124 kBubbleMessageIDs[change->type()],
125 old_setting,
126 change->GetNewSetting());
127 }
112 } 128 }
113 129
114 string16 SettingsChangeGlobalError::GetBubbleViewAcceptButtonLabel() { 130 string16 SettingsChangeGlobalError::GetBubbleViewAcceptButtonLabel() {
115 const Change& change = changes_.front(); 131 scoped_refptr<SettingChange> change = changes_.front();
116 return l10n_util::GetStringFUTF16(kBubbleChangeSettingIDs[change.type], 132 string16 old_setting = change->GetOldSetting();
117 change.new_setting); 133 if (old_setting.empty()) {
134 return l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_OPEN_SETTINGS);
135 } else {
136 return l10n_util::GetStringFUTF16(
137 kBubbleKeepSettingIDs[change->type()],
138 old_setting);
139 }
118 } 140 }
119 141
120 string16 SettingsChangeGlobalError::GetBubbleViewCancelButtonLabel() { 142 string16 SettingsChangeGlobalError::GetBubbleViewCancelButtonLabel() {
121 const Change& change = changes_.front(); 143 scoped_refptr<SettingChange> change = changes_.front();
122 return change.old_setting.empty() ? 144 return l10n_util::GetStringFUTF16(kBubbleChangeSettingIDs[change->type()],
123 l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_OPEN_SETTINGS) : 145 change->GetNewSetting());
124 l10n_util::GetStringFUTF16(kBubbleKeepSettingIDs[change.type],
125 change.old_setting);
126 } 146 }
127 147
128 bool SettingsChangeGlobalError::IsAcceptButtonDefault() { 148 bool SettingsChangeGlobalError::IsAcceptButtonDefault() {
129 return false; 149 return false;
130 } 150 }
131 151
132 void SettingsChangeGlobalError::BubbleViewAcceptButtonPressed() { 152 void SettingsChangeGlobalError::BubbleViewAcceptButtonPressed() {
133 VLOG(1) << "Apply changes"; 153 VLOG(1) << "Apply changes";
134 apply_changes_cb_.Run(); 154 apply_changes_cb_.Run();
135 closed_by_button_ = true; 155 closed_by_button_ = true;
136 } 156 }
137 157
138 void SettingsChangeGlobalError::BubbleViewCancelButtonPressed() { 158 void SettingsChangeGlobalError::BubbleViewCancelButtonPressed() {
139 VLOG(1) << "Revert changes"; 159 VLOG(1) << "Revert changes";
140 revert_changes_cb_.Run(); 160 revert_changes_cb_.Run();
141 closed_by_button_ = true; 161 closed_by_button_ = true;
142 } 162 }
143 163
144 void SettingsChangeGlobalError::RemoveFromProfile() { 164 void SettingsChangeGlobalError::RemoveFromProfile() {
145 if (profile_) 165 if (profile_)
146 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this); 166 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this);
147 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); 167 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
148 } 168 }
149 169
150 void SettingsChangeGlobalError::BubbleViewDidClose() { 170 void SettingsChangeGlobalError::BubbleViewDidClose() {
171 browser_ = NULL;
151 if (!closed_by_button_) { 172 if (!closed_by_button_) {
152 BrowserThread::PostDelayedTask( 173 BrowserThread::PostDelayedTask(
153 BrowserThread::UI, FROM_HERE, 174 BrowserThread::UI, FROM_HERE,
154 base::Bind(&SettingsChangeGlobalError::RemoveFromProfile, 175 base::Bind(&SettingsChangeGlobalError::RemoveFromProfile,
155 weak_factory_.GetWeakPtr()), 176 weak_factory_.GetWeakPtr()),
156 kMenuItemDisplayPeriodMs); 177 kMenuItemDisplayPeriodMs);
157 } else { 178 } else {
158 RemoveFromProfile(); 179 RemoveFromProfile();
159 } 180 }
160 } 181 }
(...skipping 12 matching lines...) Expand all
173 void SettingsChangeGlobalError::AddToDefaultProfile() { 194 void SettingsChangeGlobalError::AddToDefaultProfile() {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
175 profile_ = ProfileManager::GetDefaultProfile(); 196 profile_ = ProfileManager::GetDefaultProfile();
176 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this); 197 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this);
177 Show(); 198 Show();
178 } 199 }
179 200
180 void SettingsChangeGlobalError::Show() { 201 void SettingsChangeGlobalError::Show() {
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
182 DCHECK(profile_); 203 DCHECK(profile_);
183 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); 204 browser_ = BrowserList::GetLastActiveWithProfile(profile_);
184 if (browser) 205 if (browser_)
185 ShowBubbleView(browser); 206 ShowBubbleView(browser_);
186 } 207 }
208
209 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698