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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/protector/settings_change_global_error.cc
diff --git a/chrome/browser/protector/settings_change_global_error.cc b/chrome/browser/protector/settings_change_global_error.cc
index cbeb0565379f203103431497cc7b7def9a75cc61..be78bc1b383e0e453c2ffe0b1c654163af8f8121 100644
--- a/chrome/browser/protector/settings_change_global_error.cc
+++ b/chrome/browser/protector/settings_change_global_error.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/protector/settings_change_global_error.h"
#include "base/bind.h"
+#include "base/logging.h"
#include "base/task.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
@@ -16,35 +17,43 @@
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+namespace protector {
+
namespace {
// Timeout before the global error is removed (wrench menu item disappears).
const int kMenuItemDisplayPeriodMs = 10*60*1000; // 10 min
+
// IDs of menu item labels.
const int kMenuItemLabelIDs[] = {
IDS_SEARCH_ENGINE_CHANGE_WRENCH_MENU_ITEM,
IDS_HOMEPAGE_CHANGE_WRENCH_MENU_ITEM
};
+
// IDs of bubble title messages.
const int kBubbleTitleIDs[] = {
IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TITLE,
IDS_HOMEPAGE_CHANGE_BUBBLE_TITLE
};
+
// IDs of bubble text messages.
const int kBubbleMessageIDs[] = {
IDS_SEARCH_ENGINE_CHANGE_BUBBLE_TEXT,
IDS_HOMEPAGE_CHANGE_BUBBLE_TEXT
};
+
// IDs of bubble text messages when the old setting is unknown.
const int kBubbleMessageOldUnknownIDs[] = {
IDS_SEARCH_ENGINE_CHANGE_UNKNOWN_BUBBLE_TEXT,
IDS_HOMEPAGE_CHANGE_UNKNOWN_BUBBLE_TEXT
};
+
// IDs of "Keep Setting" button titles.
const int kBubbleKeepSettingIDs[] = {
IDS_SEARCH_ENGINE_CHANGE_RESTORE,
IDS_HOMEPAGE_CHANGE_RESTORE
};
+
// IDs of "Change Setting" button titles.
const int kBubbleChangeSettingIDs[] = {
IDS_SEARCH_ENGINE_CHANGE_APPLY,
@@ -54,7 +63,7 @@ const int kBubbleChangeSettingIDs[] = {
} // namespace
SettingsChangeGlobalError::SettingsChangeGlobalError(
- const ChangesVector& changes,
+ const Protector::ChangesVector& changes,
const base::Closure& make_changes_cb,
const base::Closure& restore_changes_cb)
: changes_(changes),
@@ -86,12 +95,13 @@ int SettingsChangeGlobalError::MenuItemCommandID() {
// can display warning about multiple changes.
string16 SettingsChangeGlobalError::MenuItemLabel() {
- return l10n_util::GetStringUTF16(kMenuItemLabelIDs[changes_.front().type]);
+ return l10n_util::GetStringUTF16(kMenuItemLabelIDs[changes_.front()->type()]);
}
void SettingsChangeGlobalError::ExecuteMenuItem(Browser* browser) {
weak_factory_.InvalidateWeakPtrs(); // Cancel previously posted tasks.
- ShowBubbleView(browser);
+ browser_ = browser;
+ ShowBubbleView(browser_);
}
bool SettingsChangeGlobalError::HasBubbleView() {
@@ -99,30 +109,40 @@ bool SettingsChangeGlobalError::HasBubbleView() {
}
string16 SettingsChangeGlobalError::GetBubbleViewTitle() {
- return l10n_util::GetStringUTF16(kBubbleTitleIDs[changes_.front().type]);
+ return l10n_util::GetStringUTF16(kBubbleTitleIDs[changes_.front()->type()]);
}
string16 SettingsChangeGlobalError::GetBubbleViewMessage() {
- const Change& change = changes_.front();
- return change.old_setting.empty() ?
- l10n_util::GetStringFUTF16(kBubbleMessageOldUnknownIDs[change.type],
- change.new_setting) :
- l10n_util::GetStringFUTF16(kBubbleMessageIDs[change.type],
- change.old_setting, change.new_setting);
+ scoped_refptr<SettingChange> change = changes_.front();
+ const string16& old_setting = change->GetOldSetting();
+ if (old_setting.empty()) {
+ return l10n_util::GetStringFUTF16(
+ kBubbleMessageOldUnknownIDs[change->type()],
+ change->GetNewSetting());
+ } else {
+ return l10n_util::GetStringFUTF16(
+ kBubbleMessageIDs[change->type()],
+ old_setting,
+ change->GetNewSetting());
+ }
}
string16 SettingsChangeGlobalError::GetBubbleViewAcceptButtonLabel() {
- const Change& change = changes_.front();
- return change.old_setting.empty() ?
- l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_OPEN_SETTINGS) :
- l10n_util::GetStringFUTF16(kBubbleKeepSettingIDs[change.type],
- change.old_setting);
+ scoped_refptr<SettingChange> change = changes_.front();
+ string16 old_setting = change->GetOldSetting();
+ if (old_setting.empty()) {
+ return l10n_util::GetStringUTF16(IDS_SETTINGS_CHANGE_OPEN_SETTINGS);
+ } else {
+ return l10n_util::GetStringFUTF16(
+ kBubbleKeepSettingIDs[change->type()],
+ old_setting);
+ }
}
string16 SettingsChangeGlobalError::GetBubbleViewCancelButtonLabel() {
- const Change& change = changes_.front();
- return l10n_util::GetStringFUTF16(kBubbleChangeSettingIDs[change.type],
- change.new_setting);
+ scoped_refptr<SettingChange> change = changes_.front();
+ return l10n_util::GetStringFUTF16(kBubbleChangeSettingIDs[change->type()],
+ change->GetNewSetting());
}
void SettingsChangeGlobalError::BubbleViewAcceptButtonPressed() {
@@ -144,6 +164,7 @@ void SettingsChangeGlobalError::RemoveFromProfile() {
}
void SettingsChangeGlobalError::BubbleViewDidClose() {
+ browser_ = NULL;
if (!closed_by_button_) {
BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE,
@@ -176,7 +197,9 @@ void SettingsChangeGlobalError::AddToDefaultProfile() {
void SettingsChangeGlobalError::Show() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(profile_);
- Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
- if (browser)
- ShowBubbleView(browser);
+ browser_ = BrowserList::GetLastActiveWithProfile(profile_);
+ if (browser_)
+ ShowBubbleView(browser_);
}
+
+} // namespace protector

Powered by Google App Engine
This is Rietveld 408576698