OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/protector/protector.h" | 5 #include "chrome/browser/protector/protector.h" |
6 | 6 |
7 #include "base/bind.h" | |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/protector/settings_change_global_error.h" | 10 #include "chrome/browser/protector/settings_change_global_error.h" |
10 #include "chrome/browser/protector/keys.h" | 11 #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.h" |
12 #include "chrome/browser/search_engines/template_url_service_factory.h" | 13 #include "chrome/browser/search_engines/template_url_service_factory.h" |
13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
34 } | 35 } |
35 error_->browser()->ShowSingletonTab(url); | 36 error_->browser()->ShowSingletonTab(url); |
36 } | 37 } |
37 | 38 |
38 TemplateURLService* Protector::GetTemplateURLService() { | 39 TemplateURLService* Protector::GetTemplateURLService() { |
39 return TemplateURLServiceFactory::GetForProfile(profile_); | 40 return TemplateURLServiceFactory::GetForProfile(profile_); |
40 } | 41 } |
41 | 42 |
42 void Protector::ShowChange(SettingChange* change) { | 43 void Protector::ShowChange(SettingChange* change) { |
43 DCHECK(change); | 44 DCHECK(change); |
44 SettingChangeVector changes(1, change); | 45 error_.reset(new SettingsChangeGlobalError(change, this)); |
46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
47 base::Bind(&Protector::InitAndShowChange, | |
48 base::Unretained(this))); | |
49 } | |
45 | 50 |
46 error_.reset(new SettingsChangeGlobalError(changes, this)); | 51 void Protector::InitAndShowChange() { |
52 VLOG(1) << "Init change"; | |
53 error_->change()->Init(this); | |
47 error_->ShowForProfile(profile_); | 54 error_->ShowForProfile(profile_); |
48 } | 55 } |
49 | 56 |
50 void Protector::OnApplyChanges() { | 57 void Protector::OnApplyChange() { |
51 OnChangesAction(&SettingChange::Accept); | 58 VLOG(1) << "Apply change"; |
59 error_->change()->Apply(this); | |
52 } | 60 } |
53 | 61 |
54 void Protector::OnDiscardChanges() { | 62 void Protector::OnDiscardChange() { |
55 OnChangesAction(&SettingChange::Revert); | 63 VLOG(1) << "Discard change"; |
64 error_->change()->Discard(this); | |
56 } | 65 } |
57 | 66 |
58 void Protector::OnDecisionTimeout() { | 67 void Protector::OnDecisionTimeout() { |
59 OnChangesAction(&SettingChange::DoDefault); | 68 VLOG(1) << "Timeout"; |
whywhat
2011/11/18 08:18:20
Add a todo for histogram here, please.
Ivan Korotkov
2011/11/18 10:44:25
Done.
| |
60 } | 69 } |
61 | 70 |
62 void Protector::OnRemovedFromProfile() { | 71 void Protector::OnRemovedFromProfile() { |
63 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 72 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
64 } | 73 } |
65 | 74 |
66 void Protector::OnChangesAction(SettingChangeAction action) { | |
67 DCHECK(error_.get()); | |
68 SettingChangeVector* changes = error_->mutable_changes(); | |
69 for (SettingChangeVector::iterator it = changes->begin(); | |
70 it != changes->end(); ++it) | |
71 ((*it)->*action)(this); | |
72 } | |
73 | |
74 | 75 |
75 std::string SignSetting(const std::string& value) { | 76 std::string SignSetting(const std::string& value) { |
76 crypto::HMAC hmac(crypto::HMAC::SHA256); | 77 crypto::HMAC hmac(crypto::HMAC::SHA256); |
77 if (!hmac.Init(kProtectorSigningKey)) { | 78 if (!hmac.Init(kProtectorSigningKey)) { |
78 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing"; | 79 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing"; |
79 return std::string(); | 80 return std::string(); |
80 } | 81 } |
81 | 82 |
82 std::vector<unsigned char> digest(hmac.DigestLength()); | 83 std::vector<unsigned char> digest(hmac.DigestLength()); |
83 if (!hmac.Sign(value, &digest[0], digest.size())) { | 84 if (!hmac.Sign(value, &digest[0], digest.size())) { |
84 LOG(WARNING) << "Failed to sign setting"; | 85 LOG(WARNING) << "Failed to sign setting"; |
85 return std::string(); | 86 return std::string(); |
86 } | 87 } |
87 | 88 |
88 return std::string(&digest[0], &digest[0] + digest.size()); | 89 return std::string(&digest[0], &digest[0] + digest.size()); |
89 } | 90 } |
90 | 91 |
91 bool IsSettingValid(const std::string& value, const std::string& signature) { | 92 bool IsSettingValid(const std::string& value, const std::string& signature) { |
92 crypto::HMAC hmac(crypto::HMAC::SHA256); | 93 crypto::HMAC hmac(crypto::HMAC::SHA256); |
93 if (!hmac.Init(kProtectorSigningKey)) { | 94 if (!hmac.Init(kProtectorSigningKey)) { |
94 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; | 95 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; |
95 return false; | 96 return false; |
96 } | 97 } |
97 return hmac.Verify(value, signature); | 98 return hmac.Verify(value, signature); |
98 } | 99 } |
99 | 100 |
100 } // namespace protector | 101 } // namespace protector |
OLD | NEW |