Chromium Code Reviews| 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); |
| }; |