OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_service.h" | 5 #include "chrome/browser/protector/protector_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/protector/settings_change_global_error.h" | 11 #include "chrome/browser/protector/settings_change_global_error.h" |
12 #include "chrome/browser/protector/keys.h" | 12 #include "chrome/browser/protector/keys.h" |
| 13 #include "chrome/browser/protector/protected_prefs_watcher.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 "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
18 #include "crypto/hmac.h" | 19 #include "crypto/hmac.h" |
19 | 20 |
20 namespace protector { | 21 namespace protector { |
21 | 22 |
22 ProtectorService::ProtectorService(Profile* profile) | 23 ProtectorService::ProtectorService(Profile* profile) |
23 : profile_(profile), | 24 : profile_(profile), |
24 has_active_change_(false) { | 25 has_active_change_(false) { |
| 26 // Start observing pref changes. |
| 27 prefs_watcher_.reset(new ProtectedPrefsWatcher(profile)); |
25 } | 28 } |
26 | 29 |
27 ProtectorService::~ProtectorService() { | 30 ProtectorService::~ProtectorService() { |
28 DCHECK(!IsShowingChange()); // Should have been dismissed by Shutdown. | 31 DCHECK(!IsShowingChange()); // Should have been dismissed by Shutdown. |
29 } | 32 } |
30 | 33 |
31 void ProtectorService::ShowChange(BaseSettingChange* change) { | 34 void ProtectorService::ShowChange(BaseSettingChange* change) { |
32 DCHECK(change); | 35 DCHECK(change); |
33 Item new_item; | 36 Item new_item; |
34 new_item.change.reset(change); | 37 new_item.change.reset(change); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 std::find_if(items_.begin(), items_.end(), MatchItemByChange(change)); | 70 std::find_if(items_.begin(), items_.end(), MatchItemByChange(change)); |
68 DCHECK(item != items_.end()); | 71 DCHECK(item != items_.end()); |
69 item->error->RemoveFromProfile(); | 72 item->error->RemoveFromProfile(); |
70 } | 73 } |
71 | 74 |
72 void ProtectorService::OpenTab(const GURL& url, Browser* browser) { | 75 void ProtectorService::OpenTab(const GURL& url, Browser* browser) { |
73 DCHECK(browser); | 76 DCHECK(browser); |
74 browser->ShowSingletonTab(url); | 77 browser->ShowSingletonTab(url); |
75 } | 78 } |
76 | 79 |
| 80 ProtectedPrefsWatcher* ProtectorService::GetPrefsWatcher() { |
| 81 return prefs_watcher_.get(); |
| 82 } |
| 83 |
77 void ProtectorService::Shutdown() { | 84 void ProtectorService::Shutdown() { |
78 while (IsShowingChange()) | 85 while (IsShowingChange()) |
79 items_[0].error->RemoveFromProfile(); | 86 items_[0].error->RemoveFromProfile(); |
80 } | 87 } |
81 | 88 |
82 void ProtectorService::OnApplyChange(SettingsChangeGlobalError* error, | 89 void ProtectorService::OnApplyChange(SettingsChangeGlobalError* error, |
83 Browser* browser) { | 90 Browser* browser) { |
84 DVLOG(1) << "Apply change"; | 91 DVLOG(1) << "Apply change"; |
85 error->change()->Apply(browser); | 92 error->change()->Apply(browser); |
86 has_active_change_ = false; | 93 has_active_change_ = false; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return false; | 175 return false; |
169 } | 176 } |
170 return hmac.Verify(value, signature); | 177 return hmac.Verify(value, signature); |
171 } | 178 } |
172 | 179 |
173 bool IsEnabled() { | 180 bool IsEnabled() { |
174 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoProtector); | 181 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoProtector); |
175 } | 182 } |
176 | 183 |
177 } // namespace protector | 184 } // namespace protector |
OLD | NEW |