| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_state_fetcher.h" | 5 #include "chrome/browser/extensions/blacklist_state_fetcher.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 BlacklistStateFetcher::BlacklistStateFetcher() | 25 BlacklistStateFetcher::BlacklistStateFetcher() |
| 26 : url_fetcher_id_(0), | 26 : url_fetcher_id_(0), |
| 27 weak_ptr_factory_(this) {} | 27 weak_ptr_factory_(this) {} |
| 28 | 28 |
| 29 BlacklistStateFetcher::~BlacklistStateFetcher() { | 29 BlacklistStateFetcher::~BlacklistStateFetcher() { |
| 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 31 STLDeleteContainerPairFirstPointers(requests_.begin(), requests_.end()); | 31 base::STLDeleteContainerPairFirstPointers(requests_.begin(), requests_.end()); |
| 32 requests_.clear(); | 32 requests_.clear(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void BlacklistStateFetcher::Request(const std::string& id, | 35 void BlacklistStateFetcher::Request(const std::string& id, |
| 36 const RequestCallback& callback) { | 36 const RequestCallback& callback) { |
| 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 38 if (!safe_browsing_config_) { | 38 if (!safe_browsing_config_) { |
| 39 if (g_browser_process && g_browser_process->safe_browsing_service()) { | 39 if (g_browser_process && g_browser_process->safe_browsing_service()) { |
| 40 SetSafeBrowsingConfig( | 40 SetSafeBrowsingConfig( |
| 41 g_browser_process->safe_browsing_service()->GetProtocolConfig()); | 41 g_browser_process->safe_browsing_service()->GetProtocolConfig()); |
| 42 } else { | 42 } else { |
| 43 base::ThreadTaskRunnerHandle::Get()->PostTask( | 43 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 44 FROM_HERE, base::Bind(callback, BLACKLISTED_UNKNOWN)); | 44 FROM_HERE, base::Bind(callback, BLACKLISTED_UNKNOWN)); |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool request_already_sent = ContainsKey(callbacks_, id); | 49 bool request_already_sent = base::ContainsKey(callbacks_, id); |
| 50 callbacks_.insert(std::make_pair(id, callback)); | 50 callbacks_.insert(std::make_pair(id, callback)); |
| 51 if (request_already_sent) | 51 if (request_already_sent) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 if (!url_request_context_getter_ && g_browser_process && | 54 if (!url_request_context_getter_ && g_browser_process && |
| 55 g_browser_process->safe_browsing_service()) { | 55 g_browser_process->safe_browsing_service()) { |
| 56 url_request_context_getter_ = | 56 url_request_context_getter_ = |
| 57 g_browser_process->safe_browsing_service()->url_request_context(); | 57 g_browser_process->safe_browsing_service()->url_request_context(); |
| 58 } | 58 } |
| 59 | 59 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 for (CallbackMultiMap::const_iterator callback_it = range.first; | 149 for (CallbackMultiMap::const_iterator callback_it = range.first; |
| 150 callback_it != range.second; | 150 callback_it != range.second; |
| 151 ++callback_it) { | 151 ++callback_it) { |
| 152 callback_it->second.Run(state); | 152 callback_it->second.Run(state); |
| 153 } | 153 } |
| 154 | 154 |
| 155 callbacks_.erase(range.first, range.second); | 155 callbacks_.erase(range.first, range.second); |
| 156 } | 156 } |
| 157 | 157 |
| 158 } // namespace extensions | 158 } // namespace extensions |
| OLD | NEW |