| 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..96d3c223712da941541d5d063cd76bdd1f0f601e
|
| --- /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() {
|
| + BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
|
| +}
|
| +
|
| +
|
| +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
|
|
|