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

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 changes in separate files. Simplified objects ownership. 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..9c760b0af6d6c427a146601b103e6cfd4007aea7
--- /dev/null
+++ b/chrome/browser/protector/protector.cc
@@ -0,0 +1,89 @@
+// 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 "base/stl_util.h"
+#include "chrome/browser/protector/settings_change_global_error.h"
+#include "chrome/browser/protector/keys.h"
+#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/ui/browser.h"
+#include "content/browser/browser_thread.h"
+#include "crypto/hmac.h"
+
+namespace protector {
+
+Protector::Protector() {
+}
+
+Protector::~Protector() {
+ STLDeleteElements(&changes_);
+}
+
+void Protector::AddChange(SettingChange* change) {
+ if (error_.get()) {
+ NOTREACHED() << "Adding setting change after showing the error.";
+ return;
+ }
+ changes_.push_back(change);
+}
+
+void Protector::NotifyUser() {
+ DCHECK(!changes_.empty());
+
+ error_.reset(new SettingsChangeGlobalError(changes_, this));
+ error_->ShowForDefaultProfile();
+}
+
+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() {
+ if (!error_.get() || !error_->profile()) {
+ LOG(WARNING) << "Don't have profile to get to search engines.";
+ return NULL;
+ }
+ return TemplateURLServiceFactory::GetForProfile(error_->profile());
+}
+
+void Protector::OnApplyChanges() {
+ for (size_t i = 0; i < changes_.size(); ++i)
+ changes_[i]->Accept(this);
+ BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
+}
+
+void Protector::OnDiscardChanges() {
+ for (size_t i = 0; i < changes_.size(); ++i)
+ changes_[i]->Revert(this);
+ BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
+}
+
+void Protector::OnDecisionTimeout() {
+ OnDiscardChanges();
Ivan Korotkov 2011/10/20 21:04:52 This means the settings page will be opened automa
whywhat 2011/10/20 23:02:39 Right, fixed.
+}
+
+
+void NotifyUserOfChange(SettingChange* change) {
+ Protector* protector = new Protector();
+ protector->AddChange(change);
+ protector->NotifyUser();
+}
+
+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