#ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_
#define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/containers/hash_tables.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/safe_browsing/report.pb.h"
#include "net/base/completion_callback.h"
#include "net/url_request/url_fetcher_delegate.h"
namespace net {
class URLFetcher;
class URLRequestContext;
}
namespace safe_browsing {
typedef base::hash_map<
std::string,
linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap;
}
class MalwareDetailsCacheCollector
: public base::RefCountedThreadSafe<MalwareDetailsCacheCollector>,
public net::URLFetcherDelegate {
public:
MalwareDetailsCacheCollector();
void StartCacheCollection(
net::URLRequestContextGetter* request_context_getter,
safe_browsing::ResourceMap* resources,
bool* result,
const base::Closure& callback);
bool HasStarted();
protected:
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
private:
friend class base::RefCountedThreadSafe<MalwareDetailsCacheCollector>;
virtual ~MalwareDetailsCacheCollector();
safe_browsing::ResourceMap::iterator resources_it_;
safe_browsing::ResourceMap* resources_;
bool* result_;
base::Closure callback_;
bool has_started_;
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
scoped_ptr<net::URLFetcher> current_fetch_;
safe_browsing::ClientMalwareReportRequest::Resource* GetResource(
const GURL& url);
void OpenEntry();
void ReadResponse(
safe_browsing::ClientMalwareReportRequest::Resource* pb_resource,
const net::URLFetcher* source);
void ReadData(
safe_browsing::ClientMalwareReportRequest::Resource* pb_resource,
const std::string& data);
void AllDone(bool success);
void AdvanceEntry();
};
#endif