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

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

Issue 8342049: Added Protector, hooked up DSE verification with error bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved changes in separate files. Simplified objects ownership. Created 9 years, 2 months 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
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698