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

Unified Diff: chrome/browser/safe_browsing/malware_details.cc

Issue 6611023: The optional Malware Details also collects HTTP cache information. See design... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/malware_details.cc
===================================================================
--- chrome/browser/safe_browsing/malware_details.cc (revision 81745)
+++ chrome/browser/safe_browsing/malware_details.cc (working copy)
@@ -6,14 +6,21 @@
#include "chrome/browser/safe_browsing/malware_details.h"
+#include "base/callback.h"
#include "base/lazy_instance.h"
+#include "chrome/browser/net/chrome_url_request_context.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/safe_browsing/malware_details_cache.h"
+#include "chrome/browser/safe_browsing/report.pb.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
-#include "chrome/browser/safe_browsing/report.pb.h"
#include "chrome/common/safe_browsing/safebrowsing_messages.h"
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/navigation_entry.h"
#include "content/browser/tab_contents/tab_contents.h"
+#include "net/base/io_buffer.h"
+#include "net/disk_cache/disk_cache.h"
+#include "net/url_request/url_request_context_getter.h"
using safe_browsing::ClientMalwareReportRequest;
@@ -29,9 +36,10 @@
: public MalwareDetailsFactory {
public:
MalwareDetails* CreateMalwareDetails(
+ SafeBrowsingService* sb_service,
TabContents* tab_contents,
const SafeBrowsingService::UnsafeResource& unsafe_resource) {
- return new MalwareDetails(tab_contents, unsafe_resource);
+ return new MalwareDetails(sb_service, tab_contents, unsafe_resource);
}
private:
@@ -49,25 +57,31 @@
// Create a MalwareDetails for the given tab.
/* static */
MalwareDetails* MalwareDetails::NewMalwareDetails(
+ SafeBrowsingService* sb_service,
TabContents* tab_contents,
const SafeBrowsingService::UnsafeResource& resource) {
// Set up the factory if this has not been done already (tests do that
// before this method is called).
if (!factory_)
factory_ = g_malware_details_factory_impl.Pointer();
- return factory_->CreateMalwareDetails(tab_contents, resource);
+ return factory_->CreateMalwareDetails(sb_service, tab_contents, resource);
}
// Create a MalwareDetails for the given tab. Runs in the UI thread.
MalwareDetails::MalwareDetails(
+ SafeBrowsingService* sb_service,
TabContents* tab_contents,
const SafeBrowsingService::UnsafeResource& resource)
: TabContentsObserver(tab_contents),
- resource_(resource) {
+ request_context_getter_(tab_contents->profile()->GetRequestContext()),
+ sb_service_(sb_service),
+ resource_(resource),
+ cache_collector_(new MalwareDetailsCacheCollector) {
StartCollection();
}
-MalwareDetails::~MalwareDetails() {}
+MalwareDetails::~MalwareDetails() {
+}
bool MalwareDetails::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
@@ -88,7 +102,7 @@
// resources_ and updates |resource| to point to it.
ClientMalwareReportRequest::Resource* MalwareDetails::FindOrCreateResource(
const GURL& url) {
- ResourceMap::iterator it = resources_.find(url.spec());
+ safe_browsing::ResourceMap::iterator it = resources_.find(url.spec());
if (it != resources_.end()) {
return it->second.get();
}
@@ -207,9 +221,15 @@
void MalwareDetails::AddDOMDetails(
const std::vector<SafeBrowsingHostMsg_MalwareDOMDetails_Node>& params) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DVLOG(1) << "Nodes from the DOM: " << params.size();
+
+ // If we have already started collecting data from the HTTP cache, don't
+ // modify our state.
+ if (cache_collector_->HasStarted())
+ return;
+
// Add the urls from the DOM to |resources_|. The renderer could be
// sending bogus messages, so limit the number of nodes we accept.
- DVLOG(1) << "Nodes from the DOM: " << params.size();
for (uint32 i = 0; i < params.size() && i < kMaxDomNodes; ++i) {
SafeBrowsingHostMsg_MalwareDOMDetails_Node node = params[i];
DVLOG(1) << node.url << ", " << node.tag_name << ", " << node.parent;
@@ -222,21 +242,34 @@
// to take an action, we expect this to be called after
// OnReceivedMalwareDOMDetails in most cases. If not, we don't include
// the DOM data in our report.
-const std::string* MalwareDetails::GetSerializedReport() {
+void MalwareDetails::FinishCollection() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // The |report_| protocol buffer is now generated: We add all the
- // urls in our |resources_| maps.
- for (ResourceMap::const_iterator it = resources_.begin();
+
+ cache_collector_->StartCacheCollection(
+ request_context_getter_,
+ &resources_,
+ &cache_result_,
+ NewRunnableMethod(this, &MalwareDetails::OnCacheCollectionReady));
+}
+
+void MalwareDetails::OnCacheCollectionReady() {
+ DVLOG(1) << "OnCacheCollectionReady.";
+ // Add all the urls in our |resources_| maps to the |report_| protocol buffer.
+ for (safe_browsing::ResourceMap::const_iterator it = resources_.begin();
it != resources_.end(); it++) {
ClientMalwareReportRequest::Resource* pb_resource =
report_->add_resources();
pb_resource->CopyFrom(*(it->second));
}
- scoped_ptr<std::string> request_data(new std::string());
- if (!report_->SerializeToString(request_data.get())) {
+ report_->set_complete(cache_result_);
+
+ // Send the report, using the SafeBrowsingService.
+ std::string serialized;
+ if (!report_->SerializeToString(&serialized)) {
DLOG(ERROR) << "Unable to serialize the malware report.";
+ return;
}
- return request_data.release();
+ sb_service_->SendSerializedMalwareDetails(serialized);
}

Powered by Google App Engine
This is Rietveld 408576698