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

Side by Side Diff: trunk/src/chrome/browser/safe_browsing/safe_browsing_store_file.cc

Issue 105823009: Revert 239280 "Move more file_util functions to base namespace." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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
OLDNEW
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 #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/md5.h" 7 #include "base/md5.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 9
10 namespace { 10 namespace {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 285 }
286 286
287 bool SafeBrowsingStoreFile::WriteAddPrefix(int32 chunk_id, SBPrefix prefix) { 287 bool SafeBrowsingStoreFile::WriteAddPrefix(int32 chunk_id, SBPrefix prefix) {
288 add_prefixes_.push_back(SBAddPrefix(chunk_id, prefix)); 288 add_prefixes_.push_back(SBAddPrefix(chunk_id, prefix));
289 return true; 289 return true;
290 } 290 }
291 291
292 bool SafeBrowsingStoreFile::GetAddPrefixes(SBAddPrefixes* add_prefixes) { 292 bool SafeBrowsingStoreFile::GetAddPrefixes(SBAddPrefixes* add_prefixes) {
293 add_prefixes->clear(); 293 add_prefixes->clear();
294 294
295 file_util::ScopedFILE file(base::OpenFile(filename_, "rb")); 295 file_util::ScopedFILE file(file_util::OpenFile(filename_, "rb"));
296 if (file.get() == NULL) return false; 296 if (file.get() == NULL) return false;
297 297
298 FileHeader header; 298 FileHeader header;
299 if (!ReadAndVerifyHeader(filename_, file.get(), &header, NULL)) 299 if (!ReadAndVerifyHeader(filename_, file.get(), &header, NULL))
300 return OnCorruptDatabase(); 300 return OnCorruptDatabase();
301 301
302 size_t add_prefix_offset = header.add_chunk_count * sizeof(int32) + 302 size_t add_prefix_offset = header.add_chunk_count * sizeof(int32) +
303 header.sub_chunk_count * sizeof(int32); 303 header.sub_chunk_count * sizeof(int32);
304 if (!FileSkip(add_prefix_offset, file.get())) 304 if (!FileSkip(add_prefix_offset, file.get()))
305 return false; 305 return false;
306 306
307 if (!ReadToContainer(add_prefixes, header.add_prefix_count, file.get(), NULL)) 307 if (!ReadToContainer(add_prefixes, header.add_prefix_count, file.get(), NULL))
308 return false; 308 return false;
309 309
310 return true; 310 return true;
311 } 311 }
312 312
313 bool SafeBrowsingStoreFile::GetAddFullHashes( 313 bool SafeBrowsingStoreFile::GetAddFullHashes(
314 std::vector<SBAddFullHash>* add_full_hashes) { 314 std::vector<SBAddFullHash>* add_full_hashes) {
315 add_full_hashes->clear(); 315 add_full_hashes->clear();
316 316
317 file_util::ScopedFILE file(base::OpenFile(filename_, "rb")); 317 file_util::ScopedFILE file(file_util::OpenFile(filename_, "rb"));
318 if (file.get() == NULL) return false; 318 if (file.get() == NULL) return false;
319 319
320 FileHeader header; 320 FileHeader header;
321 if (!ReadAndVerifyHeader(filename_, file.get(), &header, NULL)) 321 if (!ReadAndVerifyHeader(filename_, file.get(), &header, NULL))
322 return OnCorruptDatabase(); 322 return OnCorruptDatabase();
323 323
324 size_t offset = 324 size_t offset =
325 header.add_chunk_count * sizeof(int32) + 325 header.add_chunk_count * sizeof(int32) +
326 header.sub_chunk_count * sizeof(int32) + 326 header.sub_chunk_count * sizeof(int32) +
327 header.add_prefix_count * sizeof(SBAddPrefix) + 327 header.add_prefix_count * sizeof(SBAddPrefix) +
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 DCHECK_EQ(chunks_written_, 0); 390 DCHECK_EQ(chunks_written_, 0);
391 391
392 // Since the following code will already hit the profile looking for 392 // Since the following code will already hit the profile looking for
393 // database files, this is a reasonable to time delete any old 393 // database files, this is a reasonable to time delete any old
394 // files. 394 // files.
395 CheckForOriginalAndDelete(filename_); 395 CheckForOriginalAndDelete(filename_);
396 396
397 corruption_seen_ = false; 397 corruption_seen_ = false;
398 398
399 const base::FilePath new_filename = TemporaryFileForFilename(filename_); 399 const base::FilePath new_filename = TemporaryFileForFilename(filename_);
400 file_util::ScopedFILE new_file(base::OpenFile(new_filename, "wb+")); 400 file_util::ScopedFILE new_file(file_util::OpenFile(new_filename, "wb+"));
401 if (new_file.get() == NULL) 401 if (new_file.get() == NULL)
402 return false; 402 return false;
403 403
404 file_util::ScopedFILE file(base::OpenFile(filename_, "rb")); 404 file_util::ScopedFILE file(file_util::OpenFile(filename_, "rb"));
405 empty_ = (file.get() == NULL); 405 empty_ = (file.get() == NULL);
406 if (empty_) { 406 if (empty_) {
407 // If the file exists but cannot be opened, try to delete it (not 407 // If the file exists but cannot be opened, try to delete it (not
408 // deleting directly, the bloom filter needs to be deleted, too). 408 // deleting directly, the bloom filter needs to be deleted, too).
409 if (base::PathExists(filename_)) 409 if (base::PathExists(filename_))
410 return OnCorruptDatabase(); 410 return OnCorruptDatabase();
411 411
412 new_file_.swap(new_file); 412 new_file_.swap(new_file);
413 return true; 413 return true;
414 } 414 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 !WriteContainer(sub_full_hashes, new_file_.get(), &context)) 637 !WriteContainer(sub_full_hashes, new_file_.get(), &context))
638 return false; 638 return false;
639 639
640 // Write the checksum at the end. 640 // Write the checksum at the end.
641 base::MD5Digest digest; 641 base::MD5Digest digest;
642 base::MD5Final(&digest, &context); 642 base::MD5Final(&digest, &context);
643 if (!WriteItem(digest, new_file_.get(), NULL)) 643 if (!WriteItem(digest, new_file_.get(), NULL))
644 return false; 644 return false;
645 645
646 // Trim any excess left over from the temporary chunk data. 646 // Trim any excess left over from the temporary chunk data.
647 if (!base::TruncateFile(new_file_.get())) 647 if (!file_util::TruncateFile(new_file_.get()))
648 return false; 648 return false;
649 649
650 // Close the file handle and swizzle the file into place. 650 // Close the file handle and swizzle the file into place.
651 new_file_.reset(); 651 new_file_.reset();
652 if (!base::DeleteFile(filename_, false) && 652 if (!base::DeleteFile(filename_, false) &&
653 base::PathExists(filename_)) 653 base::PathExists(filename_))
654 return false; 654 return false;
655 655
656 const base::FilePath new_filename = TemporaryFileForFilename(filename_); 656 const base::FilePath new_filename = TemporaryFileForFilename(filename_);
657 if (!base::Move(new_filename, filename_)) 657 if (!base::Move(new_filename, filename_))
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 // With SQLite support gone, one way to get to this code is if the 742 // With SQLite support gone, one way to get to this code is if the
743 // existing file is a SQLite file. Make sure the journal file is 743 // existing file is a SQLite file. Make sure the journal file is
744 // also removed. 744 // also removed.
745 const base::FilePath journal_filename( 745 const base::FilePath journal_filename(
746 basename.value() + FILE_PATH_LITERAL("-journal")); 746 basename.value() + FILE_PATH_LITERAL("-journal"));
747 if (base::PathExists(journal_filename)) 747 if (base::PathExists(journal_filename))
748 base::DeleteFile(journal_filename, false); 748 base::DeleteFile(journal_filename, false);
749 749
750 return true; 750 return true;
751 } 751 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698