Chromium Code Reviews| Index: chrome/browser/safe_browsing/malware_details_cache.h |
| =================================================================== |
| --- chrome/browser/safe_browsing/malware_details_cache.h (revision 0) |
| +++ chrome/browser/safe_browsing/malware_details_cache.h (revision 0) |
| @@ -0,0 +1,126 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
| +#define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
| +#pragma once |
| + |
| +// A class that gets malware details from the HTTP Cache. |
| + |
| +// An instance of this class is generated by MalwareDetails. |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/hash_tables.h" |
| +#include "base/memory/linked_ptr.h" |
| +#include "chrome/browser/safe_browsing/report.pb.h" |
| +#include "net/base/completion_callback.h" |
| + |
| +namespace disk_cache { |
| +class Backend; |
| +class Entry; |
| +} |
| +namespace net { |
| +class IOBuffer; |
| +class URLRequestContext; |
| +} |
| + |
| +class MalwareDetailsFactory; |
| + |
| +namespace safe_browsing { |
| + |
| +// Maps a URL to its Resource. |
| +typedef base::hash_map< |
| + std::string, |
| + linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap; |
| +} |
| + |
| +class MalwareDetailsCacheCollector |
| + : public base::RefCountedThreadSafe<MalwareDetailsCacheCollector> { |
|
noelutz
2011/04/06 20:34:19
include base/memory/ref_counted.h?
panayiotis
2011/04/07 20:08:32
Done.
|
| + |
| + public: |
| + |
|
noelutz
2011/04/06 20:34:19
nit: remove extra nl?
panayiotis
2011/04/07 20:08:32
Done.
|
| + MalwareDetailsCacheCollector(); |
| + ~MalwareDetailsCacheCollector(); |
|
noelutz
2011/04/06 20:34:19
I think the destructor needs to be private? See r
panayiotis
2011/04/07 20:08:32
Done.
|
| + |
| + void StartCacheCollection( |
|
noelutz
2011/04/06 20:34:19
I think this methods needs a comment. E.g., how l
panayiotis
2011/04/07 20:08:32
Done.
|
| + URLRequestContextGetter* request_context_getter, |
| + safe_browsing::ResourceMap* resources, |
| + int* result, |
| + Task* callback); |
| + |
| + // 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(); |
|
noelutz
2011/04/06 20:34:19
Do all these methods have to be public?
panayiotis
2011/04/07 20:08:32
Done.
|
| + 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); |
| + |
| + bool InProgress(); |
|
noelutz
2011/04/06 20:34:19
Maybe add a comment for all public methods?
panayiotis
2011/04/07 20:08:32
Done.
|
| + |
| + protected: |
| + virtual net::URLRequestContext* GetURLRequestContext(); |
| + |
| + private: |
| + 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, |
| + }; |
| + |
| + // Points to the url for which we are fetching the HTTP cache entry or |
| + // redirect chain. |
| + safe_browsing::ResourceMap::iterator resources_it_; |
| + |
| + // Points to the resources_ map in the MalwareDetails. |
| + safe_browsing::ResourceMap* resources_; |
| + |
| + // Points to the cache_result_ in the MalwareDetails. |
| + int* result_; |
| + |
| + // Method we call when we are done. The caller must be alive for the |
| + // whole time, we are modifying its state (see above). |
| + Task* callback_; |
| + |
| + // 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. |
| + // This is not ref-counted. |
| + net::CompletionCallbackImpl<MalwareDetailsCacheCollector> cache_callback_; |
| + |
| + // Callback for when the cache entry is opened. |
| + scoped_refptr< |
| + net::CancelableCompletionCallback<MalwareDetailsCacheCollector> > |
| + entry_callback_; |
| + |
| + // 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_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_ |
| Property changes on: chrome/browser/safe_browsing/malware_details_cache.h |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |