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

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: 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 Protector::ChangesVector& changes,
58 const base::Closure& make_changes_cb, 67 const base::Closure& make_changes_cb,
59 const base::Closure& restore_changes_cb) 68 const base::Closure& restore_changes_cb)
60 : changes_(changes), 69 : changes_(changes),
61 make_changes_cb_(make_changes_cb), 70 make_changes_cb_(make_changes_cb),
62 restore_changes_cb_(restore_changes_cb), 71 restore_changes_cb_(restore_changes_cb),
63 profile_(NULL), 72 profile_(NULL),
64 closed_by_button_(false), 73 closed_by_button_(false),
Ivan Korotkov 2011/10/19 20:24:37 browser_(NULL) after profile_
whywhat 2011/10/20 20:50:10 Done.
65 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 74 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
66 DCHECK(changes.size() > 0); 75 DCHECK(changes.size() > 0);
67 } 76 }
68 77
69 SettingsChangeGlobalError::~SettingsChangeGlobalError() { 78 SettingsChangeGlobalError::~SettingsChangeGlobalError() {
70 } 79 }
71 80
72 bool SettingsChangeGlobalError::HasBadge() { 81 bool SettingsChangeGlobalError::HasBadge() {
73 return true; 82 return true;
74 } 83 }
75 84
76 bool SettingsChangeGlobalError::HasMenuItem() { 85 bool SettingsChangeGlobalError::HasMenuItem() {
77 return true; 86 return true;
78 } 87 }
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 change.old_setting.empty() ? 132 string16 old_setting = change->GetOldSetting();
117 l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_OPEN_SETTINGS) : 133 if (old_setting.empty()) {
118 l10n_util::GetStringFUTF16(kBubbleKeepSettingIDs[change.type], 134 return l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_OPEN_SETTINGS);
119 change.old_setting); 135 } else {
136 return l10n_util::GetStringFUTF16(
137 kBubbleKeepSettingIDs[change->type()],
138 old_setting);
139 }
120 } 140 }
121 141
122 string16 SettingsChangeGlobalError::GetBubbleViewCancelButtonLabel() { 142 string16 SettingsChangeGlobalError::GetBubbleViewCancelButtonLabel() {
123 const Change& change = changes_.front(); 143 scoped_refptr<SettingChange> change = changes_.front();
124 return l10n_util::GetStringFUTF16(kBubbleChangeSettingIDs[change.type], 144 return l10n_util::GetStringFUTF16(kBubbleChangeSettingIDs[change->type()],
125 change.new_setting); 145 change->GetNewSetting());
126 } 146 }
127 147
128 void SettingsChangeGlobalError::BubbleViewAcceptButtonPressed() { 148 void SettingsChangeGlobalError::BubbleViewAcceptButtonPressed() {
129 VLOG(1) << "Restore changes"; 149 VLOG(1) << "Restore changes";
130 restore_changes_cb_.Run(); 150 restore_changes_cb_.Run();
131 closed_by_button_ = true; 151 closed_by_button_ = true;
132 } 152 }
133 153
134 void SettingsChangeGlobalError::BubbleViewCancelButtonPressed() { 154 void SettingsChangeGlobalError::BubbleViewCancelButtonPressed() {
135 VLOG(1) << "Make changes"; 155 VLOG(1) << "Make changes";
136 make_changes_cb_.Run(); 156 make_changes_cb_.Run();
137 closed_by_button_ = true; 157 closed_by_button_ = true;
138 } 158 }
139 159
140 void SettingsChangeGlobalError::RemoveFromProfile() { 160 void SettingsChangeGlobalError::RemoveFromProfile() {
141 if (profile_) 161 if (profile_)
142 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this); 162 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(this);
143 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); 163 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
144 } 164 }
145 165
146 void SettingsChangeGlobalError::BubbleViewDidClose() { 166 void SettingsChangeGlobalError::BubbleViewDidClose() {
167 browser_ = NULL;
147 if (!closed_by_button_) { 168 if (!closed_by_button_) {
148 BrowserThread::PostDelayedTask( 169 BrowserThread::PostDelayedTask(
149 BrowserThread::UI, FROM_HERE, 170 BrowserThread::UI, FROM_HERE,
150 base::Bind(&SettingsChangeGlobalError::RemoveFromProfile, 171 base::Bind(&SettingsChangeGlobalError::RemoveFromProfile,
151 weak_factory_.GetWeakPtr()), 172 weak_factory_.GetWeakPtr()),
152 kMenuItemDisplayPeriodMs); 173 kMenuItemDisplayPeriodMs);
153 } else { 174 } else {
154 RemoveFromProfile(); 175 RemoveFromProfile();
155 } 176 }
156 } 177 }
(...skipping 12 matching lines...) Expand all
169 void SettingsChangeGlobalError::AddToDefaultProfile() { 190 void SettingsChangeGlobalError::AddToDefaultProfile() {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
171 profile_ = ProfileManager::GetDefaultProfile(); 192 profile_ = ProfileManager::GetDefaultProfile();
172 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this); 193 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(this);
173 Show(); 194 Show();
174 } 195 }
175 196
176 void SettingsChangeGlobalError::Show() { 197 void SettingsChangeGlobalError::Show() {
177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
178 DCHECK(profile_); 199 DCHECK(profile_);
179 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); 200 browser_ = BrowserList::GetLastActiveWithProfile(profile_);
180 if (browser) 201 if (browser_)
181 ShowBubbleView(browser); 202 ShowBubbleView(browser_);
182 } 203 }
204
205 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698