| 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 "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" | 10 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 parent_context_getter->GetURLRequestContext()); | 33 parent_context_getter->GetURLRequestContext()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 static void Create( | 36 static void Create( |
| 37 scoped_refptr<net::URLRequestContextGetter> parent_context_getter, | 37 scoped_refptr<net::URLRequestContextGetter> parent_context_getter, |
| 38 base::Callback<void(scoped_refptr<net::URLRequestContextGetter>)> | 38 base::Callback<void(scoped_refptr<net::URLRequestContextGetter>)> |
| 39 callback) { | 39 callback) { |
| 40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 40 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 41 | 41 |
| 42 scoped_refptr<net::URLRequestContextGetter> context_getter = | 42 scoped_refptr<net::URLRequestContextGetter> context_getter = |
| 43 new BlacklistRequestContextGetter(parent_context_getter); | 43 new BlacklistRequestContextGetter(parent_context_getter.get()); |
| 44 BrowserThread::PostTask(BrowserThread::UI, | 44 BrowserThread::PostTask(BrowserThread::UI, |
| 45 FROM_HERE, | 45 FROM_HERE, |
| 46 base::Bind(callback, context_getter)); | 46 base::Bind(callback, context_getter)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { | 49 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 51 return url_request_context_.get(); | 51 return url_request_context_.get(); |
| 52 } | 52 } |
| 53 | 53 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 FROM_HERE, base::Bind(callback, BLACKLISTED_UNKNOWN)); | 92 FROM_HERE, base::Bind(callback, BLACKLISTED_UNKNOWN)); |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool request_already_sent = ContainsKey(callbacks_, id); | 97 bool request_already_sent = ContainsKey(callbacks_, id); |
| 98 callbacks_.insert(std::make_pair(id, callback)); | 98 callbacks_.insert(std::make_pair(id, callback)); |
| 99 if (request_already_sent) | 99 if (request_already_sent) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 if (url_request_context_getter_ || | 102 if (url_request_context_getter_.get() || !g_browser_process || |
| 103 !g_browser_process || !g_browser_process->safe_browsing_service()) { | 103 !g_browser_process->safe_browsing_service()) { |
| 104 SendRequest(id); | 104 SendRequest(id); |
| 105 } else { | 105 } else { |
| 106 scoped_refptr<net::URLRequestContextGetter> parent_request_context; | 106 scoped_refptr<net::URLRequestContextGetter> parent_request_context; |
| 107 if (g_browser_process && g_browser_process->safe_browsing_service()) { | 107 if (g_browser_process && g_browser_process->safe_browsing_service()) { |
| 108 parent_request_context = g_browser_process->safe_browsing_service() | 108 parent_request_context = g_browser_process->safe_browsing_service() |
| 109 ->url_request_context(); | 109 ->url_request_context(); |
| 110 } else { | 110 } else { |
| 111 parent_request_context = parent_request_context_for_test_; | 111 parent_request_context = parent_request_context_for_test_; |
| 112 } | 112 } |
| 113 | 113 |
| 114 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
| 115 BrowserThread::IO, FROM_HERE, | 115 BrowserThread::IO, FROM_HERE, |
| 116 base::Bind(&BlacklistRequestContextGetter::Create, | 116 base::Bind(&BlacklistRequestContextGetter::Create, |
| 117 parent_request_context, | 117 parent_request_context, |
| 118 base::Bind(&BlacklistStateFetcher::SaveRequestContext, | 118 base::Bind(&BlacklistStateFetcher::SaveRequestContext, |
| 119 weak_ptr_factory_.GetWeakPtr(), | 119 weak_ptr_factory_.GetWeakPtr(), |
| 120 id))); | 120 id))); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 void BlacklistStateFetcher::SaveRequestContext( | 124 void BlacklistStateFetcher::SaveRequestContext( |
| 125 const std::string& id, | 125 const std::string& id, |
| 126 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { | 126 scoped_refptr<net::URLRequestContextGetter> request_context_getter) { |
| 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 128 if (!url_request_context_getter_) | 128 if (!url_request_context_getter_.get()) |
| 129 url_request_context_getter_ = request_context_getter; | 129 url_request_context_getter_ = request_context_getter; |
| 130 SendRequest(id); | 130 SendRequest(id); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void BlacklistStateFetcher::SendRequest(const std::string& id) { | 133 void BlacklistStateFetcher::SendRequest(const std::string& id) { |
| 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 135 | 135 |
| 136 ClientCRXListInfoRequest request; | 136 ClientCRXListInfoRequest request; |
| 137 request.set_id(id); | 137 request.set_id(id); |
| 138 std::string request_str; | 138 std::string request_str; |
| 139 request.SerializeToString(&request_str); | 139 request.SerializeToString(&request_str); |
| 140 | 140 |
| 141 GURL request_url = RequestUrl(); | 141 GURL request_url = RequestUrl(); |
| 142 net::URLFetcher* fetcher = net::URLFetcher::Create(url_fetcher_id_++, | 142 net::URLFetcher* fetcher = net::URLFetcher::Create(url_fetcher_id_++, |
| 143 request_url, | 143 request_url, |
| 144 net::URLFetcher::POST, | 144 net::URLFetcher::POST, |
| 145 this); | 145 this); |
| 146 requests_[fetcher] = id; | 146 requests_[fetcher] = id; |
| 147 fetcher->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. | 147 fetcher->SetAutomaticallyRetryOn5xx(false); // Don't retry on error. |
| 148 fetcher->SetRequestContext(url_request_context_getter_); | 148 fetcher->SetRequestContext(url_request_context_getter_.get()); |
| 149 fetcher->SetUploadData("application/octet-stream", request_str); | 149 fetcher->SetUploadData("application/octet-stream", request_str); |
| 150 fetcher->Start(); | 150 fetcher->Start(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void BlacklistStateFetcher::SetSafeBrowsingConfig( | 153 void BlacklistStateFetcher::SetSafeBrowsingConfig( |
| 154 const SafeBrowsingProtocolConfig& config) { | 154 const SafeBrowsingProtocolConfig& config) { |
| 155 safe_browsing_config_.reset(new SafeBrowsingProtocolConfig(config)); | 155 safe_browsing_config_.reset(new SafeBrowsingProtocolConfig(config)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void BlacklistStateFetcher::SetURLRequestContextForTest( | 158 void BlacklistStateFetcher::SetURLRequestContextForTest( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 callback_it != range.second; | 220 callback_it != range.second; |
| 221 ++callback_it) { | 221 ++callback_it) { |
| 222 callback_it->second.Run(state); | 222 callback_it->second.Run(state); |
| 223 } | 223 } |
| 224 | 224 |
| 225 callbacks_.erase(range.first, range.second); | 225 callbacks_.erase(range.first, range.second); |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace extensions | 228 } // namespace extensions |
| 229 | 229 |
| OLD | NEW |