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

Side by Side Diff: chrome/browser/protector/protector.cc

Issue 8558020: Protector strings and bubble/SettingsChange code refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: This time it really should compile. Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/protector/protector.h ('k') | chrome/browser/protector/setting_change.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
32 LOG(WARNING) << "Don't have browser to show tab in."; 33 LOG(WARNING) << "Don't have browser to show tab in.";
33 return; 34 return;
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(BaseSettingChange* change) {
43 DCHECK(change); 44 DCHECK(change);
44 SettingChangeVector changes(1, change); 45 BrowserThread::PostTask(
46 BrowserThread::UI, FROM_HERE,
47 base::Bind(&Protector::InitAndShowChange,
48 base::Unretained(this), change));
49 }
45 50
46 error_.reset(new SettingsChangeGlobalError(changes, this)); 51 void Protector::InitAndShowChange(BaseSettingChange* change) {
52 VLOG(1) << "Init change";
53 if (!change->Init(this)) {
54 VLOG(1) << "Error while initializing, removing ourselves";
55 delete change;
56 OnRemovedFromProfile();
57 return;
58 }
59 error_.reset(new SettingsChangeGlobalError(change, this));
47 error_->ShowForProfile(profile_); 60 error_->ShowForProfile(profile_);
48 } 61 }
49 62
50 void Protector::OnApplyChanges() { 63 void Protector::OnApplyChange() {
51 OnChangesAction(&SettingChange::Accept); 64 VLOG(1) << "Apply change";
65 error_->mutable_change()->Apply(this);
52 } 66 }
53 67
54 void Protector::OnDiscardChanges() { 68 void Protector::OnDiscardChange() {
55 OnChangesAction(&SettingChange::Revert); 69 VLOG(1) << "Discard change";
70 error_->mutable_change()->Discard(this);
56 } 71 }
57 72
58 void Protector::OnDecisionTimeout() { 73 void Protector::OnDecisionTimeout() {
59 OnChangesAction(&SettingChange::DoDefault); 74 // TODO(ivankr): Add histogram.
75 VLOG(1) << "Timeout";
60 } 76 }
61 77
62 void Protector::OnRemovedFromProfile() { 78 void Protector::OnRemovedFromProfile() {
63 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); 79 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
64 } 80 }
65 81
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 82
75 std::string SignSetting(const std::string& value) { 83 std::string SignSetting(const std::string& value) {
76 crypto::HMAC hmac(crypto::HMAC::SHA256); 84 crypto::HMAC hmac(crypto::HMAC::SHA256);
77 if (!hmac.Init(kProtectorSigningKey)) { 85 if (!hmac.Init(kProtectorSigningKey)) {
78 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing"; 86 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing";
79 return std::string(); 87 return std::string();
80 } 88 }
81 89
82 std::vector<unsigned char> digest(hmac.DigestLength()); 90 std::vector<unsigned char> digest(hmac.DigestLength());
83 if (!hmac.Sign(value, &digest[0], digest.size())) { 91 if (!hmac.Sign(value, &digest[0], digest.size())) {
84 LOG(WARNING) << "Failed to sign setting"; 92 LOG(WARNING) << "Failed to sign setting";
85 return std::string(); 93 return std::string();
86 } 94 }
87 95
88 return std::string(&digest[0], &digest[0] + digest.size()); 96 return std::string(&digest[0], &digest[0] + digest.size());
89 } 97 }
90 98
91 bool IsSettingValid(const std::string& value, const std::string& signature) { 99 bool IsSettingValid(const std::string& value, const std::string& signature) {
92 crypto::HMAC hmac(crypto::HMAC::SHA256); 100 crypto::HMAC hmac(crypto::HMAC::SHA256);
93 if (!hmac.Init(kProtectorSigningKey)) { 101 if (!hmac.Init(kProtectorSigningKey)) {
94 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; 102 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification.";
95 return false; 103 return false;
96 } 104 }
97 return hmac.Verify(value, signature); 105 return hmac.Verify(value, signature);
98 } 106 }
99 107
100 } // namespace protector 108 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/protector.h ('k') | chrome/browser/protector/setting_change.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698