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 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 | 10 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 return true; | 214 return true; |
215 } | 215 } |
216 | 216 |
217 void SafeBrowsingStoreFile::Init(const FilePath& filename, | 217 void SafeBrowsingStoreFile::Init(const FilePath& filename, |
218 Callback0::Type* corruption_callback) { | 218 Callback0::Type* corruption_callback) { |
219 filename_ = filename; | 219 filename_ = filename; |
220 corruption_callback_.reset(corruption_callback); | 220 corruption_callback_.reset(corruption_callback); |
221 } | 221 } |
222 | 222 |
| 223 bool SafeBrowsingStoreFile::BeginChunk() { |
| 224 return ClearChunkBuffers(); |
| 225 } |
| 226 |
| 227 bool SafeBrowsingStoreFile::WriteAddPrefix(int32 chunk_id, SBPrefix prefix) { |
| 228 add_prefixes_.push_back(SBAddPrefix(chunk_id, prefix)); |
| 229 return true; |
| 230 } |
| 231 |
| 232 bool SafeBrowsingStoreFile::WriteAddHash(int32 chunk_id, |
| 233 base::Time receive_time, |
| 234 SBFullHash full_hash) { |
| 235 add_hashes_.push_back(SBAddFullHash(chunk_id, receive_time, full_hash)); |
| 236 return true; |
| 237 } |
| 238 |
| 239 bool SafeBrowsingStoreFile::WriteSubPrefix(int32 chunk_id, |
| 240 int32 add_chunk_id, |
| 241 SBPrefix prefix) { |
| 242 sub_prefixes_.push_back(SBSubPrefix(chunk_id, add_chunk_id, prefix)); |
| 243 return true; |
| 244 } |
| 245 |
| 246 bool SafeBrowsingStoreFile::WriteSubHash(int32 chunk_id, int32 add_chunk_id, |
| 247 SBFullHash full_hash) { |
| 248 sub_hashes_.push_back(SBSubFullHash(chunk_id, add_chunk_id, full_hash)); |
| 249 return true; |
| 250 } |
| 251 |
223 bool SafeBrowsingStoreFile::OnCorruptDatabase() { | 252 bool SafeBrowsingStoreFile::OnCorruptDatabase() { |
224 if (corruption_callback_.get()) | 253 if (corruption_callback_.get()) |
225 corruption_callback_->Run(); | 254 corruption_callback_->Run(); |
226 | 255 |
227 // Return false as a convenience to callers. | 256 // Return false as a convenience to callers. |
228 return false; | 257 return false; |
229 } | 258 } |
230 | 259 |
231 bool SafeBrowsingStoreFile::Close() { | 260 bool SafeBrowsingStoreFile::Close() { |
232 ClearUpdateBuffers(); | 261 ClearUpdateBuffers(); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 DCHECK(!file_.get()); | 609 DCHECK(!file_.get()); |
581 DCHECK(!old_store_.get()); | 610 DCHECK(!old_store_.get()); |
582 | 611 |
583 return Close(); | 612 return Close(); |
584 } | 613 } |
585 | 614 |
586 bool SafeBrowsingStoreFile::CancelUpdate() { | 615 bool SafeBrowsingStoreFile::CancelUpdate() { |
587 old_store_.reset(); | 616 old_store_.reset(); |
588 return Close(); | 617 return Close(); |
589 } | 618 } |
| 619 |
| 620 void SafeBrowsingStoreFile::SetAddChunk(int32 chunk_id) { |
| 621 add_chunks_cache_.insert(chunk_id); |
| 622 } |
| 623 |
| 624 bool SafeBrowsingStoreFile::CheckAddChunk(int32 chunk_id) { |
| 625 return add_chunks_cache_.count(chunk_id) > 0; |
| 626 } |
| 627 |
| 628 void SafeBrowsingStoreFile::GetAddChunks(std::vector<int32>* out) { |
| 629 out->clear(); |
| 630 out->insert(out->end(), add_chunks_cache_.begin(), add_chunks_cache_.end()); |
| 631 } |
| 632 |
| 633 void SafeBrowsingStoreFile::SetSubChunk(int32 chunk_id) { |
| 634 sub_chunks_cache_.insert(chunk_id); |
| 635 } |
| 636 |
| 637 bool SafeBrowsingStoreFile::CheckSubChunk(int32 chunk_id) { |
| 638 return sub_chunks_cache_.count(chunk_id) > 0; |
| 639 } |
| 640 |
| 641 void SafeBrowsingStoreFile::GetSubChunks(std::vector<int32>* out) { |
| 642 out->clear(); |
| 643 out->insert(out->end(), sub_chunks_cache_.begin(), sub_chunks_cache_.end()); |
| 644 } |
| 645 |
| 646 void SafeBrowsingStoreFile::DeleteAddChunk(int32 chunk_id) { |
| 647 add_del_cache_.insert(chunk_id); |
| 648 } |
| 649 |
| 650 void SafeBrowsingStoreFile::DeleteSubChunk(int32 chunk_id) { |
| 651 sub_del_cache_.insert(chunk_id); |
| 652 } |
OLD | NEW |