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

Side by Side Diff: chrome/browser/safe_browsing/threat_details_cache.cc

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: Bring back anon namespace. Remove safe_browsing:: wherever not needed. Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 // Implementation of the ThreatDetails class. 5 // Implementation of the ThreatDetails class.
6 6
7 #include "chrome/browser/safe_browsing/threat_details.h" 7 #include "chrome/browser/safe_browsing/threat_details.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/md5.h" 11 #include "base/md5.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "chrome/browser/safe_browsing/report.pb.h" 13 #include "chrome/browser/safe_browsing/report.pb.h"
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/browser/safe_browsing/threat_details_cache.h" 15 #include "chrome/browser/safe_browsing/threat_details_cache.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "net/base/host_port_pair.h" 17 #include "net/base/host_port_pair.h"
18 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
21 #include "net/url_request/url_fetcher.h" 21 #include "net/url_request/url_fetcher.h"
22 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
23 #include "net/url_request/url_request_status.h" 23 #include "net/url_request/url_request_status.h"
24 24
25 using content::BrowserThread; 25 using content::BrowserThread;
26 using safe_browsing::ClientMalwareReportRequest; 26
27 namespace safe_browsing {
28
29 class ClientMalwareReportRequest;
Nathan Parker 2015/11/11 21:23:36 Shouldn't need this pre-decl, since it must be in
vakh (old account. dont use) 2015/11/11 23:22:46 Done.
27 30
28 // Only send small files for now, a better strategy would use the size 31 // Only send small files for now, a better strategy would use the size
29 // of the whole report and the user's bandwidth. 32 // of the whole report and the user's bandwidth.
30 static const uint32 kMaxBodySizeBytes = 1024; 33 static const uint32 kMaxBodySizeBytes = 1024;
31 34
32 ThreatDetailsCacheCollector::ThreatDetailsCacheCollector() 35 ThreatDetailsCacheCollector::ThreatDetailsCacheCollector()
33 : resources_(NULL), result_(NULL), has_started_(false) {} 36 : resources_(NULL), result_(NULL), has_started_(false) {}
34 37
35 void ThreatDetailsCacheCollector::StartCacheCollection( 38 void ThreatDetailsCacheCollector::StartCacheCollection(
36 net::URLRequestContextGetter* request_context_getter, 39 net::URLRequestContextGetter* request_context_getter,
37 safe_browsing::ResourceMap* resources, 40 ResourceMap* resources,
38 bool* result, 41 bool* result,
39 const base::Closure& callback) { 42 const base::Closure& callback) {
40 // Start the data collection from the HTTP cache. We use a URLFetcher 43 // Start the data collection from the HTTP cache. We use a URLFetcher
41 // and set the right flags so we only hit the cache. 44 // and set the right flags so we only hit the cache.
42 DVLOG(1) << "Getting cache data for all urls..."; 45 DVLOG(1) << "Getting cache data for all urls...";
43 request_context_getter_ = request_context_getter; 46 request_context_getter_ = request_context_getter;
44 resources_ = resources; 47 resources_ = resources;
45 resources_it_ = resources_->begin(); 48 resources_it_ = resources_->begin();
46 result_ = result; 49 result_ = result;
47 callback_ = callback; 50 callback_ = callback;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 current_fetch_->SetRequestContext(request_context_getter_.get()); 85 current_fetch_->SetRequestContext(request_context_getter_.get());
83 // Only from cache, and don't save cookies. 86 // Only from cache, and don't save cookies.
84 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE | 87 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE |
85 net::LOAD_DO_NOT_SAVE_COOKIES); 88 net::LOAD_DO_NOT_SAVE_COOKIES);
86 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries. 89 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries.
87 current_fetch_->Start(); // OnURLFetchComplete will be called when done. 90 current_fetch_->Start(); // OnURLFetchComplete will be called when done.
88 } 91 }
89 92
90 ClientMalwareReportRequest::Resource* ThreatDetailsCacheCollector::GetResource( 93 ClientMalwareReportRequest::Resource* ThreatDetailsCacheCollector::GetResource(
91 const GURL& url) { 94 const GURL& url) {
92 safe_browsing::ResourceMap::iterator it = resources_->find(url.spec()); 95 ResourceMap::iterator it = resources_->find(url.spec());
93 if (it != resources_->end()) { 96 if (it != resources_->end()) {
94 return it->second.get(); 97 return it->second.get();
95 } 98 }
96 return NULL; 99 return NULL;
97 } 100 }
98 101
99 void ThreatDetailsCacheCollector::OnURLFetchComplete( 102 void ThreatDetailsCacheCollector::OnURLFetchComplete(
100 const net::URLFetcher* source) { 103 const net::URLFetcher* source) {
101 DVLOG(1) << "OnUrlFetchComplete"; 104 DVLOG(1) << "OnUrlFetchComplete";
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 105 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 base::Bind(&ThreatDetailsCacheCollector::OpenEntry, this)); 197 base::Bind(&ThreatDetailsCacheCollector::OpenEntry, this));
195 } 198 }
196 199
197 void ThreatDetailsCacheCollector::AllDone(bool success) { 200 void ThreatDetailsCacheCollector::AllDone(bool success) {
198 DVLOG(1) << "AllDone"; 201 DVLOG(1) << "AllDone";
199 DCHECK_CURRENTLY_ON(BrowserThread::IO); 202 DCHECK_CURRENTLY_ON(BrowserThread::IO);
200 *result_ = success; 203 *result_ = success;
201 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); 204 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
202 callback_.Reset(); 205 callback_.Reset();
203 } 206 }
207
208 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698