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

Unified Diff: chrome/browser/safe_browsing/malware_details_cache.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, 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_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,136 @@
+// 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 "base/memory/ref_counted.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> {
+
+ public:
+ MalwareDetailsCacheCollector();
+
+ // We use |request_context_getter|, we modify |resources| and
+ // |result|, and we call |callback|, so they must all remain alive
+ // for the lifetime of this object.
+ void StartCacheCollection(
+ net::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);
+
+ // Returns whether or not StartCacheCollection has been called.
+ bool InProgress();
+
+ 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.
+ net::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_;
+
+ friend class base::RefCountedThreadSafe<MalwareDetailsCacheCollector>;
+ ~MalwareDetailsCacheCollector();
+
+ 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);
+
+ // Advances to the next entry in resources_it_.
+ int AdvanceEntry();
+};
+
+#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

Powered by Google App Engine
This is Rietveld 408576698