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

Unified Diff: chrome/browser/protector/protector.cc

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved check to Protector, work with search engines via TemplateURLService 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/protector.cc
diff --git a/chrome/browser/protector/protector.cc b/chrome/browser/protector/protector.cc
new file mode 100644
index 0000000000000000000000000000000000000000..93b1d037e75d2b2267c4b6125bf58ddb0ff3ca47
--- /dev/null
+++ b/chrome/browser/protector/protector.cc
@@ -0,0 +1,103 @@
+// 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 "chrome/browser/protector/protector.h"
+
+#include "base/logging.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/protector/settings_change_global_error.h"
+#include "chrome/browser/protector/keys.h"
+#include "chrome/browser/search_engines/template_url_service.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/browser/browser_thread.h"
+#include "content/public/browser/notification_source.h"
+#include "crypto/hmac.h"
+
+namespace protector {
+
+Protector::Protector(Profile* profile)
+ : profile_(profile) {
+ TemplateURLService* template_url_service =
+ GetTemplateURLService();
+ registrar_.Add(
+ this,
+ chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
+ content::Source<TemplateURLService>(template_url_service));
+}
+
+Protector::~Protector() {
+}
+
+void Protector::OpenTab(const GURL& url) {
+ if (!error_.get() || !error_->browser()) {
+ LOG(WARNING) << "Don't have browser to show tab in.";
+ return;
+ }
+ error_->browser()->ShowSingletonTab(url);
+}
+
+TemplateURLService* Protector::GetTemplateURLService() {
+ return TemplateURLServiceFactory::GetForProfile(profile_);
+}
+
+void Protector::OnApplyChanges() {
+ OnChangesAction(&SettingChange::Accept);
+}
+
+void Protector::OnDiscardChanges() {
+ OnChangesAction(&SettingChange::Revert);
+}
+
+void Protector::OnDecisionTimeout() {
+ OnChangesAction(&SettingChange::DoDefault);
+}
+
+void Protector::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED);
+ TemplateURLService* template_url_service =
+ content::Source<TemplateURLService>(source).ptr();
+ DCHECK(template_url_service ==
+ TemplateURLServiceFactory::GetForProfile(profile_));
+
+ if (!template_url_service->is_default_search_provider_verified()) {
+ SettingChange* change = CreateDefaultSearchProviderChange(
+ template_url_service->GetDefaultSearchProvider(),
+ template_url_service->backup_default_search_provider());
+ ShowChange(change);
+ }
+}
+
+void Protector::ShowChange(SettingChange* change) {
+ DCHECK(change);
+ SettingChangeVector changes(1, change);
+
+ error_.reset(new SettingsChangeGlobalError(changes, this));
+ error_->ShowForProfile(profile_);
+}
+
+void Protector::OnChangesAction(SettingChangeAction action) {
+ DCHECK(error_.get());
+ SettingChangeVector* changes = error_->mutable_changes();
+ for (SettingChangeVector::iterator it = changes->begin();
+ it != changes->end(); ++it)
+ ((*it)->*action)(this);
+ BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, error_.release());
+}
+
+
+std::string SignSetting(const std::string& value) {
+ crypto::HMAC hmac(crypto::HMAC::SHA256);
+ DCHECK(hmac.Init(kProtectorSigningKey));
+
+ std::vector<unsigned char> digest(hmac.DigestLength());
+ DCHECK(hmac.Sign(value, &digest[0], digest.size()));
+
+ return std::string(&digest[0], &digest[0] + digest.size());
+}
+
+} // namespace protector

Powered by Google App Engine
This is Rietveld 408576698