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

Side by Side Diff: chrome/browser/extensions/blacklist.cc

Issue 2825963003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/extensions (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 typedef base::Callback<void(const std::set<std::string>&)> OnResultCallback; 72 typedef base::Callback<void(const std::set<std::string>&)> OnResultCallback;
73 73
74 // Constructs a client to query the database manager for |extension_ids| and 74 // Constructs a client to query the database manager for |extension_ids| and
75 // run |callback| with the IDs of those which have been blacklisted. 75 // run |callback| with the IDs of those which have been blacklisted.
76 SafeBrowsingClientImpl( 76 SafeBrowsingClientImpl(
77 const std::set<std::string>& extension_ids, 77 const std::set<std::string>& extension_ids,
78 const OnResultCallback& callback) 78 const OnResultCallback& callback)
79 : callback_task_runner_(base::ThreadTaskRunnerHandle::Get()), 79 : callback_task_runner_(base::ThreadTaskRunnerHandle::Get()),
80 callback_(callback) { 80 callback_(callback) {
81 BrowserThread::PostTask( 81 BrowserThread::PostTask(
82 BrowserThread::IO, 82 BrowserThread::IO, FROM_HERE,
83 FROM_HERE, 83 base::BindOnce(&SafeBrowsingClientImpl::StartCheck, this,
84 base::Bind(&SafeBrowsingClientImpl::StartCheck, this, 84 g_database_manager.Get().get(), extension_ids));
85 g_database_manager.Get().get(),
86 extension_ids));
87 } 85 }
88 86
89 private: 87 private:
90 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>; 88 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>;
91 ~SafeBrowsingClientImpl() override {} 89 ~SafeBrowsingClientImpl() override {}
92 90
93 // Pass |database_manager| as a parameter to avoid touching 91 // Pass |database_manager| as a parameter to avoid touching
94 // SafeBrowsingService on the IO thread. 92 // SafeBrowsingService on the IO thread.
95 void StartCheck(scoped_refptr<SafeBrowsingDatabaseManager> database_manager, 93 void StartCheck(scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
96 const std::set<std::string>& extension_ids) { 94 const std::set<std::string>& extension_ids) {
97 DCHECK_CURRENTLY_ON(BrowserThread::IO); 95 DCHECK_CURRENTLY_ON(BrowserThread::IO);
98 if (database_manager->CheckExtensionIDs(extension_ids, this)) { 96 if (database_manager->CheckExtensionIDs(extension_ids, this)) {
99 // Definitely not blacklisted. Callback immediately. 97 // Definitely not blacklisted. Callback immediately.
100 callback_task_runner_->PostTask( 98 callback_task_runner_->PostTask(
101 FROM_HERE, 99 FROM_HERE, base::BindOnce(callback_, std::set<std::string>()));
102 base::Bind(callback_, std::set<std::string>()));
103 return; 100 return;
104 } 101 }
105 // Something might be blacklisted, response will come in 102 // Something might be blacklisted, response will come in
106 // OnCheckExtensionsResult. 103 // OnCheckExtensionsResult.
107 AddRef(); // Balanced in OnCheckExtensionsResult 104 AddRef(); // Balanced in OnCheckExtensionsResult
108 } 105 }
109 106
110 void OnCheckExtensionsResult(const std::set<std::string>& hits) override { 107 void OnCheckExtensionsResult(const std::set<std::string>& hits) override {
111 DCHECK_CURRENTLY_ON(BrowserThread::IO); 108 DCHECK_CURRENTLY_ON(BrowserThread::IO);
112 callback_task_runner_->PostTask(FROM_HERE, base::Bind(callback_, hits)); 109 callback_task_runner_->PostTask(FROM_HERE, base::BindOnce(callback_, hits));
113 Release(); // Balanced in StartCheck. 110 Release(); // Balanced in StartCheck.
114 } 111 }
115 112
116 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_; 113 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_;
117 OnResultCallback callback_; 114 OnResultCallback callback_;
118 115
119 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl); 116 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl);
120 }; 117 };
121 118
122 void CheckOneExtensionState( 119 void CheckOneExtensionState(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 Blacklist* Blacklist::Get(content::BrowserContext* context) { 185 Blacklist* Blacklist::Get(content::BrowserContext* context) {
189 return BlacklistFactory::GetForBrowserContext(context); 186 return BlacklistFactory::GetForBrowserContext(context);
190 } 187 }
191 188
192 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids, 189 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids,
193 const GetBlacklistedIDsCallback& callback) { 190 const GetBlacklistedIDsCallback& callback) {
194 DCHECK_CURRENTLY_ON(BrowserThread::UI); 191 DCHECK_CURRENTLY_ON(BrowserThread::UI);
195 192
196 if (ids.empty() || !g_database_manager.Get().get().get()) { 193 if (ids.empty() || !g_database_manager.Get().get().get()) {
197 base::ThreadTaskRunnerHandle::Get()->PostTask( 194 base::ThreadTaskRunnerHandle::Get()->PostTask(
198 FROM_HERE, base::Bind(callback, BlacklistStateMap())); 195 FROM_HERE, base::BindOnce(callback, BlacklistStateMap()));
199 return; 196 return;
200 } 197 }
201 198
202 // Constructing the SafeBrowsingClientImpl begins the process of asking 199 // Constructing the SafeBrowsingClientImpl begins the process of asking
203 // safebrowsing for the blacklisted extensions. The set of blacklisted 200 // safebrowsing for the blacklisted extensions. The set of blacklisted
204 // extensions returned by SafeBrowsing will then be passed to 201 // extensions returned by SafeBrowsing will then be passed to
205 // GetBlacklistStateIDs to get the particular BlacklistState for each id. 202 // GetBlacklistStateIDs to get the particular BlacklistState for each id.
206 new SafeBrowsingClientImpl( 203 new SafeBrowsingClientImpl(
207 ids, base::Bind(&Blacklist::GetBlacklistStateForIDs, AsWeakPtr(), 204 ids, base::Bind(&Blacklist::GetBlacklistStateForIDs, AsWeakPtr(),
208 callback)); 205 callback));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 348
352 void Blacklist::Observe(int type, 349 void Blacklist::Observe(int type,
353 const content::NotificationSource& source, 350 const content::NotificationSource& source,
354 const content::NotificationDetails& details) { 351 const content::NotificationDetails& details) {
355 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); 352 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type);
356 for (auto& observer : observers_) 353 for (auto& observer : observers_)
357 observer.OnBlacklistUpdated(); 354 observer.OnBlacklistUpdated();
358 } 355 }
359 356
360 } // namespace extensions 357 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/background_xhr_browsertest.cc ('k') | chrome/browser/extensions/blacklist_state_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698