Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/protector/protector.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/stl_util.h" | |
| 9 #include "chrome/browser/protector/settings_change_global_error.h" | |
| 10 #include "chrome/browser/protector/keys.h" | |
| 11 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 12 #include "chrome/browser/ui/browser.h" | |
| 13 #include "content/browser/browser_thread.h" | |
| 14 #include "crypto/hmac.h" | |
| 15 | |
| 16 namespace protector { | |
| 17 | |
| 18 Protector::Protector() { | |
| 19 } | |
| 20 | |
| 21 Protector::~Protector() { | |
| 22 STLDeleteElements(&changes_); | |
| 23 } | |
| 24 | |
| 25 void Protector::AddChange(SettingChange* change) { | |
| 26 if (error_.get()) { | |
| 27 NOTREACHED() << "Adding setting change after showing the error."; | |
| 28 return; | |
| 29 } | |
| 30 changes_.push_back(change); | |
| 31 } | |
| 32 | |
| 33 void Protector::NotifyUser() { | |
| 34 DCHECK(!changes_.empty()); | |
| 35 | |
| 36 error_.reset(new SettingsChangeGlobalError(changes_, this)); | |
| 37 error_->ShowForDefaultProfile(); | |
| 38 } | |
| 39 | |
| 40 void Protector::OpenTab(const GURL& url) { | |
| 41 if (!error_.get() || !error_->browser()) { | |
| 42 LOG(WARNING) << "Don't have browser to show tab in."; | |
| 43 return; | |
| 44 } | |
| 45 error_->browser()->ShowSingletonTab(url); | |
| 46 } | |
| 47 | |
| 48 TemplateURLService* Protector::GetTemplateURLService() { | |
| 49 if (!error_.get() || !error_->profile()) { | |
| 50 LOG(WARNING) << "Don't have profile to get to search engines."; | |
| 51 return NULL; | |
| 52 } | |
| 53 return TemplateURLServiceFactory::GetForProfile(error_->profile()); | |
| 54 } | |
| 55 | |
| 56 void Protector::OnApplyChanges() { | |
| 57 for (size_t i = 0; i < changes_.size(); ++i) | |
| 58 changes_[i]->Accept(this); | |
| 59 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | |
| 60 } | |
| 61 | |
| 62 void Protector::OnDiscardChanges() { | |
| 63 for (size_t i = 0; i < changes_.size(); ++i) | |
| 64 changes_[i]->Revert(this); | |
| 65 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | |
| 66 } | |
| 67 | |
| 68 void Protector::OnDecisionTimeout() { | |
| 69 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.
| |
| 70 } | |
| 71 | |
| 72 | |
| 73 void NotifyUserOfChange(SettingChange* change) { | |
| 74 Protector* protector = new Protector(); | |
| 75 protector->AddChange(change); | |
| 76 protector->NotifyUser(); | |
| 77 } | |
| 78 | |
| 79 std::string SignSetting(const std::string& value) { | |
| 80 crypto::HMAC hmac(crypto::HMAC::SHA256); | |
| 81 DCHECK(hmac.Init(kProtectorSigningKey)); | |
| 82 | |
| 83 std::vector<unsigned char> digest(hmac.DigestLength()); | |
| 84 DCHECK(hmac.Sign(value, &digest[0], digest.size())); | |
| 85 | |
| 86 return std::string(&digest[0], &digest[0] + digest.size()); | |
| 87 } | |
| 88 | |
| 89 } // namespace protector | |
| OLD | NEW |