Chromium Code Reviews| 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" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 public: | 37 public: |
| 38 LazySafeBrowsingDatabaseManager() { | 38 LazySafeBrowsingDatabaseManager() { |
| 39 #if defined(SAFE_BROWSING_DB_LOCAL) | 39 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 40 if (g_browser_process && g_browser_process->safe_browsing_service()) { | 40 if (g_browser_process && g_browser_process->safe_browsing_service()) { |
| 41 instance_ = | 41 instance_ = |
| 42 g_browser_process->safe_browsing_service()->database_manager(); | 42 g_browser_process->safe_browsing_service()->database_manager(); |
| 43 } | 43 } |
| 44 #endif | 44 #endif |
| 45 } | 45 } |
| 46 | 46 |
| 47 scoped_refptr<SafeBrowsingDatabaseManager> get() { | 47 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> get() { |
|
Nathan Parker
2015/11/05 22:00:52
My opinion: If there are more than 2 or 3 uses in
vakh (old account. dont use)
2015/11/07 01:22:56
Done.
| |
| 48 return instance_; | 48 return instance_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void set(scoped_refptr<SafeBrowsingDatabaseManager> instance) { | 51 void set(scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> instance) { |
| 52 instance_ = instance; | 52 instance_ = instance; |
| 53 } | 53 } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 scoped_refptr<SafeBrowsingDatabaseManager> instance_; | 56 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> instance_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 static base::LazyInstance<LazySafeBrowsingDatabaseManager> g_database_manager = | 59 static base::LazyInstance<LazySafeBrowsingDatabaseManager> g_database_manager = |
| 60 LAZY_INSTANCE_INITIALIZER; | 60 LAZY_INSTANCE_INITIALIZER; |
| 61 | 61 |
| 62 // Implementation of SafeBrowsingDatabaseManager::Client, the class which is | 62 // Implementation of SafeBrowsingDatabaseManager::Client, the class which is |
| 63 // called back from safebrowsing queries. | 63 // called back from safebrowsing queries. |
| 64 // | 64 // |
| 65 // Constructed on any thread but lives on the IO from then on. | 65 // Constructed on any thread but lives on the IO from then on. |
| 66 class SafeBrowsingClientImpl | 66 class SafeBrowsingClientImpl |
| 67 : public SafeBrowsingDatabaseManager::Client, | 67 : public safe_browsing::SafeBrowsingDatabaseManager::Client, |
| 68 public base::RefCountedThreadSafe<SafeBrowsingClientImpl> { | 68 public base::RefCountedThreadSafe<SafeBrowsingClientImpl> { |
| 69 public: | 69 public: |
| 70 typedef base::Callback<void(const std::set<std::string>&)> OnResultCallback; | 70 typedef base::Callback<void(const std::set<std::string>&)> OnResultCallback; |
| 71 | 71 |
| 72 // Constructs a client to query the database manager for |extension_ids| and | 72 // Constructs a client to query the database manager for |extension_ids| and |
| 73 // run |callback| with the IDs of those which have been blacklisted. | 73 // run |callback| with the IDs of those which have been blacklisted. |
| 74 SafeBrowsingClientImpl( | 74 SafeBrowsingClientImpl( |
| 75 const std::set<std::string>& extension_ids, | 75 const std::set<std::string>& extension_ids, |
| 76 const OnResultCallback& callback) | 76 const OnResultCallback& callback) |
| 77 : callback_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 77 : callback_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 78 callback_(callback) { | 78 callback_(callback) { |
| 79 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
| 80 BrowserThread::IO, | 80 BrowserThread::IO, |
| 81 FROM_HERE, | 81 FROM_HERE, |
| 82 base::Bind(&SafeBrowsingClientImpl::StartCheck, this, | 82 base::Bind(&SafeBrowsingClientImpl::StartCheck, this, |
| 83 g_database_manager.Get().get(), | 83 g_database_manager.Get().get(), |
| 84 extension_ids)); | 84 extension_ids)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>; | 88 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>; |
| 89 ~SafeBrowsingClientImpl() override {} | 89 ~SafeBrowsingClientImpl() override {} |
| 90 | 90 |
| 91 // Pass |database_manager| as a parameter to avoid touching | 91 // Pass |database_manager| as a parameter to avoid touching |
| 92 // SafeBrowsingService on the IO thread. | 92 // SafeBrowsingService on the IO thread. |
| 93 void StartCheck(scoped_refptr<SafeBrowsingDatabaseManager> database_manager, | 93 void StartCheck(scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> |
| 94 database_manager, | |
| 94 const std::set<std::string>& extension_ids) { | 95 const std::set<std::string>& extension_ids) { |
| 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 96 if (database_manager->CheckExtensionIDs(extension_ids, this)) { | 97 if (database_manager->CheckExtensionIDs(extension_ids, this)) { |
| 97 // Definitely not blacklisted. Callback immediately. | 98 // Definitely not blacklisted. Callback immediately. |
| 98 callback_task_runner_->PostTask( | 99 callback_task_runner_->PostTask( |
| 99 FROM_HERE, | 100 FROM_HERE, |
| 100 base::Bind(callback_, std::set<std::string>())); | 101 base::Bind(callback_, std::set<std::string>())); |
| 101 return; | 102 return; |
| 102 } | 103 } |
| 103 // Something might be blacklisted, response will come in | 104 // Something might be blacklisted, response will come in |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 | 143 |
| 143 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) { | 144 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) { |
| 144 blacklist_->AddObserver(this); | 145 blacklist_->AddObserver(this); |
| 145 } | 146 } |
| 146 | 147 |
| 147 Blacklist::Observer::~Observer() { | 148 Blacklist::Observer::~Observer() { |
| 148 blacklist_->RemoveObserver(this); | 149 blacklist_->RemoveObserver(this); |
| 149 } | 150 } |
| 150 | 151 |
| 151 Blacklist::ScopedDatabaseManagerForTest::ScopedDatabaseManagerForTest( | 152 Blacklist::ScopedDatabaseManagerForTest::ScopedDatabaseManagerForTest( |
| 152 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) | 153 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager) |
| 153 : original_(GetDatabaseManager()) { | 154 : original_(GetDatabaseManager()) { |
| 154 SetDatabaseManager(database_manager); | 155 SetDatabaseManager(database_manager); |
| 155 } | 156 } |
| 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<safe_browsing::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(this, chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
| 166 this, | 167 content::Source<safe_browsing::SafeBrowsingDatabaseManager>( |
| 167 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 168 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) { |
| 178 if (!prefs->GetInstalledExtensionInfo(*it)) | 178 if (!prefs->GetInstalledExtensionInfo(*it)) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 observers_.AddObserver(observer); | 332 observers_.AddObserver(observer); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void Blacklist::RemoveObserver(Observer* observer) { | 335 void Blacklist::RemoveObserver(Observer* observer) { |
| 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 337 observers_.RemoveObserver(observer); | 337 observers_.RemoveObserver(observer); |
| 338 } | 338 } |
| 339 | 339 |
| 340 // static | 340 // static |
| 341 void Blacklist::SetDatabaseManager( | 341 void Blacklist::SetDatabaseManager( |
| 342 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) { | 342 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> |
| 343 database_manager) { | |
| 343 g_database_manager.Get().set(database_manager); | 344 g_database_manager.Get().set(database_manager); |
| 344 } | 345 } |
| 345 | 346 |
| 346 // static | 347 // static |
| 347 scoped_refptr<SafeBrowsingDatabaseManager> Blacklist::GetDatabaseManager() { | 348 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> |
| 349 Blacklist::GetDatabaseManager() { | |
| 348 return g_database_manager.Get().get(); | 350 return g_database_manager.Get().get(); |
| 349 } | 351 } |
| 350 | 352 |
| 351 void Blacklist::Observe(int type, | 353 void Blacklist::Observe(int type, |
| 352 const content::NotificationSource& source, | 354 const content::NotificationSource& source, |
| 353 const content::NotificationDetails& details) { | 355 const content::NotificationDetails& details) { |
| 354 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); | 356 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); |
| 355 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); | 357 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); |
| 356 } | 358 } |
| 357 | 359 |
| 358 } // namespace extensions | 360 } // namespace extensions |
| OLD | NEW |