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 "chrome/browser/visitedlink/visitedlink_master.h" | 5 #include "chrome/browser/visitedlink/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> |
11 #endif // defined(OS_WIN) | 11 #endif // defined(OS_WIN) |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
18 #include "base/containers/stack_container.h" | 18 #include "base/containers/stack_container.h" |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
24 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
26 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
27 #include "chrome/browser/visitedlink/visitedlink_delegate.h" | 27 #include "chrome/browser/history/history.h" |
| 28 #include "chrome/browser/history/history_service_factory.h" |
| 29 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" | 30 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" |
29 #include "content/public/browser/browser_context.h" | |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "googleurl/src/gurl.h" | |
32 | 32 |
33 using content::BrowserThread; | 33 using content::BrowserThread; |
34 using file_util::ScopedFILE; | 34 using file_util::ScopedFILE; |
35 using file_util::OpenFile; | 35 using file_util::OpenFile; |
36 using file_util::TruncateFile; | 36 using file_util::TruncateFile; |
37 | 37 |
38 const int32 VisitedLinkMaster::kFileHeaderSignatureOffset = 0; | 38 const int32 VisitedLinkMaster::kFileHeaderSignatureOffset = 0; |
39 const int32 VisitedLinkMaster::kFileHeaderVersionOffset = 4; | 39 const int32 VisitedLinkMaster::kFileHeaderVersionOffset = 4; |
40 const int32 VisitedLinkMaster::kFileHeaderLengthOffset = 8; | 40 const int32 VisitedLinkMaster::kFileHeaderLengthOffset = 8; |
41 const int32 VisitedLinkMaster::kFileHeaderUsedOffset = 12; | 41 const int32 VisitedLinkMaster::kFileHeaderUsedOffset = 12; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // The builder will store the fingerprints for those URLs, and then marshalls | 131 // The builder will store the fingerprints for those URLs, and then marshalls |
132 // back to the main thread where the VisitedLinkMaster will be notified. The | 132 // back to the main thread where the VisitedLinkMaster will be notified. The |
133 // master then replaces its table with a new table containing the computed | 133 // master then replaces its table with a new table containing the computed |
134 // fingerprints. | 134 // fingerprints. |
135 // | 135 // |
136 // The builder must remain active while the history system is using it. | 136 // The builder must remain active while the history system is using it. |
137 // Sometimes, the master will be deleted before the rebuild is complete, in | 137 // Sometimes, the master will be deleted before the rebuild is complete, in |
138 // which case it notifies the builder via DisownMaster(). The builder will | 138 // which case it notifies the builder via DisownMaster(). The builder will |
139 // delete itself once rebuilding is complete, and not execute any callback. | 139 // delete itself once rebuilding is complete, and not execute any callback. |
140 class VisitedLinkMaster::TableBuilder | 140 class VisitedLinkMaster::TableBuilder |
141 : public VisitedLinkDelegate::URLEnumerator, | 141 : public HistoryService::URLEnumerator, |
142 public base::RefCountedThreadSafe<TableBuilder> { | 142 public base::RefCountedThreadSafe<TableBuilder> { |
143 public: | 143 public: |
144 TableBuilder(VisitedLinkMaster* master, | 144 TableBuilder(VisitedLinkMaster* master, |
145 const uint8 salt[LINK_SALT_LENGTH]); | 145 const uint8 salt[LINK_SALT_LENGTH]); |
146 | 146 |
147 // Called on the main thread when the master is being destroyed. This will | 147 // Called on the main thread when the master is being destroyed. This will |
148 // prevent a crash when the query completes and the master is no longer | 148 // prevent a crash when the query completes and the master is no longer |
149 // around. We can not actually do anything but mark this fact, since the | 149 // around. We can not actually do anything but mark this fact, since the |
150 // table will be being rebuilt simultaneously on the other thread. | 150 // table will be being rebuilt simultaneously on the other thread. |
151 void DisownMaster(); | 151 void DisownMaster(); |
152 | 152 |
153 // VisitedLinkDelegate::URLEnumerator | 153 // HistoryService::URLEnumerator |
154 virtual void OnURL(const GURL& url); | 154 virtual void OnURL(const history::URLRow& url_row); |
155 virtual void OnComplete(bool succeed); | 155 virtual void OnComplete(bool succeed); |
156 | 156 |
157 private: | 157 private: |
158 friend class base::RefCountedThreadSafe<TableBuilder>; | 158 friend class base::RefCountedThreadSafe<TableBuilder>; |
159 | 159 |
160 ~TableBuilder() {} | 160 ~TableBuilder() {} |
161 | 161 |
162 // OnComplete mashals to this function on the main thread to do the | 162 // OnComplete mashals to this function on the main thread to do the |
163 // notification. | 163 // notification. |
164 void OnCompleteMainThread(); | 164 void OnCompleteMainThread(); |
165 | 165 |
166 // Owner of this object. MAY ONLY BE ACCESSED ON THE MAIN THREAD! | 166 // Owner of this object. MAY ONLY BE ACCESSED ON THE MAIN THREAD! |
167 VisitedLinkMaster* master_; | 167 VisitedLinkMaster* master_; |
168 | 168 |
169 // Indicates whether the operation has failed or not. | 169 // Indicates whether the operation has failed or not. |
170 bool success_; | 170 bool success_; |
171 | 171 |
172 // Salt for this new table. | 172 // Salt for this new table. |
173 uint8 salt_[LINK_SALT_LENGTH]; | 173 uint8 salt_[LINK_SALT_LENGTH]; |
174 | 174 |
175 // Stores the fingerprints we computed on the background thread. | 175 // Stores the fingerprints we computed on the background thread. |
176 VisitedLinkCommon::Fingerprints fingerprints_; | 176 VisitedLinkCommon::Fingerprints fingerprints_; |
177 | |
178 DISALLOW_COPY_AND_ASSIGN(TableBuilder); | |
179 }; | 177 }; |
180 | 178 |
181 // VisitedLinkMaster ---------------------------------------------------------- | 179 // VisitedLinkMaster ---------------------------------------------------------- |
182 | 180 |
183 VisitedLinkMaster::VisitedLinkMaster(content::BrowserContext* browser_context, | 181 VisitedLinkMaster::VisitedLinkMaster(Profile* profile) |
184 VisitedLinkDelegate* delegate) | 182 : profile_(profile) { |
185 : browser_context_(browser_context), | 183 listener_.reset(new VisitedLinkEventListener(profile)); |
186 delegate_(delegate), | 184 DCHECK(listener_.get()); |
187 listener_(new VisitedLinkEventListener( | |
188 ALLOW_THIS_IN_INITIALIZER_LIST(this), browser_context)) { | |
189 InitMembers(); | 185 InitMembers(); |
190 } | 186 } |
191 | 187 |
192 VisitedLinkMaster::VisitedLinkMaster(Listener* listener, | 188 VisitedLinkMaster::VisitedLinkMaster(Listener* listener, |
193 VisitedLinkDelegate* delegate, | 189 HistoryService* history_service, |
194 bool suppress_rebuild, | 190 bool suppress_rebuild, |
195 const FilePath& filename, | 191 const FilePath& filename, |
196 int32 default_table_size) | 192 int32 default_table_size) |
197 : browser_context_(NULL), | 193 : profile_(NULL) { |
198 delegate_(delegate) { | |
199 listener_.reset(listener); | 194 listener_.reset(listener); |
200 DCHECK(listener_.get()); | 195 DCHECK(listener_.get()); |
201 InitMembers(); | 196 InitMembers(); |
202 | 197 |
203 database_name_override_ = filename; | 198 database_name_override_ = filename; |
204 table_size_override_ = default_table_size; | 199 table_size_override_ = default_table_size; |
| 200 history_service_override_ = history_service; |
205 suppress_rebuild_ = suppress_rebuild; | 201 suppress_rebuild_ = suppress_rebuild; |
206 } | 202 } |
207 | 203 |
208 VisitedLinkMaster::~VisitedLinkMaster() { | 204 VisitedLinkMaster::~VisitedLinkMaster() { |
209 if (table_builder_.get()) { | 205 if (table_builder_.get()) { |
210 // Prevent the table builder from calling us back now that we're being | 206 // Prevent the table builder from calling us back now that we're being |
211 // destroyed. Note that we DON'T delete the object, since the history | 207 // destroyed. Note that we DON'T delete the object, since the history |
212 // system is still writing into it. When that is complete, the table | 208 // system is still writing into it. When that is complete, the table |
213 // builder will destroy itself when it finds we are gone. | 209 // builder will destroy itself when it finds we are gone. |
214 table_builder_->DisownMaster(); | 210 table_builder_->DisownMaster(); |
215 } | 211 } |
216 FreeURLTable(); | 212 FreeURLTable(); |
217 // FreeURLTable() will schedule closing of the file and deletion of |file_|. | 213 // FreeURLTable() will schedule closing of the file and deletion of |file_|. |
218 // So nothing should be done here. | 214 // So nothing should be done here. |
219 } | 215 } |
220 | 216 |
221 void VisitedLinkMaster::InitMembers() { | 217 void VisitedLinkMaster::InitMembers() { |
222 file_ = NULL; | 218 file_ = NULL; |
223 shared_memory_ = NULL; | 219 shared_memory_ = NULL; |
224 shared_memory_serial_ = 0; | 220 shared_memory_serial_ = 0; |
225 used_items_ = 0; | 221 used_items_ = 0; |
226 table_size_override_ = 0; | 222 table_size_override_ = 0; |
| 223 history_service_override_ = NULL; |
227 suppress_rebuild_ = false; | 224 suppress_rebuild_ = false; |
228 sequence_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); | 225 sequence_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); |
229 | 226 |
230 #ifndef NDEBUG | 227 #ifndef NDEBUG |
231 posted_asynchronous_operation_ = false; | 228 posted_asynchronous_operation_ = false; |
232 #endif | 229 #endif |
233 } | 230 } |
234 | 231 |
235 bool VisitedLinkMaster::Init() { | 232 bool VisitedLinkMaster::Init() { |
236 // We probably shouldn't be loading this from the UI thread, | 233 // We probably shouldn't be loading this from the UI thread, |
237 // but it does need to happen early on in startup. | 234 // but it does need to happen early on in startup. |
238 // http://code.google.com/p/chromium/issues/detail?id=24163 | 235 // http://code.google.com/p/chromium/issues/detail?id=24163 |
239 base::ThreadRestrictions::ScopedAllowIO allow_io; | 236 base::ThreadRestrictions::ScopedAllowIO allow_io; |
240 if (!InitFromFile()) | 237 if (!InitFromFile()) |
241 return InitFromScratch(suppress_rebuild_); | 238 return InitFromScratch(suppress_rebuild_); |
242 return true; | 239 return true; |
243 } | 240 } |
244 | 241 |
245 VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) { | 242 VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) { |
246 // Extra check that we are not incognito. This should not happen. | 243 // Extra check that we are not incognito. This should not happen. |
247 // TODO(boliu): Move this check to HistoryService when IsOffTheRecord is | 244 if (profile_ && profile_->IsOffTheRecord()) { |
248 // removed from BrowserContext. | |
249 if (browser_context_ && browser_context_->IsOffTheRecord()) { | |
250 NOTREACHED(); | 245 NOTREACHED(); |
251 return null_hash_; | 246 return null_hash_; |
252 } | 247 } |
253 | 248 |
254 if (!url.is_valid()) | 249 if (!url.is_valid()) |
255 return null_hash_; // Don't add invalid URLs. | 250 return null_hash_; // Don't add invalid URLs. |
256 | 251 |
257 Fingerprint fingerprint = ComputeURLFingerprint(url.spec().data(), | 252 Fingerprint fingerprint = ComputeURLFingerprint(url.spec().data(), |
258 url.spec().size(), | 253 url.spec().size(), |
259 salt_); | 254 salt_); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 memset(hash_table_, 0, this->table_length_ * sizeof(Fingerprint)); | 313 memset(hash_table_, 0, this->table_length_ * sizeof(Fingerprint)); |
319 | 314 |
320 // Resize it if it is now too empty. Resize may write the new table out for | 315 // Resize it if it is now too empty. Resize may write the new table out for |
321 // us, otherwise, schedule writing the new table to disk ourselves. | 316 // us, otherwise, schedule writing the new table to disk ourselves. |
322 if (!ResizeTableIfNecessary()) | 317 if (!ResizeTableIfNecessary()) |
323 WriteFullTable(); | 318 WriteFullTable(); |
324 | 319 |
325 listener_->Reset(); | 320 listener_->Reset(); |
326 } | 321 } |
327 | 322 |
328 VisitedLinkDelegate* VisitedLinkMaster::GetDelegate() { | 323 void VisitedLinkMaster::DeleteURLs(const history::URLRows& rows) { |
329 return delegate_; | 324 typedef std::set<GURL>::const_iterator SetIterator; |
330 } | |
331 | 325 |
332 void VisitedLinkMaster::DeleteURLs(URLIterator* urls) { | 326 if (rows.empty()) |
333 if (!urls->HasNextURL()) | |
334 return; | 327 return; |
335 | 328 |
336 listener_->Reset(); | 329 listener_->Reset(); |
337 | 330 |
338 if (table_builder_) { | 331 if (table_builder_) { |
339 // A rebuild is in progress, save this deletion in the temporary list so | 332 // A rebuild is in progress, save this deletion in the temporary list so |
340 // it can be added once rebuild is complete. | 333 // it can be added once rebuild is complete. |
341 while (urls->HasNextURL()) { | 334 for (history::URLRows::const_iterator i = rows.begin(); i != rows.end(); |
342 const GURL& url(urls->NextURL()); | 335 ++i) { |
| 336 const GURL& url(i->url()); |
343 if (!url.is_valid()) | 337 if (!url.is_valid()) |
344 continue; | 338 continue; |
345 | 339 |
346 Fingerprint fingerprint = | 340 Fingerprint fingerprint = |
347 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_); | 341 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_); |
348 deleted_since_rebuild_.insert(fingerprint); | 342 deleted_since_rebuild_.insert(fingerprint); |
349 | 343 |
350 // If the URL was just added and now we're deleting it, it may be in the | 344 // If the URL was just added and now we're deleting it, it may be in the |
351 // list of things added since the last rebuild. Delete it from that list. | 345 // list of things added since the last rebuild. Delete it from that list. |
352 std::set<Fingerprint>::iterator found = | 346 std::set<Fingerprint>::iterator found = |
353 added_since_rebuild_.find(fingerprint); | 347 added_since_rebuild_.find(fingerprint); |
354 if (found != added_since_rebuild_.end()) | 348 if (found != added_since_rebuild_.end()) |
355 added_since_rebuild_.erase(found); | 349 added_since_rebuild_.erase(found); |
356 | 350 |
357 // Delete the URLs from the in-memory table, but don't bother writing | 351 // Delete the URLs from the in-memory table, but don't bother writing |
358 // to disk since it will be replaced soon. | 352 // to disk since it will be replaced soon. |
359 DeleteFingerprint(fingerprint, false); | 353 DeleteFingerprint(fingerprint, false); |
360 } | 354 } |
361 return; | 355 return; |
362 } | 356 } |
363 | 357 |
364 // Compute the deleted URLs' fingerprints and delete them | 358 // Compute the deleted URLs' fingerprints and delete them |
365 std::set<Fingerprint> deleted_fingerprints; | 359 std::set<Fingerprint> deleted_fingerprints; |
366 while (urls->HasNextURL()) { | 360 for (history::URLRows::const_iterator i = rows.begin(); i != rows.end(); |
367 const GURL& url(urls->NextURL()); | 361 ++i) { |
| 362 const GURL& url(i->url()); |
368 if (!url.is_valid()) | 363 if (!url.is_valid()) |
369 continue; | 364 continue; |
370 deleted_fingerprints.insert( | 365 deleted_fingerprints.insert( |
371 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_)); | 366 ComputeURLFingerprint(url.spec().data(), url.spec().size(), salt_)); |
372 } | 367 } |
373 DeleteFingerprintsFromCurrentTable(deleted_fingerprints); | 368 DeleteFingerprintsFromCurrentTable(deleted_fingerprints); |
374 } | 369 } |
375 | 370 |
376 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm | 371 // See VisitedLinkCommon::IsVisited which should be in sync with this algorithm |
377 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint( | 372 VisitedLinkMaster::Hash VisitedLinkMaster::AddFingerprint( |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 // current empty table. | 574 // current empty table. |
580 WriteFullTable(); | 575 WriteFullTable(); |
581 return true; | 576 return true; |
582 } | 577 } |
583 | 578 |
584 // This will build the table from history. On the first run, history will | 579 // This will build the table from history. On the first run, history will |
585 // be empty, so this will be correct. This will also write the new table | 580 // be empty, so this will be correct. This will also write the new table |
586 // to disk. We don't want to save explicitly here, since the rebuild may | 581 // to disk. We don't want to save explicitly here, since the rebuild may |
587 // not complete, leaving us with an empty but valid visited link database. | 582 // not complete, leaving us with an empty but valid visited link database. |
588 // In the future, we won't know we need to try rebuilding again. | 583 // In the future, we won't know we need to try rebuilding again. |
589 return RebuildTableFromDelegate(); | 584 return RebuildTableFromHistory(); |
590 } | 585 } |
591 | 586 |
592 bool VisitedLinkMaster::ReadFileHeader(FILE* file, | 587 bool VisitedLinkMaster::ReadFileHeader(FILE* file, |
593 int32* num_entries, | 588 int32* num_entries, |
594 int32* used_count, | 589 int32* used_count, |
595 uint8 salt[LINK_SALT_LENGTH]) { | 590 uint8 salt[LINK_SALT_LENGTH]) { |
596 // Get file size. | 591 // Get file size. |
597 // Note that there is no need to seek back to the original location in the | 592 // Note that there is no need to seek back to the original location in the |
598 // file since ReadFromFile() [which is the next call accessing the file] | 593 // file since ReadFromFile() [which is the next call accessing the file] |
599 // seeks before reading. | 594 // seeks before reading. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 return true; | 634 return true; |
640 } | 635 } |
641 | 636 |
642 bool VisitedLinkMaster::GetDatabaseFileName(FilePath* filename) { | 637 bool VisitedLinkMaster::GetDatabaseFileName(FilePath* filename) { |
643 if (!database_name_override_.empty()) { | 638 if (!database_name_override_.empty()) { |
644 // use this filename, the directory must exist | 639 // use this filename, the directory must exist |
645 *filename = database_name_override_; | 640 *filename = database_name_override_; |
646 return true; | 641 return true; |
647 } | 642 } |
648 | 643 |
649 if (!browser_context_ || browser_context_->GetPath().empty()) | 644 if (!profile_ || profile_->GetPath().empty()) |
650 return false; | 645 return false; |
651 | 646 |
652 FilePath profile_dir = browser_context_->GetPath(); | 647 FilePath profile_dir = profile_->GetPath(); |
653 *filename = profile_dir.Append(FILE_PATH_LITERAL("Visited Links")); | 648 *filename = profile_dir.Append(FILE_PATH_LITERAL("Visited Links")); |
654 return true; | 649 return true; |
655 } | 650 } |
656 | 651 |
657 // Initializes the shared memory structure. The salt should already be filled | 652 // Initializes the shared memory structure. The salt should already be filled |
658 // in so that it can be written to the shared memory | 653 // in so that it can be written to the shared memory |
659 bool VisitedLinkMaster::CreateURLTable(int32 num_entries, bool init_to_empty) { | 654 bool VisitedLinkMaster::CreateURLTable(int32 num_entries, bool init_to_empty) { |
660 // The table is the size of the table followed by the entries. | 655 // The table is the size of the table followed by the entries. |
661 uint32 alloc_size = num_entries * sizeof(Fingerprint) + sizeof(SharedHeader); | 656 uint32 alloc_size = num_entries * sizeof(Fingerprint) + sizeof(SharedHeader); |
662 | 657 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 if (table_sizes[i] > desired) | 803 if (table_sizes[i] > desired) |
809 return table_sizes[i]; | 804 return table_sizes[i]; |
810 } | 805 } |
811 | 806 |
812 // Growing very big, just approximate a "good" number, not growing as much | 807 // Growing very big, just approximate a "good" number, not growing as much |
813 // as normal. | 808 // as normal. |
814 return item_count * 2 - 1; | 809 return item_count * 2 - 1; |
815 } | 810 } |
816 | 811 |
817 // See the TableBuilder definition in the header file for how this works. | 812 // See the TableBuilder definition in the header file for how this works. |
818 bool VisitedLinkMaster::RebuildTableFromDelegate() { | 813 bool VisitedLinkMaster::RebuildTableFromHistory() { |
819 DCHECK(!table_builder_); | 814 DCHECK(!table_builder_); |
| 815 if (table_builder_) |
| 816 return false; |
| 817 |
| 818 HistoryService* history_service = history_service_override_; |
| 819 if (!history_service && profile_) { |
| 820 history_service = |
| 821 HistoryServiceFactory::GetForProfile(profile_, |
| 822 Profile::EXPLICIT_ACCESS); |
| 823 } |
| 824 |
| 825 if (!history_service) { |
| 826 DLOG(WARNING) << "Attempted to rebuild visited link table, but couldn't " |
| 827 "obtain a HistoryService."; |
| 828 return false; |
| 829 } |
820 | 830 |
821 // TODO(brettw) make sure we have reasonable salt! | 831 // TODO(brettw) make sure we have reasonable salt! |
822 table_builder_ = new TableBuilder(this, salt_); | 832 table_builder_ = new TableBuilder(this, salt_); |
823 | 833 |
824 // Make sure the table builder stays live during the call, even if the | 834 // Make sure the table builder stays live during the call, even if the |
825 // master is deleted. This is balanced in TableBuilder::OnCompleteMainThread. | 835 // master is deleted. This is balanced in TableBuilder::OnCompleteMainThread. |
826 table_builder_->AddRef(); | 836 table_builder_->AddRef(); |
827 delegate_->RebuildTable(table_builder_); | 837 history_service->IterateURLs(table_builder_); |
828 return true; | 838 return true; |
829 } | 839 } |
830 | 840 |
831 // See the TableBuilder declaration above for how this works. | 841 // See the TableBuilder declaration above for how this works. |
832 void VisitedLinkMaster::OnTableRebuildComplete( | 842 void VisitedLinkMaster::OnTableRebuildComplete( |
833 bool success, | 843 bool success, |
834 const std::vector<Fingerprint>& fingerprints) { | 844 const std::vector<Fingerprint>& fingerprints) { |
835 if (success) { | 845 if (success) { |
836 // Replace the old table with a new blank one. | 846 // Replace the old table with a new blank one. |
837 shared_memory_serial_++; | 847 shared_memory_serial_++; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 fingerprints_.reserve(4096); | 951 fingerprints_.reserve(4096); |
942 memcpy(salt_, salt, LINK_SALT_LENGTH * sizeof(uint8)); | 952 memcpy(salt_, salt, LINK_SALT_LENGTH * sizeof(uint8)); |
943 } | 953 } |
944 | 954 |
945 // TODO(brettw): Do we want to try to cancel the request if this happens? It | 955 // TODO(brettw): Do we want to try to cancel the request if this happens? It |
946 // could delay shutdown if there are a lot of URLs. | 956 // could delay shutdown if there are a lot of URLs. |
947 void VisitedLinkMaster::TableBuilder::DisownMaster() { | 957 void VisitedLinkMaster::TableBuilder::DisownMaster() { |
948 master_ = NULL; | 958 master_ = NULL; |
949 } | 959 } |
950 | 960 |
951 void VisitedLinkMaster::TableBuilder::OnURL(const GURL& url) { | 961 void VisitedLinkMaster::TableBuilder::OnURL(const history::URLRow& url_row) { |
| 962 const GURL& url(url_row.url()); |
952 if (!url.is_empty()) { | 963 if (!url.is_empty()) { |
953 fingerprints_.push_back(VisitedLinkMaster::ComputeURLFingerprint( | 964 fingerprints_.push_back(VisitedLinkMaster::ComputeURLFingerprint( |
954 url.spec().data(), url.spec().length(), salt_)); | 965 url.spec().data(), url.spec().length(), salt_)); |
955 } | 966 } |
956 } | 967 } |
957 | 968 |
958 void VisitedLinkMaster::TableBuilder::OnComplete(bool success) { | 969 void VisitedLinkMaster::TableBuilder::OnComplete(bool success) { |
959 success_ = success; | 970 success_ = success; |
960 DLOG_IF(WARNING, !success) << "Unable to rebuild visited links"; | 971 DLOG_IF(WARNING, !success) << "Unable to rebuild visited links"; |
961 | 972 |
962 // Marshal to the main thread to notify the VisitedLinkMaster that the | 973 // Marshal to the main thread to notify the VisitedLinkMaster that the |
963 // rebuild is complete. | 974 // rebuild is complete. |
964 BrowserThread::PostTask( | 975 BrowserThread::PostTask( |
965 BrowserThread::UI, FROM_HERE, | 976 BrowserThread::UI, FROM_HERE, |
966 base::Bind(&TableBuilder::OnCompleteMainThread, this)); | 977 base::Bind(&TableBuilder::OnCompleteMainThread, this)); |
967 } | 978 } |
968 | 979 |
969 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { | 980 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { |
970 if (master_) | 981 if (master_) |
971 master_->OnTableRebuildComplete(success_, fingerprints_); | 982 master_->OnTableRebuildComplete(success_, fingerprints_); |
972 | 983 |
973 // WILL (generally) DELETE THIS! This balances the AddRef in | 984 // WILL (generally) DELETE THIS! This balances the AddRef in |
974 // VisitedLinkMaster::RebuildTableFromHistory. | 985 // VisitedLinkMaster::RebuildTableFromHistory. |
975 Release(); | 986 Release(); |
976 } | 987 } |
OLD | NEW |