OLD | NEW |
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 #include <windows.h> | 7 #include <windows.h> |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 GetCurrentProcessId(), shared_memory_serial_, | 251 GetCurrentProcessId(), shared_memory_serial_, |
252 profile_id.c_str()); | 252 profile_id.c_str()); |
253 } | 253 } |
254 | 254 |
255 bool VisitedLinkMaster::Init() { | 255 bool VisitedLinkMaster::Init() { |
256 if (!InitFromFile()) | 256 if (!InitFromFile()) |
257 return InitFromScratch(suppress_rebuild_); | 257 return InitFromScratch(suppress_rebuild_); |
258 return true; | 258 return true; |
259 } | 259 } |
260 | 260 |
261 bool VisitedLinkMaster::ShareToProcess(ProcessHandle process, | 261 bool VisitedLinkMaster::ShareToProcess(base::ProcessHandle process, |
262 SharedMemoryHandle *new_handle) { | 262 base::SharedMemoryHandle *new_handle) { |
263 if (shared_memory_) | 263 if (shared_memory_) |
264 return shared_memory_->ShareToProcess(process, new_handle); | 264 return shared_memory_->ShareToProcess(process, new_handle); |
265 | 265 |
266 NOTREACHED(); | 266 NOTREACHED(); |
267 return false; | 267 return false; |
268 } | 268 } |
269 | 269 |
270 SharedMemoryHandle VisitedLinkMaster::GetSharedMemoryHandle() { | 270 base::SharedMemoryHandle VisitedLinkMaster::GetSharedMemoryHandle() { |
271 return shared_memory_->handle(); | 271 return shared_memory_->handle(); |
272 } | 272 } |
273 | 273 |
274 VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) { | 274 VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) { |
275 // Extra check that we are not off the record. This should not happen. | 275 // Extra check that we are not off the record. This should not happen. |
276 if (profile_ && profile_->IsOffTheRecord()) { | 276 if (profile_ && profile_->IsOffTheRecord()) { |
277 NOTREACHED(); | 277 NOTREACHED(); |
278 return null_hash_; | 278 return null_hash_; |
279 } | 279 } |
280 | 280 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 return true; | 667 return true; |
668 } | 668 } |
669 | 669 |
670 // Initializes the shared memory structure. The salt should already be filled | 670 // Initializes the shared memory structure. The salt should already be filled |
671 // in so that it can be written to the shared memory | 671 // in so that it can be written to the shared memory |
672 bool VisitedLinkMaster::CreateURLTable(int32 num_entries, bool init_to_empty) { | 672 bool VisitedLinkMaster::CreateURLTable(int32 num_entries, bool init_to_empty) { |
673 // The table is the size of the table followed by the entries. | 673 // The table is the size of the table followed by the entries. |
674 int32 alloc_size = num_entries * sizeof(Fingerprint) + sizeof(SharedHeader); | 674 int32 alloc_size = num_entries * sizeof(Fingerprint) + sizeof(SharedHeader); |
675 | 675 |
676 // Create the shared memory object. | 676 // Create the shared memory object. |
677 shared_memory_ = new SharedMemory(); | 677 shared_memory_ = new base::SharedMemory(); |
678 if (!shared_memory_) | 678 if (!shared_memory_) |
679 return false; | 679 return false; |
680 | 680 |
681 if (!shared_memory_->Create(GetSharedMemoryName().c_str(), | 681 if (!shared_memory_->Create(GetSharedMemoryName().c_str(), |
682 false, false, alloc_size)) | 682 false, false, alloc_size)) |
683 return false; | 683 return false; |
684 | 684 |
685 // Map into our process. | 685 // Map into our process. |
686 if (!shared_memory_->Map(alloc_size)) { | 686 if (!shared_memory_->Map(alloc_size)) { |
687 delete shared_memory_; | 687 delete shared_memory_; |
(...skipping 17 matching lines...) Expand all Loading... |
705 static_cast<char*>(shared_memory_->memory()) + sizeof(SharedHeader)); | 705 static_cast<char*>(shared_memory_->memory()) + sizeof(SharedHeader)); |
706 | 706 |
707 #ifndef NDEBUG | 707 #ifndef NDEBUG |
708 DebugValidate(); | 708 DebugValidate(); |
709 #endif | 709 #endif |
710 | 710 |
711 return true; | 711 return true; |
712 } | 712 } |
713 | 713 |
714 bool VisitedLinkMaster::BeginReplaceURLTable(int32 num_entries) { | 714 bool VisitedLinkMaster::BeginReplaceURLTable(int32 num_entries) { |
715 SharedMemory *old_shared_memory = shared_memory_; | 715 base::SharedMemory *old_shared_memory = shared_memory_; |
716 Fingerprint* old_hash_table = hash_table_; | 716 Fingerprint* old_hash_table = hash_table_; |
717 int32 old_table_length = table_length_; | 717 int32 old_table_length = table_length_; |
718 if (!CreateURLTable(num_entries, true)) { | 718 if (!CreateURLTable(num_entries, true)) { |
719 // Try to put back the old state. | 719 // Try to put back the old state. |
720 shared_memory_ = old_shared_memory; | 720 shared_memory_ = old_shared_memory; |
721 hash_table_ = old_hash_table; | 721 hash_table_ = old_hash_table; |
722 table_length_ = old_table_length; | 722 table_length_ = old_table_length; |
723 return false; | 723 return false; |
724 } | 724 } |
725 return true; | 725 return true; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 764 } |
765 | 765 |
766 void VisitedLinkMaster::ResizeTable(int32 new_size) { | 766 void VisitedLinkMaster::ResizeTable(int32 new_size) { |
767 DCHECK(shared_memory_ && shared_memory_->memory() && hash_table_); | 767 DCHECK(shared_memory_ && shared_memory_->memory() && hash_table_); |
768 shared_memory_serial_++; | 768 shared_memory_serial_++; |
769 | 769 |
770 #ifndef NDEBUG | 770 #ifndef NDEBUG |
771 DebugValidate(); | 771 DebugValidate(); |
772 #endif | 772 #endif |
773 | 773 |
774 SharedMemory* old_shared_memory = shared_memory_; | 774 base::SharedMemory* old_shared_memory = shared_memory_; |
775 Fingerprint* old_hash_table = hash_table_; | 775 Fingerprint* old_hash_table = hash_table_; |
776 int32 old_table_length = table_length_; | 776 int32 old_table_length = table_length_; |
777 if (!BeginReplaceURLTable(new_size)) | 777 if (!BeginReplaceURLTable(new_size)) |
778 return; | 778 return; |
779 | 779 |
780 // Now we have two tables, our local copy which is the old one, and the new | 780 // Now we have two tables, our local copy which is the old one, and the new |
781 // one loaded into this object where we need to copy the data. | 781 // one loaded into this object where we need to copy the data. |
782 for (int32 i = 0; i < old_table_length; i++) { | 782 for (int32 i = 0; i < old_table_length; i++) { |
783 Fingerprint cur = old_hash_table[i]; | 783 Fingerprint cur = old_hash_table[i]; |
784 if (cur) | 784 if (cur) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 // See the TableBuilder definition in the header file for how this works. | 863 // See the TableBuilder definition in the header file for how this works. |
864 void VisitedLinkMaster::OnTableRebuildComplete( | 864 void VisitedLinkMaster::OnTableRebuildComplete( |
865 bool success, | 865 bool success, |
866 const std::vector<Fingerprint>& fingerprints) { | 866 const std::vector<Fingerprint>& fingerprints) { |
867 if (success) { | 867 if (success) { |
868 // Replace the old table with a new blank one. | 868 // Replace the old table with a new blank one. |
869 shared_memory_serial_++; | 869 shared_memory_serial_++; |
870 | 870 |
871 // We are responsible for freeing it AFTER it has been replaced if | 871 // We are responsible for freeing it AFTER it has been replaced if |
872 // replacement succeeds. | 872 // replacement succeeds. |
873 SharedMemory* old_shared_memory = shared_memory_; | 873 base::SharedMemory* old_shared_memory = shared_memory_; |
874 | 874 |
875 int new_table_size = NewTableSizeForCount( | 875 int new_table_size = NewTableSizeForCount( |
876 static_cast<int>(fingerprints.size())); | 876 static_cast<int>(fingerprints.size())); |
877 if (BeginReplaceURLTable(new_table_size)) { | 877 if (BeginReplaceURLTable(new_table_size)) { |
878 // Free the old table. | 878 // Free the old table. |
879 delete old_shared_memory; | 879 delete old_shared_memory; |
880 | 880 |
881 // Add the stored fingerprints to the hash table. | 881 // Add the stored fingerprints to the hash table. |
882 for (size_t i = 0; i < fingerprints.size(); i++) | 882 for (size_t i = 0; i < fingerprints.size(); i++) |
883 AddFingerprint(fingerprints[i]); | 883 AddFingerprint(fingerprints[i]); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 } | 1002 } |
1003 | 1003 |
1004 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 1004 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
1005 if (master_) | 1005 if (master_) |
1006 master_->OnTableRebuildComplete(success_, fingerprints_); | 1006 master_->OnTableRebuildComplete(success_, fingerprints_); |
1007 | 1007 |
1008 // WILL (generally) DELETE THIS! This balances the AddRef in | 1008 // WILL (generally) DELETE THIS! This balances the AddRef in |
1009 // VisitedLinkMaster::RebuildTableFromHistory. | 1009 // VisitedLinkMaster::RebuildTableFromHistory. |
1010 Release(); | 1010 Release(); |
1011 } | 1011 } |
OLD | NEW |