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/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/thread_task_runner_handle.h" |
15 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/extensions/blacklist_factory.h" | 19 #include "chrome/browser/extensions/blacklist_factory.h" |
18 #include "chrome/browser/extensions/blacklist_state_fetcher.h" | 20 #include "chrome/browser/extensions/blacklist_state_fetcher.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 22 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
21 #include "content/public/browser/notification_details.h" | 23 #include "content/public/browser/notification_details.h" |
22 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
23 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
24 | 26 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 : public SafeBrowsingDatabaseManager::Client, | 67 : public SafeBrowsingDatabaseManager::Client, |
66 public base::RefCountedThreadSafe<SafeBrowsingClientImpl> { | 68 public base::RefCountedThreadSafe<SafeBrowsingClientImpl> { |
67 public: | 69 public: |
68 typedef base::Callback<void(const std::set<std::string>&)> OnResultCallback; | 70 typedef base::Callback<void(const std::set<std::string>&)> OnResultCallback; |
69 | 71 |
70 // 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 |
71 // run |callback| with the IDs of those which have been blacklisted. | 73 // run |callback| with the IDs of those which have been blacklisted. |
72 SafeBrowsingClientImpl( | 74 SafeBrowsingClientImpl( |
73 const std::set<std::string>& extension_ids, | 75 const std::set<std::string>& extension_ids, |
74 const OnResultCallback& callback) | 76 const OnResultCallback& callback) |
75 : callback_message_loop_(base::MessageLoopProxy::current()), | 77 : callback_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
76 callback_(callback) { | 78 callback_(callback) { |
77 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
78 BrowserThread::IO, | 80 BrowserThread::IO, |
79 FROM_HERE, | 81 FROM_HERE, |
80 base::Bind(&SafeBrowsingClientImpl::StartCheck, this, | 82 base::Bind(&SafeBrowsingClientImpl::StartCheck, this, |
81 g_database_manager.Get().get(), | 83 g_database_manager.Get().get(), |
82 extension_ids)); | 84 extension_ids)); |
83 } | 85 } |
84 | 86 |
85 private: | 87 private: |
86 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>; | 88 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>; |
87 ~SafeBrowsingClientImpl() override {} | 89 ~SafeBrowsingClientImpl() override {} |
88 | 90 |
89 // Pass |database_manager| as a parameter to avoid touching | 91 // Pass |database_manager| as a parameter to avoid touching |
90 // SafeBrowsingService on the IO thread. | 92 // SafeBrowsingService on the IO thread. |
91 void StartCheck(scoped_refptr<SafeBrowsingDatabaseManager> database_manager, | 93 void StartCheck(scoped_refptr<SafeBrowsingDatabaseManager> database_manager, |
92 const std::set<std::string>& extension_ids) { | 94 const std::set<std::string>& extension_ids) { |
93 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
94 if (database_manager->CheckExtensionIDs(extension_ids, this)) { | 96 if (database_manager->CheckExtensionIDs(extension_ids, this)) { |
95 // Definitely not blacklisted. Callback immediately. | 97 // Definitely not blacklisted. Callback immediately. |
96 callback_message_loop_->PostTask( | 98 callback_task_runner_->PostTask( |
97 FROM_HERE, | 99 FROM_HERE, |
98 base::Bind(callback_, std::set<std::string>())); | 100 base::Bind(callback_, std::set<std::string>())); |
99 return; | 101 return; |
100 } | 102 } |
101 // Something might be blacklisted, response will come in | 103 // Something might be blacklisted, response will come in |
102 // OnCheckExtensionsResult. | 104 // OnCheckExtensionsResult. |
103 AddRef(); // Balanced in OnCheckExtensionsResult | 105 AddRef(); // Balanced in OnCheckExtensionsResult |
104 } | 106 } |
105 | 107 |
106 void OnCheckExtensionsResult(const std::set<std::string>& hits) override { | 108 void OnCheckExtensionsResult(const std::set<std::string>& hits) override { |
107 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 109 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
108 callback_message_loop_->PostTask(FROM_HERE, base::Bind(callback_, hits)); | 110 callback_task_runner_->PostTask(FROM_HERE, base::Bind(callback_, hits)); |
109 Release(); // Balanced in StartCheck. | 111 Release(); // Balanced in StartCheck. |
110 } | 112 } |
111 | 113 |
112 scoped_refptr<base::MessageLoopProxy> callback_message_loop_; | 114 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_; |
113 OnResultCallback callback_; | 115 OnResultCallback callback_; |
114 | 116 |
115 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl); | 117 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl); |
116 }; | 118 }; |
117 | 119 |
118 void CheckOneExtensionState( | 120 void CheckOneExtensionState( |
119 const Blacklist::IsBlacklistedCallback& callback, | 121 const Blacklist::IsBlacklistedCallback& callback, |
120 const Blacklist::BlacklistStateMap& state_map) { | 122 const Blacklist::BlacklistStateMap& state_map) { |
121 callback.Run(state_map.empty() ? NOT_BLACKLISTED : state_map.begin()->second); | 123 callback.Run(state_map.empty() ? NOT_BLACKLISTED : state_map.begin()->second); |
122 } | 124 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // static | 186 // static |
185 Blacklist* Blacklist::Get(content::BrowserContext* context) { | 187 Blacklist* Blacklist::Get(content::BrowserContext* context) { |
186 return BlacklistFactory::GetForBrowserContext(context); | 188 return BlacklistFactory::GetForBrowserContext(context); |
187 } | 189 } |
188 | 190 |
189 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids, | 191 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids, |
190 const GetBlacklistedIDsCallback& callback) { | 192 const GetBlacklistedIDsCallback& callback) { |
191 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
192 | 194 |
193 if (ids.empty() || !g_database_manager.Get().get().get()) { | 195 if (ids.empty() || !g_database_manager.Get().get().get()) { |
194 base::MessageLoopProxy::current()->PostTask( | 196 base::ThreadTaskRunnerHandle::Get()->PostTask( |
195 FROM_HERE, base::Bind(callback, BlacklistStateMap())); | 197 FROM_HERE, base::Bind(callback, BlacklistStateMap())); |
196 return; | 198 return; |
197 } | 199 } |
198 | 200 |
199 // Constructing the SafeBrowsingClientImpl begins the process of asking | 201 // Constructing the SafeBrowsingClientImpl begins the process of asking |
200 // safebrowsing for the blacklisted extensions. The set of blacklisted | 202 // safebrowsing for the blacklisted extensions. The set of blacklisted |
201 // extensions returned by SafeBrowsing will then be passed to | 203 // extensions returned by SafeBrowsing will then be passed to |
202 // GetBlacklistStateIDs to get the particular BlacklistState for each id. | 204 // GetBlacklistStateIDs to get the particular BlacklistState for each id. |
203 new SafeBrowsingClientImpl( | 205 new SafeBrowsingClientImpl( |
204 ids, base::Bind(&Blacklist::GetBlacklistStateForIDs, AsWeakPtr(), | 206 ids, base::Bind(&Blacklist::GetBlacklistStateForIDs, AsWeakPtr(), |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 } | 349 } |
348 | 350 |
349 void Blacklist::Observe(int type, | 351 void Blacklist::Observe(int type, |
350 const content::NotificationSource& source, | 352 const content::NotificationSource& source, |
351 const content::NotificationDetails& details) { | 353 const content::NotificationDetails& details) { |
352 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); | 354 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); |
353 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); | 355 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); |
354 } | 356 } |
355 | 357 |
356 } // namespace extensions | 358 } // namespace extensions |
OLD | NEW |