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

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

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

Powered by Google App Engine
This is Rietveld 408576698