| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_SQLITE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_SQLITE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_SQLITE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_SQLITE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 class SafeBrowsingStoreSqlite : public SafeBrowsingStore { | 22 class SafeBrowsingStoreSqlite : public SafeBrowsingStore { |
| 23 public: | 23 public: |
| 24 SafeBrowsingStoreSqlite(); | 24 SafeBrowsingStoreSqlite(); |
| 25 virtual ~SafeBrowsingStoreSqlite(); | 25 virtual ~SafeBrowsingStoreSqlite(); |
| 26 | 26 |
| 27 virtual bool Delete(); | 27 virtual bool Delete(); |
| 28 | 28 |
| 29 virtual void Init(const FilePath& filename, | 29 virtual void Init(const FilePath& filename, |
| 30 Callback0::Type* corruption_callback); | 30 Callback0::Type* corruption_callback); |
| 31 | 31 |
| 32 virtual bool BeginChunk() { | 32 virtual bool BeginChunk(); |
| 33 return true; | |
| 34 } | |
| 35 | 33 |
| 36 // Get all Add prefixes out from the store. | 34 // Get all Add prefixes out from the store. |
| 37 virtual bool GetAddPrefixes(std::vector<SBAddPrefix>* add_prefixes); | 35 virtual bool GetAddPrefixes(std::vector<SBAddPrefix>* add_prefixes); |
| 38 virtual bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix) { | 36 virtual bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix); |
| 39 const std::vector<SBAddPrefix> prefixes(1, SBAddPrefix(chunk_id, prefix)); | |
| 40 return WriteAddPrefixes(prefixes); | |
| 41 } | |
| 42 virtual bool WriteAddHash(int32 chunk_id, | 37 virtual bool WriteAddHash(int32 chunk_id, |
| 43 base::Time receive_time, | 38 base::Time receive_time, |
| 44 const SBFullHash& full_hash) { | 39 const SBFullHash& full_hash); |
| 45 const std::vector<SBAddFullHash> | |
| 46 hashes(1, SBAddFullHash(chunk_id, receive_time, full_hash)); | |
| 47 return WriteAddHashes(hashes); | |
| 48 } | |
| 49 virtual bool WriteSubPrefix(int32 chunk_id, | 40 virtual bool WriteSubPrefix(int32 chunk_id, |
| 50 int32 add_chunk_id, SBPrefix prefix) { | 41 int32 add_chunk_id, SBPrefix prefix); |
| 51 const std::vector<SBSubPrefix> | |
| 52 prefixes(1, SBSubPrefix(chunk_id, add_chunk_id, prefix)); | |
| 53 return WriteSubPrefixes(prefixes); | |
| 54 } | |
| 55 virtual bool WriteSubHash(int32 chunk_id, int32 add_chunk_id, | 42 virtual bool WriteSubHash(int32 chunk_id, int32 add_chunk_id, |
| 56 const SBFullHash& full_hash) { | 43 const SBFullHash& full_hash); |
| 57 const std::vector<SBSubFullHash> | 44 virtual bool FinishChunk(); |
| 58 hashes(1, SBSubFullHash(chunk_id, add_chunk_id, full_hash)); | |
| 59 return WriteSubHashes(hashes); | |
| 60 } | |
| 61 virtual bool FinishChunk() { | |
| 62 return true; | |
| 63 } | |
| 64 | 45 |
| 65 virtual bool BeginUpdate(); | 46 virtual bool BeginUpdate(); |
| 66 // TODO(shess): Should not be public. | 47 // TODO(shess): Should not be public. |
| 67 virtual bool DoUpdate(const std::vector<SBAddFullHash>& pending_adds, | 48 virtual bool DoUpdate(const std::vector<SBAddFullHash>& pending_adds, |
| 68 std::vector<SBAddPrefix>* add_prefixes_result, | 49 std::vector<SBAddPrefix>* add_prefixes_result, |
| 69 std::vector<SBAddFullHash>* add_full_hashes_result); | 50 std::vector<SBAddFullHash>* add_full_hashes_result); |
| 70 // NOTE: |prefix_misses| is ignored, as it will be handled in | 51 // NOTE: |prefix_misses| is ignored, as it will be handled in |
| 71 // |SafeBrowsingStoreFile::DoUpdate()|. | 52 // |SafeBrowsingStoreFile::DoUpdate()|. |
| 72 virtual bool FinishUpdate(const std::vector<SBAddFullHash>& pending_adds, | 53 virtual bool FinishUpdate(const std::vector<SBAddFullHash>& pending_adds, |
| 73 const std::set<SBPrefix>& prefix_misses, | 54 const std::set<SBPrefix>& prefix_misses, |
| 74 std::vector<SBAddPrefix>* add_prefixes_result, | 55 std::vector<SBAddPrefix>* add_prefixes_result, |
| 75 std::vector<SBAddFullHash>* add_full_hashes_result); | 56 std::vector<SBAddFullHash>* add_full_hashes_result); |
| 76 virtual bool CancelUpdate(); | 57 virtual bool CancelUpdate(); |
| 77 | 58 |
| 78 virtual void SetAddChunk(int32 chunk_id) { | 59 virtual void SetAddChunk(int32 chunk_id); |
| 79 add_chunks_cache_.insert(chunk_id); | 60 virtual bool CheckAddChunk(int32 chunk_id); |
| 80 } | 61 virtual void GetAddChunks(std::vector<int32>* out); |
| 81 virtual bool CheckAddChunk(int32 chunk_id) { | |
| 82 return add_chunks_cache_.count(chunk_id) > 0; | |
| 83 } | |
| 84 virtual void GetAddChunks(std::vector<int32>* out) { | |
| 85 out->clear(); | |
| 86 out->insert(out->end(), add_chunks_cache_.begin(), add_chunks_cache_.end()); | |
| 87 } | |
| 88 | 62 |
| 89 virtual void SetSubChunk(int32 chunk_id) { | 63 virtual void SetSubChunk(int32 chunk_id); |
| 90 sub_chunks_cache_.insert(chunk_id); | 64 virtual bool CheckSubChunk(int32 chunk_id); |
| 91 } | 65 virtual void GetSubChunks(std::vector<int32>* out); |
| 92 virtual bool CheckSubChunk(int32 chunk_id) { | |
| 93 return sub_chunks_cache_.count(chunk_id) > 0; | |
| 94 } | |
| 95 virtual void GetSubChunks(std::vector<int32>* out) { | |
| 96 out->clear(); | |
| 97 out->insert(out->end(), sub_chunks_cache_.begin(), sub_chunks_cache_.end()); | |
| 98 } | |
| 99 | 66 |
| 100 virtual void DeleteAddChunk(int32 chunk_id) { | 67 virtual void DeleteAddChunk(int32 chunk_id); |
| 101 add_del_cache_.insert(chunk_id); | 68 virtual void DeleteSubChunk(int32 chunk_id); |
| 102 } | |
| 103 virtual void DeleteSubChunk(int32 chunk_id) { | |
| 104 sub_del_cache_.insert(chunk_id); | |
| 105 } | |
| 106 | 69 |
| 107 // Returns the name of the SQLite journal file for |filename|. | 70 // Returns the name of the SQLite journal file for |filename|. |
| 108 // Exported for unit tests. | 71 // Exported for unit tests. |
| 109 static const FilePath JournalFileForFilename(const FilePath& filename) { | 72 static const FilePath JournalFileForFilename(const FilePath& filename); |
| 110 return FilePath(filename.value() + FILE_PATH_LITERAL("-journal")); | |
| 111 } | |
| 112 | 73 |
| 113 private: | 74 private: |
| 114 // For on-the-fly migration. | 75 // For on-the-fly migration. |
| 115 // TODO(shess): Remove (entire class) after migration. | 76 // TODO(shess): Remove (entire class) after migration. |
| 116 friend class SafeBrowsingStoreFile; | 77 friend class SafeBrowsingStoreFile; |
| 117 | 78 |
| 118 // The following routines return true on success, or false on | 79 // The following routines return true on success, or false on |
| 119 // failure. Failure is presumed to be persistent, so the caller | 80 // failure. Failure is presumed to be persistent, so the caller |
| 120 // should stop trying and unwind the transaction. | 81 // should stop trying and unwind the transaction. |
| 121 // OnCorruptDatabase() is called if SQLite returns SQLITE_CORRUPT. | 82 // OnCorruptDatabase() is called if SQLite returns SQLITE_CORRUPT. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 base::hash_set<int32> add_del_cache_; | 150 base::hash_set<int32> add_del_cache_; |
| 190 base::hash_set<int32> sub_del_cache_; | 151 base::hash_set<int32> sub_del_cache_; |
| 191 | 152 |
| 192 // Called when SQLite returns SQLITE_CORRUPT. | 153 // Called when SQLite returns SQLITE_CORRUPT. |
| 193 scoped_ptr<Callback0::Type> corruption_callback_; | 154 scoped_ptr<Callback0::Type> corruption_callback_; |
| 194 | 155 |
| 195 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreSqlite); | 156 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreSqlite); |
| 196 }; | 157 }; |
| 197 | 158 |
| 198 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_SQLITE_H_ | 159 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_SQLITE_H_ |
| OLD | NEW |