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

Unified Diff: chrome/browser/protector/default_search_provider_change.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 comment 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/default_search_provider_change.cc
diff --git a/chrome/browser/protector/default_search_provider_change.cc b/chrome/browser/protector/default_search_provider_change.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a395e71103cad29bcc1c827091be2d0057a14148
--- /dev/null
+++ b/chrome/browser/protector/default_search_provider_change.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "chrome/browser/protector/protector.h"
+#include "chrome/browser/protector/setting_change.h"
+#include "chrome/browser/search_engines/template_url.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/webdata/keyword_table.h"
+#include "chrome/common/url_constants.h"
+#include "googleurl/src/gurl.h"
+
+namespace protector {
+
+class DefaultSearchProviderChange : public SettingChange {
+ public:
+ DefaultSearchProviderChange(const TemplateURL* old_url,
+ const TemplateURL* new_url);
+
+ // SettingChange overrides:
+ virtual string16 GetOldSetting() const OVERRIDE;
+ virtual string16 GetNewSetting() const OVERRIDE;
+ virtual void Accept(Protector* protector) OVERRIDE;
+ virtual void Revert(Protector* protector) OVERRIDE;
+ virtual void DoDefault(Protector* protector) OVERRIDE;
+
+ private:
+ ~DefaultSearchProviderChange();
sky 2011/10/21 21:34:11 virtual
whywhat 2011/10/24 15:30:17 Done.
+
+ // Sets the given default search provider to profile that |protector| is
+ // guarding.
+ void SetDefaultSearchProvider(Protector* protector, const TemplateURL* url);
+
+ const TemplateURL* old_url_;
+ const TemplateURL* new_url_;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange);
+};
+
+DefaultSearchProviderChange::DefaultSearchProviderChange(
+ const TemplateURL* old_url,
+ const TemplateURL* new_url)
+ : SettingChange(kSearchEngineChanged),
+ old_url_(old_url),
+ new_url_(new_url) {
+ DCHECK(new_url_);
+}
+
+DefaultSearchProviderChange::~DefaultSearchProviderChange() {
+}
+
+string16 DefaultSearchProviderChange::GetOldSetting() const {
+ if (old_url_)
+ return old_url_->short_name();
+ else
+ return string16();
+}
+
+string16 DefaultSearchProviderChange::GetNewSetting() const {
+ DCHECK(new_url_);
+ return new_url_->short_name();
+}
+
+void DefaultSearchProviderChange::Accept(Protector* protector) {
+ SetDefaultSearchProvider(protector, new_url_);
+ // TODO(avayvod): Add histrogram.
+}
+
+void DefaultSearchProviderChange::Revert(Protector* protector) {
+ SetDefaultSearchProvider(protector, old_url_);
+ if (!old_url_) {
+ // Open settings page in case the original setting was lost.
+ protector->OpenTab(
+ GURL(std::string(chrome::kChromeUISettingsURL) +
+ chrome::kSearchEnginesSubPage));
+ }
+ // TODO(avayvod): Add histrogram.
+}
+
+void DefaultSearchProviderChange::DoDefault(Protector* protector) {
+ SetDefaultSearchProvider(protector, old_url_);
+ // TODO(avayvod): Add histrogram.
+}
+
+void DefaultSearchProviderChange::SetDefaultSearchProvider(
+ Protector* protector,
+ const TemplateURL* url) {
+ DCHECK(protector);
+ TemplateURLService* url_service = protector->GetTemplateURLService();
+ if (!url_service) {
+ LOG(WARNING) << "Can't get TemplateURLService object.";
+ return;
+ }
+ if (!url) {
+ // Select the first among search providers as default.
+ const TemplateURLService::TemplateURLVector& urls =
+ url_service->GetTemplateURLs();
+ if (!urls.empty())
+ url = urls.front();
sky 2011/10/21 21:34:11 The first may be a poor choice. Better to choose o
whywhat 2011/10/24 15:30:17 Done. I had to make FindNewDefaultSearchProvider m
+ }
+ url_service->ForceSetDefaultSearchProvider(url);
+}
+
+SettingChange* CreateDefaultSearchProviderChange(
+ const TemplateURL* actual,
+ const TemplateURL* backup) {
+ return new DefaultSearchProviderChange(backup, actual);
+}
+
+} // namespace protector
« no previous file with comments | « no previous file | chrome/browser/protector/keys.h » ('j') | chrome/browser/protector/settings_change_global_error.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698