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

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

Issue 8586050: Revert 110684 - Protector strings and bubble/SettingsChange code refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/protector/settings_change_global_error.h" 9 #include "chrome/browser/protector/settings_change_global_error.h"
11 #include "chrome/browser/protector/keys.h" 10 #include "chrome/browser/protector/keys.h"
12 #include "chrome/browser/search_engines/template_url_service.h" 11 #include "chrome/browser/search_engines/template_url_service.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h"
14 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
16 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
(...skipping 17 matching lines...) Expand all
35 } 34 }
36 error_->browser()->ShowSingletonTab(url); 35 error_->browser()->ShowSingletonTab(url);
37 } 36 }
38 37
39 TemplateURLService* Protector::GetTemplateURLService() { 38 TemplateURLService* Protector::GetTemplateURLService() {
40 return TemplateURLServiceFactory::GetForProfile(profile_); 39 return TemplateURLServiceFactory::GetForProfile(profile_);
41 } 40 }
42 41
43 void Protector::ShowChange(SettingChange* change) { 42 void Protector::ShowChange(SettingChange* change) {
44 DCHECK(change); 43 DCHECK(change);
45 BrowserThread::PostTask( 44 SettingChangeVector changes(1, change);
46 BrowserThread::UI, FROM_HERE,
47 base::Bind(&Protector::InitAndShowChange,
48 base::Unretained(this), change));
49 }
50 45
51 void Protector::InitAndShowChange(SettingChange* change) { 46 error_.reset(new SettingsChangeGlobalError(changes, this));
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));
60 error_->ShowForProfile(profile_); 47 error_->ShowForProfile(profile_);
61 } 48 }
62 49
63 void Protector::OnApplyChange() { 50 void Protector::OnApplyChanges() {
64 VLOG(1) << "Apply change"; 51 OnChangesAction(&SettingChange::Accept);
65 error_->mutable_change()->Apply(this);
66 } 52 }
67 53
68 void Protector::OnDiscardChange() { 54 void Protector::OnDiscardChanges() {
69 VLOG(1) << "Discard change"; 55 OnChangesAction(&SettingChange::Revert);
70 error_->mutable_change()->Discard(this);
71 } 56 }
72 57
73 void Protector::OnDecisionTimeout() { 58 void Protector::OnDecisionTimeout() {
74 // TODO(ivankr): Add histogram. 59 OnChangesAction(&SettingChange::DoDefault);
75 VLOG(1) << "Timeout";
76 } 60 }
77 61
78 void Protector::OnRemovedFromProfile() { 62 void Protector::OnRemovedFromProfile() {
79 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); 63 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
80 } 64 }
81 65
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
82 74
83 std::string SignSetting(const std::string& value) { 75 std::string SignSetting(const std::string& value) {
84 crypto::HMAC hmac(crypto::HMAC::SHA256); 76 crypto::HMAC hmac(crypto::HMAC::SHA256);
85 if (!hmac.Init(kProtectorSigningKey)) { 77 if (!hmac.Init(kProtectorSigningKey)) {
86 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing"; 78 LOG(WARNING) << "Failed to initialize HMAC algorithm for signing";
87 return std::string(); 79 return std::string();
88 } 80 }
89 81
90 std::vector<unsigned char> digest(hmac.DigestLength()); 82 std::vector<unsigned char> digest(hmac.DigestLength());
91 if (!hmac.Sign(value, &digest[0], digest.size())) { 83 if (!hmac.Sign(value, &digest[0], digest.size())) {
92 LOG(WARNING) << "Failed to sign setting"; 84 LOG(WARNING) << "Failed to sign setting";
93 return std::string(); 85 return std::string();
94 } 86 }
95 87
96 return std::string(&digest[0], &digest[0] + digest.size()); 88 return std::string(&digest[0], &digest[0] + digest.size());
97 } 89 }
98 90
99 bool IsSettingValid(const std::string& value, const std::string& signature) { 91 bool IsSettingValid(const std::string& value, const std::string& signature) {
100 crypto::HMAC hmac(crypto::HMAC::SHA256); 92 crypto::HMAC hmac(crypto::HMAC::SHA256);
101 if (!hmac.Init(kProtectorSigningKey)) { 93 if (!hmac.Init(kProtectorSigningKey)) {
102 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification."; 94 LOG(WARNING) << "Failed to initialize HMAC algorithm for verification.";
103 return false; 95 return false;
104 } 96 }
105 return hmac.Verify(value, signature); 97 return hmac.Verify(value, signature);
106 } 98 }
107 99
108 } // namespace protector 100 } // 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