OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/safe_browsing/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 11 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
12 #include "chrome/common/net/http_return.h" | 12 #include "chrome/common/net/http_return.h" |
13 #include "chrome/common/safe_browsing/csd.pb.h" | 13 #include "chrome/common/safe_browsing/csd.pb.h" |
14 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 15 #include "content/common/net/url_fetcher.h" |
15 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
17 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
18 | 19 |
19 namespace safe_browsing { | 20 namespace safe_browsing { |
20 | 21 |
21 const char DownloadProtectionService::kDownloadRequestUrl[] = | 22 const char DownloadProtectionService::kDownloadRequestUrl[] = |
22 "https://sb-ssl.google.com/safebrowsing/clientreport/download"; | 23 "https://sb-ssl.google.com/safebrowsing/clientreport/download"; |
23 | 24 |
24 DownloadProtectionService::DownloadInfo::DownloadInfo() | 25 DownloadProtectionService::DownloadInfo::DownloadInfo() |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 download_requests_.begin(); | 60 download_requests_.begin(); |
60 it != download_requests_.end(); ++it) { | 61 it != download_requests_.end(); ++it) { |
61 it->second.Run(SAFE); | 62 it->second.Run(SAFE); |
62 } | 63 } |
63 STLDeleteContainerPairFirstPointers(download_requests_.begin(), | 64 STLDeleteContainerPairFirstPointers(download_requests_.begin(), |
64 download_requests_.end()); | 65 download_requests_.end()); |
65 download_requests_.clear(); | 66 download_requests_.clear(); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 void DownloadProtectionService::OnURLFetchComplete( | 70 void DownloadProtectionService::OnURLFetchComplete(const URLFetcher* source) { |
70 const URLFetcher* source, | |
71 const GURL& url, | |
72 const net::URLRequestStatus& status, | |
73 int response_code, | |
74 const net::ResponseCookies& cookies, | |
75 const std::string& data) { | |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
77 scoped_ptr<const URLFetcher> s(source); // will delete the URLFetcher object. | 72 scoped_ptr<const URLFetcher> s(source); // will delete the URLFetcher object. |
78 if (download_requests_.find(source) != download_requests_.end()) { | 73 if (download_requests_.find(source) != download_requests_.end()) { |
79 CheckDownloadCallback callback = download_requests_[source]; | 74 CheckDownloadCallback callback = download_requests_[source]; |
80 download_requests_.erase(source); | 75 download_requests_.erase(source); |
81 if (!enabled_) { | 76 if (!enabled_) { |
82 // SafeBrowsing got disabled. We can't do anything. Note: the request | 77 // SafeBrowsing got disabled. We can't do anything. Note: the request |
83 // object will be deleted. | 78 // object will be deleted. |
84 RecordStats(REASON_SB_DISABLED); | 79 RecordStats(REASON_SB_DISABLED); |
85 return; | 80 return; |
86 } | 81 } |
87 DownloadCheckResultReason reason = REASON_MAX; | 82 DownloadCheckResultReason reason = REASON_MAX; |
88 if (status.is_success() && | 83 reason = REASON_SERVER_PING_FAILED; |
89 RC_REQUEST_OK == response_code && | 84 if (source->status().is_success() && |
90 data.size() > 0) { | 85 RC_REQUEST_OK == source->response_code()) { |
91 // For now no matter what we'll always say the download is safe. | 86 std::string data; |
92 // TODO(noelutz): Parse the response body to see exactly what's going on. | 87 source->GetResponseAsString(&data); |
93 reason = REASON_INVALID_RESPONSE_PROTO; | 88 if (data.size() > 0) { |
94 } else { | 89 // For now no matter what we'll always say the download is safe. |
95 reason = REASON_SERVER_PING_FAILED; | 90 // TODO(noelutz): Parse the response body to see exactly what's going |
| 91 // on. |
| 92 reason = REASON_INVALID_RESPONSE_PROTO; |
| 93 } |
96 } | 94 } |
97 BrowserThread::PostTask( | 95 BrowserThread::PostTask( |
98 BrowserThread::UI, | 96 BrowserThread::UI, |
99 FROM_HERE, | 97 FROM_HERE, |
100 base::Bind(&DownloadProtectionService::EndCheckClientDownload, | 98 base::Bind(&DownloadProtectionService::EndCheckClientDownload, |
101 this, SAFE, reason, callback)); | 99 this, SAFE, reason, callback)); |
102 } else { | 100 } else { |
103 NOTREACHED(); | 101 NOTREACHED(); |
104 } | 102 } |
105 } | 103 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 RecordStats(reason); | 201 RecordStats(reason); |
204 callback.Run(result); | 202 callback.Run(result); |
205 } | 203 } |
206 | 204 |
207 void DownloadProtectionService::RecordStats(DownloadCheckResultReason reason) { | 205 void DownloadProtectionService::RecordStats(DownloadCheckResultReason reason) { |
208 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", | 206 UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", |
209 reason, | 207 reason, |
210 REASON_MAX); | 208 REASON_MAX); |
211 } | 209 } |
212 } // namespace safe_browsing | 210 } // namespace safe_browsing |
OLD | NEW |