| 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 "chrome/browser/profiles/profile.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.h" |
| 12 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "content/browser/browser_thread.h" |
| 16 #include "content/public/browser/notification_source.h" |
| 17 #include "crypto/hmac.h" |
| 18 |
| 19 namespace protector { |
| 20 |
| 21 Protector::Protector(Profile* profile) |
| 22 : profile_(profile) { |
| 23 } |
| 24 |
| 25 Protector::~Protector() { |
| 26 } |
| 27 |
| 28 void Protector::OpenTab(const GURL& url) { |
| 29 if (!error_.get() || !error_->browser()) { |
| 30 LOG(WARNING) << "Don't have browser to show tab in."; |
| 31 return; |
| 32 } |
| 33 error_->browser()->ShowSingletonTab(url); |
| 34 } |
| 35 |
| 36 TemplateURLService* Protector::GetTemplateURLService() { |
| 37 return TemplateURLServiceFactory::GetForProfile(profile_); |
| 38 } |
| 39 |
| 40 void Protector::ShowChange(SettingChange* change) { |
| 41 DCHECK(change); |
| 42 SettingChangeVector changes(1, change); |
| 43 |
| 44 error_.reset(new SettingsChangeGlobalError(changes, this)); |
| 45 error_->ShowForProfile(profile_); |
| 46 } |
| 47 |
| 48 void Protector::OnApplyChanges() { |
| 49 OnChangesAction(&SettingChange::Accept); |
| 50 } |
| 51 |
| 52 void Protector::OnDiscardChanges() { |
| 53 OnChangesAction(&SettingChange::Revert); |
| 54 } |
| 55 |
| 56 void Protector::OnDecisionTimeout() { |
| 57 OnChangesAction(&SettingChange::DoDefault); |
| 58 } |
| 59 |
| 60 void Protector::OnChangesAction(SettingChangeAction action) { |
| 61 DCHECK(error_.get()); |
| 62 SettingChangeVector* changes = error_->mutable_changes(); |
| 63 for (SettingChangeVector::iterator it = changes->begin(); |
| 64 it != changes->end(); ++it) |
| 65 ((*it)->*action)(this); |
| 66 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 67 } |
| 68 |
| 69 |
| 70 std::string SignSetting(const std::string& value) { |
| 71 crypto::HMAC hmac(crypto::HMAC::SHA256); |
| 72 DCHECK(hmac.Init(kProtectorSigningKey)); |
| 73 |
| 74 std::vector<unsigned char> digest(hmac.DigestLength()); |
| 75 DCHECK(hmac.Sign(value, &digest[0], digest.size())); |
| 76 |
| 77 return std::string(&digest[0], &digest[0] + digest.size()); |
| 78 } |
| 79 |
| 80 } // namespace protector |
| OLD | NEW |