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

Side by Side Diff: chrome/browser/visitedlink_master.cc

Issue 48005: Port visitedlink tests to Linux. Also make them pass on Linux, which (Closed)
Patch Set: GetInvalidHandle -> NULLHandle Created 11 years, 9 months 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
« no previous file with comments | « base/shared_memory_win.cc ('k') | chrome/browser/visitedlink_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/visitedlink_master.h" 5 #include "chrome/browser/visitedlink_master.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <io.h> 9 #include <io.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 // Allocate and read the table. 575 // Allocate and read the table.
576 if (!CreateURLTable(num_entries, false)) 576 if (!CreateURLTable(num_entries, false))
577 return false; 577 return false;
578 if (!ReadFromFile(file_closer.get(), kFileHeaderSize, 578 if (!ReadFromFile(file_closer.get(), kFileHeaderSize,
579 hash_table_, num_entries * sizeof(Fingerprint))) { 579 hash_table_, num_entries * sizeof(Fingerprint))) {
580 FreeURLTable(); 580 FreeURLTable();
581 return false; 581 return false;
582 } 582 }
583 used_items_ = used_count; 583 used_items_ = used_count;
584 584
585 #ifndef NDEBUG
586 DebugValidate();
587 #endif
588
585 file_ = file_closer.release(); 589 file_ = file_closer.release();
586 return true; 590 return true;
587 } 591 }
588 592
589 bool VisitedLinkMaster::InitFromScratch(bool suppress_rebuild) { 593 bool VisitedLinkMaster::InitFromScratch(bool suppress_rebuild) {
590 int32 table_size = kDefaultTableSize; 594 int32 table_size = kDefaultTableSize;
591 if (table_size_override_) 595 if (table_size_override_)
592 table_size = table_size_override_; 596 table_size = table_size_override_;
593 597
594 // The salt must be generated before the table so that it can be copied to 598 // The salt must be generated before the table so that it can be copied to
595 // the shared memory. 599 // the shared memory.
596 GenerateSalt(salt_); 600 GenerateSalt(salt_);
597 if (!CreateURLTable(table_size, true)) 601 if (!CreateURLTable(table_size, true))
598 return false; 602 return false;
599 603
604 #ifndef NDEBUG
605 DebugValidate();
606 #endif
607
600 if (suppress_rebuild) { 608 if (suppress_rebuild) {
601 // When we disallow rebuilds (normally just unit tests), just use the 609 // When we disallow rebuilds (normally just unit tests), just use the
602 // current empty table. 610 // current empty table.
603 return WriteFullTable(); 611 return WriteFullTable();
604 } 612 }
605 613
606 // This will build the table from history. On the first run, history will 614 // This will build the table from history. On the first run, history will
607 // be empty, so this will be correct. This will also write the new table 615 // be empty, so this will be correct. This will also write the new table
608 // to disk. We don't want to save explicitly here, since the rebuild may 616 // to disk. We don't want to save explicitly here, since the rebuild may
609 // not complete, leaving us with an empty but valid visited link database. 617 // not complete, leaving us with an empty but valid visited link database.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 714
707 // Save the header for other processes to read. 715 // Save the header for other processes to read.
708 SharedHeader* header = static_cast<SharedHeader*>(shared_memory_->memory()); 716 SharedHeader* header = static_cast<SharedHeader*>(shared_memory_->memory());
709 header->length = table_length_; 717 header->length = table_length_;
710 memcpy(header->salt, salt_, LINK_SALT_LENGTH); 718 memcpy(header->salt, salt_, LINK_SALT_LENGTH);
711 719
712 // Our table pointer is just the data immediately following the size. 720 // Our table pointer is just the data immediately following the size.
713 hash_table_ = reinterpret_cast<Fingerprint*>( 721 hash_table_ = reinterpret_cast<Fingerprint*>(
714 static_cast<char*>(shared_memory_->memory()) + sizeof(SharedHeader)); 722 static_cast<char*>(shared_memory_->memory()) + sizeof(SharedHeader));
715 723
716 #ifndef NDEBUG
717 DebugValidate();
718 #endif
719
720 return true; 724 return true;
721 } 725 }
722 726
723 bool VisitedLinkMaster::BeginReplaceURLTable(int32 num_entries) { 727 bool VisitedLinkMaster::BeginReplaceURLTable(int32 num_entries) {
724 base::SharedMemory *old_shared_memory = shared_memory_; 728 base::SharedMemory *old_shared_memory = shared_memory_;
725 Fingerprint* old_hash_table = hash_table_; 729 Fingerprint* old_hash_table = hash_table_;
726 int32 old_table_length = table_length_; 730 int32 old_table_length = table_length_;
727 if (!CreateURLTable(num_entries, true)) { 731 if (!CreateURLTable(num_entries, true)) {
728 // Try to put back the old state. 732 // Try to put back the old state.
729 shared_memory_ = old_shared_memory; 733 shared_memory_ = old_shared_memory;
730 hash_table_ = old_hash_table; 734 hash_table_ = old_hash_table;
731 table_length_ = old_table_length; 735 table_length_ = old_table_length;
732 return false; 736 return false;
733 } 737 }
738
739 #ifndef NDEBUG
740 DebugValidate();
741 #endif
742
734 return true; 743 return true;
735 } 744 }
736 745
737 void VisitedLinkMaster::FreeURLTable() { 746 void VisitedLinkMaster::FreeURLTable() {
738 if (shared_memory_) { 747 if (shared_memory_) {
739 delete shared_memory_; 748 delete shared_memory_;
740 shared_memory_ = NULL; 749 shared_memory_ = NULL;
741 } 750 }
742 if (file_) { 751 if (file_) {
743 if (file_thread_) { 752 if (file_thread_) {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 } 1024 }
1016 1025
1017 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { 1026 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() {
1018 if (master_) 1027 if (master_)
1019 master_->OnTableRebuildComplete(success_, fingerprints_); 1028 master_->OnTableRebuildComplete(success_, fingerprints_);
1020 1029
1021 // WILL (generally) DELETE THIS! This balances the AddRef in 1030 // WILL (generally) DELETE THIS! This balances the AddRef in
1022 // VisitedLinkMaster::RebuildTableFromHistory. 1031 // VisitedLinkMaster::RebuildTableFromHistory.
1023 Release(); 1032 Release();
1024 } 1033 }
OLDNEW
« no previous file with comments | « base/shared_memory_win.cc ('k') | chrome/browser/visitedlink_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698