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

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

Powered by Google App Engine
This is Rietveld 408576698