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 #include "components/visitedlink/browser/visitedlink_master.h" | 5 #include "components/visitedlink/browser/visitedlink_master.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | |
10 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/containers/stack_container.h" | 14 #include "base/containers/stack_container.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/files/scoped_file.h" | 16 #include "base/files/scoped_file.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 DISALLOW_COPY_AND_ASSIGN(LoadFromFileResult); | 143 DISALLOW_COPY_AND_ASSIGN(LoadFromFileResult); |
144 }; | 144 }; |
145 | 145 |
146 VisitedLinkMaster::LoadFromFileResult::LoadFromFileResult( | 146 VisitedLinkMaster::LoadFromFileResult::LoadFromFileResult( |
147 base::ScopedFILE file, | 147 base::ScopedFILE file, |
148 scoped_ptr<base::SharedMemory> shared_memory, | 148 scoped_ptr<base::SharedMemory> shared_memory, |
149 Fingerprint* hash_table, | 149 Fingerprint* hash_table, |
150 int32_t num_entries, | 150 int32_t num_entries, |
151 int32_t used_count, | 151 int32_t used_count, |
152 uint8_t salt[LINK_SALT_LENGTH]) | 152 uint8_t salt[LINK_SALT_LENGTH]) |
153 : file(file.Pass()), | 153 : file(std::move(file)), |
154 shared_memory(shared_memory.Pass()), | 154 shared_memory(std::move(shared_memory)), |
155 hash_table(hash_table), | 155 hash_table(hash_table), |
156 num_entries(num_entries), | 156 num_entries(num_entries), |
157 used_count(used_count) { | 157 used_count(used_count) { |
158 memcpy(this->salt, salt, LINK_SALT_LENGTH); | 158 memcpy(this->salt, salt, LINK_SALT_LENGTH); |
159 } | 159 } |
160 | 160 |
161 VisitedLinkMaster::LoadFromFileResult::~LoadFromFileResult() { | 161 VisitedLinkMaster::LoadFromFileResult::~LoadFromFileResult() { |
162 } | 162 } |
163 | 163 |
164 // TableBuilder --------------------------------------------------------------- | 164 // TableBuilder --------------------------------------------------------------- |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 scoped_ptr<base::SharedMemory> shared_memory; | 665 scoped_ptr<base::SharedMemory> shared_memory; |
666 VisitedLinkCommon::Fingerprint* hash_table; | 666 VisitedLinkCommon::Fingerprint* hash_table; |
667 if (!CreateApartURLTable(num_entries, salt, &shared_memory, &hash_table)) | 667 if (!CreateApartURLTable(num_entries, salt, &shared_memory, &hash_table)) |
668 return false; | 668 return false; |
669 | 669 |
670 if (!ReadFromFile(file_closer.get(), kFileHeaderSize, hash_table, | 670 if (!ReadFromFile(file_closer.get(), kFileHeaderSize, hash_table, |
671 num_entries * sizeof(Fingerprint))) { | 671 num_entries * sizeof(Fingerprint))) { |
672 return false; | 672 return false; |
673 } | 673 } |
674 | 674 |
675 *load_from_file_result = new LoadFromFileResult(file_closer.Pass(), | 675 *load_from_file_result = |
676 shared_memory.Pass(), | 676 new LoadFromFileResult(std::move(file_closer), std::move(shared_memory), |
677 hash_table, | 677 hash_table, num_entries, used_count, salt); |
678 num_entries, | |
679 used_count, | |
680 salt); | |
681 return true; | 678 return true; |
682 } | 679 } |
683 | 680 |
684 void VisitedLinkMaster::OnTableLoadComplete( | 681 void VisitedLinkMaster::OnTableLoadComplete( |
685 bool success, | 682 bool success, |
686 scoped_refptr<LoadFromFileResult> load_from_file_result) { | 683 scoped_refptr<LoadFromFileResult> load_from_file_result) { |
687 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 684 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
688 DCHECK(persist_to_disk_); | 685 DCHECK(persist_to_disk_); |
689 DCHECK(!table_builder_.get()); | 686 DCHECK(!table_builder_.get()); |
690 | 687 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 | 902 |
906 // Save the header for other processes to read. | 903 // Save the header for other processes to read. |
907 SharedHeader* header = static_cast<SharedHeader*>(sh_mem->memory()); | 904 SharedHeader* header = static_cast<SharedHeader*>(sh_mem->memory()); |
908 header->length = num_entries; | 905 header->length = num_entries; |
909 memcpy(header->salt, salt, LINK_SALT_LENGTH); | 906 memcpy(header->salt, salt, LINK_SALT_LENGTH); |
910 | 907 |
911 // Our table pointer is just the data immediately following the size. | 908 // Our table pointer is just the data immediately following the size. |
912 *hash_table = reinterpret_cast<Fingerprint*>( | 909 *hash_table = reinterpret_cast<Fingerprint*>( |
913 static_cast<char*>(sh_mem->memory()) + sizeof(SharedHeader)); | 910 static_cast<char*>(sh_mem->memory()) + sizeof(SharedHeader)); |
914 | 911 |
915 *shared_memory = sh_mem.Pass(); | 912 *shared_memory = std::move(sh_mem); |
916 | 913 |
917 return true; | 914 return true; |
918 } | 915 } |
919 | 916 |
920 bool VisitedLinkMaster::BeginReplaceURLTable(int32_t num_entries) { | 917 bool VisitedLinkMaster::BeginReplaceURLTable(int32_t num_entries) { |
921 base::SharedMemory *old_shared_memory = shared_memory_; | 918 base::SharedMemory *old_shared_memory = shared_memory_; |
922 Fingerprint* old_hash_table = hash_table_; | 919 Fingerprint* old_hash_table = hash_table_; |
923 int32_t old_table_length = table_length_; | 920 int32_t old_table_length = table_length_; |
924 if (!CreateURLTable(num_entries)) { | 921 if (!CreateURLTable(num_entries)) { |
925 // Try to put back the old state. | 922 // Try to put back the old state. |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 BrowserThread::UI, FROM_HERE, | 1195 BrowserThread::UI, FROM_HERE, |
1199 base::Bind(&TableBuilder::OnCompleteMainThread, this)); | 1196 base::Bind(&TableBuilder::OnCompleteMainThread, this)); |
1200 } | 1197 } |
1201 | 1198 |
1202 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 1199 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
1203 if (master_) | 1200 if (master_) |
1204 master_->OnTableRebuildComplete(success_, fingerprints_); | 1201 master_->OnTableRebuildComplete(success_, fingerprints_); |
1205 } | 1202 } |
1206 | 1203 |
1207 } // namespace visitedlink | 1204 } // namespace visitedlink |
OLD | NEW |