summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing/safe_browsing_util.h
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-08 21:43:16 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-08 21:43:16 +0000
commit7b1e3710535c1bc6945ad170f667e0a1e9a88ef9 (patch)
tree2bd669956a242ac48e30093aeacf2d4a57f612da /chrome/browser/safe_browsing/safe_browsing_util.h
parent16e70aeca7951680226d7ad461d5c21dadccc728 (diff)
downloadchromium_src-7b1e3710535c1bc6945ad170f667e0a1e9a88ef9.zip
chromium_src-7b1e3710535c1bc6945ad170f667e0a1e9a88ef9.tar.gz
chromium_src-7b1e3710535c1bc6945ad170f667e0a1e9a88ef9.tar.bz2
Refactor chunk ownership in SafeBrowsing code.
This attempts to clean up ownership so that it's more clear who creates and deletes the chunk data between parsing and storage in the database. SBChunkList replaces std::deque<SBChunk>, mostly to add correct cleanup in the destructor rather than requiring FreeChunks() to be called manually. Additionally remove deletion of chunk info from the database layer, now it processes const data. Additionally remove the need for SafeBrowsingDatabase to have a chunk-inserted callback by having the caller handle it directly. BUG=none TEST=none Review URL: http://codereview.chromium.org/668123 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40942 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/safe_browsing_util.h')
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_util.h47
1 files changed, 45 insertions, 2 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_util.h b/chrome/browser/safe_browsing/safe_browsing_util.h
index 21fd7e3..ea58891 100644
--- a/chrome/browser/safe_browsing/safe_browsing_util.h
+++ b/chrome/browser/safe_browsing/safe_browsing_util.h
@@ -12,6 +12,7 @@
#include <string>
#include <vector>
+#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/safe_browsing/chunk_range.h"
@@ -59,6 +60,50 @@ struct SBChunk {
std::deque<SBChunkHost> hosts;
};
+// Container for a set of chunks. Interim wrapper to replace use of
+// |std::deque<SBChunk>| with something having safer memory semantics.
+// management.
+// TODO(shess): |SBEntry| is currently a very roundabout way to hold
+// things pending storage. It could be replaced with the structures
+// used in SafeBrowsingStore, then lots of bridging code could
+// dissappear.
+class SBChunkList {
+ public:
+ SBChunkList() {}
+ ~SBChunkList() {
+ clear();
+ }
+
+ // Implement that subset of the |std::deque<>| interface which
+ // callers expect.
+ bool empty() const { return chunks_.empty(); }
+ size_t size() { return chunks_.size(); }
+
+ void push_back(const SBChunk& chunk) { chunks_.push_back(chunk); }
+ SBChunk& back() { return chunks_.back(); }
+ SBChunk& front() { return chunks_.front(); }
+ const SBChunk& front() const { return chunks_.front(); }
+
+ typedef std::vector<SBChunk>::const_iterator const_iterator;
+ const_iterator begin() const { return chunks_.begin(); }
+ const_iterator end() const { return chunks_.end(); }
+
+ typedef std::vector<SBChunk>::iterator iterator;
+ iterator begin() { return chunks_.begin(); }
+ iterator end() { return chunks_.end(); }
+
+ SBChunk& operator[](size_t n) { return chunks_[n]; }
+ const SBChunk& operator[](size_t n) const { return chunks_[n]; }
+
+ // Calls |SBEvent::Destroy()| before clearing |chunks_|.
+ void clear();
+
+ private:
+ std::vector<SBChunk> chunks_;
+
+ DISALLOW_COPY_AND_ASSIGN(SBChunkList);
+};
+
// Used when we get a gethash response.
struct SBFullHashResult {
SBFullHash hash;
@@ -229,8 +274,6 @@ enum ListType {
int GetListId(const std::string& name);
std::string GetListName(int list_id);
-void FreeChunks(std::deque<SBChunk>* chunks);
-
// Given a URL, returns all the hosts we need to check. They are returned
// in order of size (i.e. b.c is first, then a.b.c).
void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts);