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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_
7 #pragma once
8
9 // A class that gets malware details from the HTTP Cache.
10
11 // An instance of this class is generated by MalwareDetails.
12
13 #include <string>
14 #include <vector>
15
16 #include "base/hash_tables.h"
17 #include "base/memory/linked_ptr.h"
18 #include "chrome/browser/safe_browsing/report.pb.h"
19 #include "net/base/completion_callback.h"
20
21 namespace disk_cache {
22 class Backend;
23 class Entry;
24 }
25 namespace net {
26 class IOBuffer;
27 class URLRequestContext;
28 }
29
30 class MalwareDetailsFactory;
31
32 namespace safe_browsing {
33 // Maps a URL to its Resource.
34 typedef base::hash_map<
35 std::string,
36 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap;
37 }
38
39 class MalwareDetailsCacheCollector:
40 public base::RefCountedThreadSafe<MalwareDetailsCacheCollector> {
41
42 public:
43
44 MalwareDetailsCacheCollector();
45 ~MalwareDetailsCacheCollector();
46
47 // Callback with the malware details, serialized. See GetSerializedReport.
48 typedef Callback1<int>::Type MalwareDetailsCacheCollectorCallback;
49
50 void StartCacheCollection(URLRequestContextGetter* request_context_getter,
51 safe_browsing::ResourceMap* resources,
52 MalwareDetailsCacheCollectorCallback* callback);
53
54 // Methods for getting the HTML body and HTTP headers from the HTTP cache.
55 // They run on the IO thread.
56 void CacheLoop(int result);
57 int DoOpenCache();
58 int DoOpenCacheComplete(int result);
59 int DoOpenEntry();
60 int DoOpenEntryComplete(int result);
61 int DoReadResponse();
62 int DoReadResponseComplete(int result);
63 int DoReadData();
64 int DoReadDataComplete(int result);
65 void DoCacheDone(int result);
66
67 bool InProgress();
68
69 protected:
70 virtual net::URLRequestContext* GetURLRequestContext();
71
72 private:
73 enum CacheState {
74 STATE_NONE,
75 STATE_OPEN_CACHE,
76 STATE_OPEN_CACHE_COMPLETE,
77 STATE_OPEN_ENTRY,
78 STATE_OPEN_ENTRY_COMPLETE,
79 STATE_READ_RESPONSE,
80 STATE_READ_RESPONSE_COMPLETE,
81 STATE_READ_DATA,
82 STATE_READ_DATA_COMPLETE,
83 STATE_CACHE_DONE,
84 };
85
86 // Points to the url for which we are fetching the HTTP cache entry or
87 // redirect chain.
88 safe_browsing::ResourceMap::iterator resources_it_;
89
90 // Points to the resources_ map in the MalwareDetails.
91 safe_browsing::ResourceMap* resources_;
92
93 // MalwareDetails method we call when we are done. MalwareDetails
94 // must be alive for the whole time, we are modifying its state.
95 MalwareDetailsCacheCollectorCallback* callback_;
96
97 // The next cache loop state.
98 CacheState cache_state_;
99
100 // Used to get a pointer to the HTTP cache.
101 URLRequestContextGetter* request_context_getter_;
102
103 // The disk cache.
104 disk_cache::Backend* cache_;
105
106 // Callback for when the cache entry is ready.
107 net::CompletionCallbackImpl<MalwareDetailsCacheCollector> cache_callback_;
108
109 // Callback for when the cache entry is opened.
110 scoped_refptr<
111 net::CancelableCompletionCallback<MalwareDetailsCacheCollector> >
112 entry_callback_;
113
114 // The current disk entry.
115 disk_cache::Entry* entry_;
116
117 // The current buffer for reading the contents of the disk entry.
118 scoped_refptr<net::IOBuffer> buf_;
119 int buf_len_;
120 };
121
122 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698