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

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

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, 10 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.h
===================================================================
--- chrome/browser/safe_browsing/malware_details.h (revision 76771)
+++ chrome/browser/safe_browsing/malware_details.h (working copy)
@@ -22,10 +22,20 @@
#include "chrome/browser/safe_browsing/report.pb.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "content/browser/tab_contents/tab_contents_observer.h"
+#include "net/base/completion_callback.h"
class TabContents;
struct ViewHostMsg_MalwareDOMDetails_Params;
+namespace disk_cache {
+class Backend;
+class Entry;
+}
+namespace net {
+class IOBuffer;
+class URLRequestContext;
+}
+
class MalwareDetailsFactory;
class MalwareDetails : public base::RefCountedThreadSafe<MalwareDetails>,
@@ -42,8 +52,15 @@
factory_ = factory;
}
+ // Callback with the malware details, serialized. See GetSerializedReport.
+ typedef Callback1<scoped_refptr<MalwareDetails> >::Type
+ MalwareDetailsCallback;
+
// The SafeBrowsingService calls this from the IO thread, to get the
// serialized report as a string and send it over.
+ // |callback| will be notified when the operation completes.
+ void StartCacheCollection(MalwareDetailsCallback* callback);
+
const std::string* GetSerializedReport();
// TabContentsObserver implementation.
@@ -59,8 +76,13 @@
virtual void AddDOMDetails(
const ViewHostMsg_MalwareDOMDetails_Params& params);
+ virtual net::URLRequestContext* GetURLRequestContext();
+
virtual ~MalwareDetails();
lzheng 2011/03/05 00:37:50 I think ~MalwareDetails() should be right after Ma
panayiotis 2011/03/29 18:14:55 Done.
+ // The report protocol buffer.
+ scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_;
+
private:
friend class base::RefCountedThreadSafe<MalwareDetails>;
@@ -70,6 +92,19 @@
linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> >
ResourceMap;
lzheng 2011/03/05 00:37:50 I would suggest to move the cache-mining code to i
panayiotis 2011/03/29 18:14:55 Done.
+ enum CacheState {
+ STATE_NONE,
+ STATE_OPEN_CACHE,
+ STATE_OPEN_CACHE_COMPLETE,
+ STATE_OPEN_ENTRY,
+ STATE_OPEN_ENTRY_COMPLETE,
+ STATE_READ_RESPONSE,
+ STATE_READ_RESPONSE_COMPLETE,
+ STATE_READ_DATA,
+ STATE_READ_DATA_COMPLETE,
+ STATE_CACHE_DONE,
+ };
+
// Starts the collection of the report.
void StartCollection();
@@ -93,21 +128,65 @@
void OnReceivedMalwareDOMDetails(
const ViewHostMsg_MalwareDOMDetails_Params& params);
+ // Methods for getting the HTML body and HTTP headers from the HTTP cache.
+ // They run on the IO thread.
+ void CacheLoop(int result);
+ int DoOpenCache();
+ int DoOpenCacheComplete(int result);
+ int DoOpenEntry();
+ int DoOpenEntryComplete(int result);
+ int DoReadResponse();
+ int DoReadResponseComplete(int result);
+ int DoReadData();
+ int DoReadDataComplete(int result);
+ void DoCacheDone(int result);
+
const SafeBrowsingService::UnsafeResource resource_;
// For every Url we collect we create a Resource message. We keep
// them in a map so we can avoid duplicates.
ResourceMap resources_;
- // The report protocol buffer.
- scoped_ptr<safe_browsing::ClientMalwareReportRequest> report_;
-
// The factory used to instanciate SafeBrowsingBlockingPage objects.
// Usefull for tests, so they can provide their own implementation of
// SafeBrowsingBlockingPage.
static MalwareDetailsFactory* factory_;
+ // The next cache loop state.
+ CacheState cache_state_;
+
+ // Used to get a pointer to the HTTP cache.
+ URLRequestContextGetter* request_context_getter_;
+
+ // The disk cache.
+ disk_cache::Backend* cache_;
+
+ // Callback for when the cache entry is ready.
+ net::CompletionCallbackImpl<MalwareDetails> cache_callback_;
+
+ // Callback for when the cache entry is opened.
+ scoped_refptr<
+ net::CancelableCompletionCallback<MalwareDetails> > entry_callback_;
+
+ // SafeBrowsingService provides us a method to call when we are done
+ // with the cache. The service outlives the MalwareDetails (in fact, it
+ // takes ownership of MalwareDetails).
+ MalwareDetailsCallback* callback_;
+
+ // Points to the url for which we are fetching the HTTP cache entry or
+ // redirect chain.
+ ResourceMap::iterator resources_it_;
+
+ // The current disk entry.
+ disk_cache::Entry* entry_;
+
+ // The current buffer for reading the contents of the disk entry.
+ scoped_refptr<net::IOBuffer> buf_;
+ int buf_len_;
+
FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, MalwareDOMDetails);
+ FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCache);
+ FRIEND_TEST_ALL_PREFIXES(MalwareDetailsTest, HTTPCacheNoEntries);
DISALLOW_COPY_AND_ASSIGN(MalwareDetails);
};
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/malware_details.cc » ('j') | chrome/browser/safe_browsing/malware_details.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698