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

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, 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 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 "base/memory/ref_counted.h"
19 #include "chrome/browser/safe_browsing/report.pb.h"
20 #include "net/base/completion_callback.h"
21
22 namespace disk_cache {
23 class Backend;
24 class Entry;
25 }
26 namespace net {
27 class IOBuffer;
28 class URLRequestContext;
29 }
30
31 class MalwareDetailsFactory;
32
33 namespace safe_browsing {
34
35 // Maps a URL to its Resource.
36 typedef base::hash_map<
37 std::string,
38 linked_ptr<safe_browsing::ClientMalwareReportRequest::Resource> > ResourceMap;
39 }
40
41 class MalwareDetailsCacheCollector
42 : public base::RefCountedThreadSafe<MalwareDetailsCacheCollector> {
43
44 public:
45 MalwareDetailsCacheCollector();
46
47 // We use |request_context_getter|, we modify |resources| and
48 // |result|, and we call |callback|, so they must all remain alive
49 // for the lifetime of this object.
50 void StartCacheCollection(
51 net::URLRequestContextGetter* request_context_getter,
52 safe_browsing::ResourceMap* resources,
53 int* result,
54 Task* callback);
55
56 // Methods for getting the HTML body and HTTP headers from the HTTP cache.
57 // They run on the IO thread.
58 void CacheLoop(int result);
59
60 // Returns whether or not StartCacheCollection has been called.
61 bool InProgress();
62
63 protected:
64 virtual net::URLRequestContext* GetURLRequestContext();
65
66 private:
67 enum CacheState {
68 STATE_NONE,
69 STATE_OPEN_CACHE,
70 STATE_OPEN_CACHE_COMPLETE,
71 STATE_OPEN_ENTRY,
72 STATE_OPEN_ENTRY_COMPLETE,
73 STATE_READ_RESPONSE,
74 STATE_READ_RESPONSE_COMPLETE,
75 STATE_READ_DATA,
76 STATE_READ_DATA_COMPLETE,
77 STATE_CACHE_DONE,
78 };
79
80 // Points to the url for which we are fetching the HTTP cache entry or
81 // redirect chain.
82 safe_browsing::ResourceMap::iterator resources_it_;
83
84 // Points to the resources_ map in the MalwareDetails.
85 safe_browsing::ResourceMap* resources_;
86
87 // Points to the cache_result_ in the MalwareDetails.
88 int* result_;
89
90 // Method we call when we are done. The caller must be alive for the
91 // whole time, we are modifying its state (see above).
92 Task* callback_;
93
94 // The next cache loop state.
95 CacheState cache_state_;
96
97 // Used to get a pointer to the HTTP cache.
98 net::URLRequestContextGetter* request_context_getter_;
99
100 // The disk cache.
101 disk_cache::Backend* cache_;
102
103 // Callback for when the cache entry is ready.
104 // This is not ref-counted.
105 net::CompletionCallbackImpl<MalwareDetailsCacheCollector> cache_callback_;
106
107 // Callback for when the cache entry is opened.
108 scoped_refptr<
109 net::CancelableCompletionCallback<MalwareDetailsCacheCollector> >
110 entry_callback_;
111
112 // The current disk entry.
113 disk_cache::Entry* entry_;
114
115 // The current buffer for reading the contents of the disk entry.
116 scoped_refptr<net::IOBuffer> buf_;
117 int buf_len_;
118
119 friend class base::RefCountedThreadSafe<MalwareDetailsCacheCollector>;
120 ~MalwareDetailsCacheCollector();
121
122 int DoOpenCache();
123 int DoOpenCacheComplete(int result);
124 int DoOpenEntry();
125 int DoOpenEntryComplete(int result);
126 int DoReadResponse();
127 int DoReadResponseComplete(int result);
128 int DoReadData();
129 int DoReadDataComplete(int result);
130 void DoCacheDone(int result);
131
132 // Advances to the next entry in resources_it_.
133 int AdvanceEntry();
134 };
135
136 #endif // CHROME_BROWSER_SAFE_BROWSING_MALWARE_DETAILS_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698