| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_FILE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // - Until done: | 118 // - Until done: |
| 119 // - Read shards of the original file's data into memory. | 119 // - Read shards of the original file's data into memory. |
| 120 // - Merge from the update data. | 120 // - Merge from the update data. |
| 121 // - Write shards to the temp file. | 121 // - Write shards to the temp file. |
| 122 // - Delete original file. | 122 // - Delete original file. |
| 123 // - Rename temp file to original filename. | 123 // - Rename temp file to original filename. |
| 124 | 124 |
| 125 class SafeBrowsingStoreFile : public SafeBrowsingStore { | 125 class SafeBrowsingStoreFile : public SafeBrowsingStore { |
| 126 public: | 126 public: |
| 127 SafeBrowsingStoreFile(); | 127 SafeBrowsingStoreFile(); |
| 128 virtual ~SafeBrowsingStoreFile(); | 128 ~SafeBrowsingStoreFile() override; |
| 129 | 129 |
| 130 virtual void Init(const base::FilePath& filename, | 130 void Init(const base::FilePath& filename, |
| 131 const base::Closure& corruption_callback) override; | 131 const base::Closure& corruption_callback) override; |
| 132 | 132 |
| 133 // Delete any on-disk files, including the permanent storage. | 133 // Delete any on-disk files, including the permanent storage. |
| 134 virtual bool Delete() override; | 134 bool Delete() override; |
| 135 | 135 |
| 136 // Get all add hash prefixes and full-length hashes, respectively, from | 136 // Get all add hash prefixes and full-length hashes, respectively, from |
| 137 // the store. | 137 // the store. |
| 138 virtual bool GetAddPrefixes(SBAddPrefixes* add_prefixes) override; | 138 bool GetAddPrefixes(SBAddPrefixes* add_prefixes) override; |
| 139 virtual bool GetAddFullHashes( | 139 bool GetAddFullHashes(std::vector<SBAddFullHash>* add_full_hashes) override; |
| 140 std::vector<SBAddFullHash>* add_full_hashes) override; | |
| 141 | 140 |
| 142 virtual bool BeginChunk() override; | 141 bool BeginChunk() override; |
| 143 | 142 |
| 144 virtual bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix) override; | 143 bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix) override; |
| 145 virtual bool WriteAddHash(int32 chunk_id, | 144 bool WriteAddHash(int32 chunk_id, const SBFullHash& full_hash) override; |
| 146 const SBFullHash& full_hash) override; | 145 bool WriteSubPrefix(int32 chunk_id, |
| 147 virtual bool WriteSubPrefix(int32 chunk_id, | 146 int32 add_chunk_id, |
| 148 int32 add_chunk_id, SBPrefix prefix) override; | 147 SBPrefix prefix) override; |
| 149 virtual bool WriteSubHash(int32 chunk_id, int32 add_chunk_id, | 148 bool WriteSubHash(int32 chunk_id, |
| 150 const SBFullHash& full_hash) override; | 149 int32 add_chunk_id, |
| 151 virtual bool FinishChunk() override; | 150 const SBFullHash& full_hash) override; |
| 151 bool FinishChunk() override; |
| 152 | 152 |
| 153 virtual bool BeginUpdate() override; | 153 bool BeginUpdate() override; |
| 154 virtual bool FinishUpdate( | 154 bool FinishUpdate( |
| 155 safe_browsing::PrefixSetBuilder* builder, | 155 safe_browsing::PrefixSetBuilder* builder, |
| 156 std::vector<SBAddFullHash>* add_full_hashes_result) override; | 156 std::vector<SBAddFullHash>* add_full_hashes_result) override; |
| 157 virtual bool CancelUpdate() override; | 157 bool CancelUpdate() override; |
| 158 | 158 |
| 159 virtual void SetAddChunk(int32 chunk_id) override; | 159 void SetAddChunk(int32 chunk_id) override; |
| 160 virtual bool CheckAddChunk(int32 chunk_id) override; | 160 bool CheckAddChunk(int32 chunk_id) override; |
| 161 virtual void GetAddChunks(std::vector<int32>* out) override; | 161 void GetAddChunks(std::vector<int32>* out) override; |
| 162 virtual void SetSubChunk(int32 chunk_id) override; | 162 void SetSubChunk(int32 chunk_id) override; |
| 163 virtual bool CheckSubChunk(int32 chunk_id) override; | 163 bool CheckSubChunk(int32 chunk_id) override; |
| 164 virtual void GetSubChunks(std::vector<int32>* out) override; | 164 void GetSubChunks(std::vector<int32>* out) override; |
| 165 | 165 |
| 166 virtual void DeleteAddChunk(int32 chunk_id) override; | 166 void DeleteAddChunk(int32 chunk_id) override; |
| 167 virtual void DeleteSubChunk(int32 chunk_id) override; | 167 void DeleteSubChunk(int32 chunk_id) override; |
| 168 | 168 |
| 169 // Verify |file_|'s checksum, calling the corruption callback if it | 169 // Verify |file_|'s checksum, calling the corruption callback if it |
| 170 // does not check out. Empty input is considered valid. | 170 // does not check out. Empty input is considered valid. |
| 171 virtual bool CheckValidity() override; | 171 bool CheckValidity() override; |
| 172 | 172 |
| 173 // Returns the name of the temporary file used to buffer data for | 173 // Returns the name of the temporary file used to buffer data for |
| 174 // |filename|. Exported for unit tests. | 174 // |filename|. Exported for unit tests. |
| 175 static const base::FilePath TemporaryFileForFilename( | 175 static const base::FilePath TemporaryFileForFilename( |
| 176 const base::FilePath& filename) { | 176 const base::FilePath& filename) { |
| 177 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); | 177 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Delete any on-disk files, including the permanent storage. | 180 // Delete any on-disk files, including the permanent storage. |
| 181 static bool DeleteStore(const base::FilePath& basename); | 181 static bool DeleteStore(const base::FilePath& basename); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 // Tracks whether corruption has already been seen in the current | 264 // Tracks whether corruption has already been seen in the current |
| 265 // update, so that only one instance is recorded in the stats. | 265 // update, so that only one instance is recorded in the stats. |
| 266 // TODO(shess): Remove with format-migration support. | 266 // TODO(shess): Remove with format-migration support. |
| 267 bool corruption_seen_; | 267 bool corruption_seen_; |
| 268 | 268 |
| 269 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); | 269 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); |
| 270 }; | 270 }; |
| 271 | 271 |
| 272 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ | 272 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ |
| OLD | NEW |