OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/extensions/blacklist.h" | 5 #include "chrome/browser/extensions/blacklist.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/extensions/blacklist_factory.h" | 19 #include "chrome/browser/extensions/blacklist_factory.h" |
20 #include "chrome/browser/extensions/blacklist_state_fetcher.h" | 20 #include "chrome/browser/extensions/blacklist_state_fetcher.h" |
21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
22 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 22 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
23 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
25 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
26 | 26 |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using safe_browsing::SafeBrowsingDatabaseManager; |
28 | 29 |
29 namespace extensions { | 30 namespace extensions { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // The safe browsing database manager to use. Make this a global/static variable | 34 // The safe browsing database manager to use. Make this a global/static variable |
34 // rather than a member of Blacklist because Blacklist accesses the real | 35 // rather than a member of Blacklist because Blacklist accesses the real |
35 // database manager before it has a chance to get a fake one. | 36 // database manager before it has a chance to get a fake one. |
36 class LazySafeBrowsingDatabaseManager { | 37 class LazySafeBrowsingDatabaseManager { |
37 public: | 38 public: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 157 |
157 Blacklist::ScopedDatabaseManagerForTest::~ScopedDatabaseManagerForTest() { | 158 Blacklist::ScopedDatabaseManagerForTest::~ScopedDatabaseManagerForTest() { |
158 SetDatabaseManager(original_); | 159 SetDatabaseManager(original_); |
159 } | 160 } |
160 | 161 |
161 Blacklist::Blacklist(ExtensionPrefs* prefs) { | 162 Blacklist::Blacklist(ExtensionPrefs* prefs) { |
162 scoped_refptr<SafeBrowsingDatabaseManager> database_manager = | 163 scoped_refptr<SafeBrowsingDatabaseManager> database_manager = |
163 g_database_manager.Get().get(); | 164 g_database_manager.Get().get(); |
164 if (database_manager.get()) { | 165 if (database_manager.get()) { |
165 registrar_.Add( | 166 registrar_.Add( |
166 this, | 167 this, chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
167 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | |
168 content::Source<SafeBrowsingDatabaseManager>(database_manager.get())); | 168 content::Source<SafeBrowsingDatabaseManager>(database_manager.get())); |
169 } | 169 } |
170 | 170 |
171 // Clear out the old prefs-backed blacklist, stored as empty extension entries | 171 // Clear out the old prefs-backed blacklist, stored as empty extension entries |
172 // with just a "blacklisted" property. | 172 // with just a "blacklisted" property. |
173 // | 173 // |
174 // TODO(kalman): Delete this block of code, see http://crbug.com/295882. | 174 // TODO(kalman): Delete this block of code, see http://crbug.com/295882. |
175 std::set<std::string> blacklisted = prefs->GetBlacklistedExtensions(); | 175 std::set<std::string> blacklisted = prefs->GetBlacklistedExtensions(); |
176 for (std::set<std::string>::iterator it = blacklisted.begin(); | 176 for (std::set<std::string>::iterator it = blacklisted.begin(); |
177 it != blacklisted.end(); ++it) { | 177 it != blacklisted.end(); ++it) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 349 } |
350 | 350 |
351 void Blacklist::Observe(int type, | 351 void Blacklist::Observe(int type, |
352 const content::NotificationSource& source, | 352 const content::NotificationSource& source, |
353 const content::NotificationDetails& details) { | 353 const content::NotificationDetails& details) { |
354 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); | 354 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); |
355 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); | 355 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); |
356 } | 356 } |
357 | 357 |
358 } // namespace extensions | 358 } // namespace extensions |
OLD | NEW |