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

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: Remove '// namespace safe_browsing' for a small fwd decl block. 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/safe_browsing_service.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/browser/safe_browsing/threat_details_cache.h" 14 #include "chrome/browser/safe_browsing/threat_details_cache.h"
15 #include "chrome/common/safe_browsing/csd.pb.h" 15 #include "chrome/common/safe_browsing/csd.pb.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::ClientSafeBrowsingReportRequest;
27 26
28 // Only send small files for now, a better strategy would use the size 27 // Only send small files for now, a better strategy would use the size
29 // of the whole report and the user's bandwidth. 28 // of the whole report and the user's bandwidth.
30 static const uint32 kMaxBodySizeBytes = 1024; 29 static const uint32 kMaxBodySizeBytes = 1024;
31 30
31 namespace safe_browsing {
32
32 ThreatDetailsCacheCollector::ThreatDetailsCacheCollector() 33 ThreatDetailsCacheCollector::ThreatDetailsCacheCollector()
33 : resources_(NULL), result_(NULL), has_started_(false) {} 34 : resources_(NULL), result_(NULL), has_started_(false) {}
34 35
35 void ThreatDetailsCacheCollector::StartCacheCollection( 36 void ThreatDetailsCacheCollector::StartCacheCollection(
36 net::URLRequestContextGetter* request_context_getter, 37 net::URLRequestContextGetter* request_context_getter,
37 safe_browsing::ResourceMap* resources, 38 ResourceMap* resources,
38 bool* result, 39 bool* result,
39 const base::Closure& callback) { 40 const base::Closure& callback) {
40 // Start the data collection from the HTTP cache. We use a URLFetcher 41 // Start the data collection from the HTTP cache. We use a URLFetcher
41 // and set the right flags so we only hit the cache. 42 // and set the right flags so we only hit the cache.
42 DVLOG(1) << "Getting cache data for all urls..."; 43 DVLOG(1) << "Getting cache data for all urls...";
43 request_context_getter_ = request_context_getter; 44 request_context_getter_ = request_context_getter;
44 resources_ = resources; 45 resources_ = resources;
45 resources_it_ = resources_->begin(); 46 resources_it_ = resources_->begin();
46 result_ = result; 47 result_ = result;
47 callback_ = callback; 48 callback_ = callback;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 current_fetch_->SetRequestContext(request_context_getter_.get()); 83 current_fetch_->SetRequestContext(request_context_getter_.get());
83 // Only from cache, and don't save cookies. 84 // Only from cache, and don't save cookies.
84 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE | 85 current_fetch_->SetLoadFlags(net::LOAD_ONLY_FROM_CACHE |
85 net::LOAD_DO_NOT_SAVE_COOKIES); 86 net::LOAD_DO_NOT_SAVE_COOKIES);
86 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries. 87 current_fetch_->SetAutomaticallyRetryOn5xx(false); // No retries.
87 current_fetch_->Start(); // OnURLFetchComplete will be called when done. 88 current_fetch_->Start(); // OnURLFetchComplete will be called when done.
88 } 89 }
89 90
90 ClientSafeBrowsingReportRequest::Resource* 91 ClientSafeBrowsingReportRequest::Resource*
91 ThreatDetailsCacheCollector::GetResource(const GURL& url) { 92 ThreatDetailsCacheCollector::GetResource(const GURL& url) {
92 safe_browsing::ResourceMap::iterator it = resources_->find(url.spec()); 93 ResourceMap::iterator it = resources_->find(url.spec());
93 if (it != resources_->end()) { 94 if (it != resources_->end()) {
94 return it->second.get(); 95 return it->second.get();
95 } 96 }
96 return NULL; 97 return NULL;
97 } 98 }
98 99
99 void ThreatDetailsCacheCollector::OnURLFetchComplete( 100 void ThreatDetailsCacheCollector::OnURLFetchComplete(
100 const net::URLFetcher* source) { 101 const net::URLFetcher* source) {
101 DVLOG(1) << "OnUrlFetchComplete"; 102 DVLOG(1) << "OnUrlFetchComplete";
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 103 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 base::Bind(&ThreatDetailsCacheCollector::OpenEntry, this)); 195 base::Bind(&ThreatDetailsCacheCollector::OpenEntry, this));
195 } 196 }
196 197
197 void ThreatDetailsCacheCollector::AllDone(bool success) { 198 void ThreatDetailsCacheCollector::AllDone(bool success) {
198 DVLOG(1) << "AllDone"; 199 DVLOG(1) << "AllDone";
199 DCHECK_CURRENTLY_ON(BrowserThread::IO); 200 DCHECK_CURRENTLY_ON(BrowserThread::IO);
200 *result_ = success; 201 *result_ = success;
201 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_); 202 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, callback_);
202 callback_.Reset(); 203 callback_.Reset();
203 } 204 }
205
206 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/threat_details_cache.h ('k') | chrome/browser/safe_browsing/threat_details_history.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698