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

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 check to Protector, work with search engines via TemplateURLService 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 "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 TemplateURLService* template_url_service =
24 GetTemplateURLService();
25 registrar_.Add(
26 this,
27 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED,
28 content::Source<TemplateURLService>(template_url_service));
29 }
30
31 Protector::~Protector() {
32 }
33
34 void Protector::OpenTab(const GURL& url) {
35 if (!error_.get() || !error_->browser()) {
36 LOG(WARNING) << "Don't have browser to show tab in.";
37 return;
38 }
39 error_->browser()->ShowSingletonTab(url);
40 }
41
42 TemplateURLService* Protector::GetTemplateURLService() {
43 return TemplateURLServiceFactory::GetForProfile(profile_);
44 }
45
46 void Protector::OnApplyChanges() {
47 OnChangesAction(&SettingChange::Accept);
48 }
49
50 void Protector::OnDiscardChanges() {
51 OnChangesAction(&SettingChange::Revert);
52 }
53
54 void Protector::OnDecisionTimeout() {
55 OnChangesAction(&SettingChange::DoDefault);
56 }
57
58 void Protector::Observe(int type,
59 const content::NotificationSource& source,
60 const content::NotificationDetails& details) {
61 DCHECK(type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED);
62 TemplateURLService* template_url_service =
63 content::Source<TemplateURLService>(source).ptr();
64 DCHECK(template_url_service ==
65 TemplateURLServiceFactory::GetForProfile(profile_));
66
67 if (!template_url_service->is_default_search_provider_verified()) {
68 SettingChange* change = CreateDefaultSearchProviderChange(
69 template_url_service->GetDefaultSearchProvider(),
70 template_url_service->backup_default_search_provider());
71 ShowChange(change);
72 }
73 }
74
75 void Protector::ShowChange(SettingChange* change) {
76 DCHECK(change);
77 SettingChangeVector changes(1, change);
78
79 error_.reset(new SettingsChangeGlobalError(changes, this));
80 error_->ShowForProfile(profile_);
81 }
82
83 void Protector::OnChangesAction(SettingChangeAction action) {
84 DCHECK(error_.get());
85 SettingChangeVector* changes = error_->mutable_changes();
86 for (SettingChangeVector::iterator it = changes->begin();
87 it != changes->end(); ++it)
88 ((*it)->*action)(this);
89 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, error_.release());
90 }
91
92
93 std::string SignSetting(const std::string& value) {
94 crypto::HMAC hmac(crypto::HMAC::SHA256);
95 DCHECK(hmac.Init(kProtectorSigningKey));
96
97 std::vector<unsigned char> digest(hmac.DigestLength());
98 DCHECK(hmac.Sign(value, &digest[0], digest.size()));
99
100 return std::string(&digest[0], &digest[0] + digest.size());
101 }
102
103 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698