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

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

Issue 9122022: Revert 116816 - Hook up the SequencedWorkerPool to the browser thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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
« no previous file with comments | « chrome/browser/visitedlink/visitedlink_master.h ('k') | content/browser/browser_main_loop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 184
185 listener_ = listener; 185 listener_ = listener;
186 file_ = NULL; 186 file_ = NULL;
187 shared_memory_ = NULL; 187 shared_memory_ = NULL;
188 shared_memory_serial_ = 0; 188 shared_memory_serial_ = 0;
189 used_items_ = 0; 189 used_items_ = 0;
190 table_size_override_ = 0; 190 table_size_override_ = 0;
191 history_service_override_ = NULL; 191 history_service_override_ = NULL;
192 suppress_rebuild_ = false; 192 suppress_rebuild_ = false;
193 profile_ = profile; 193 profile_ = profile;
194 sequence_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken();
195 194
196 #ifndef NDEBUG 195 #ifndef NDEBUG
197 posted_asynchronous_operation_ = false; 196 posted_asynchronous_operation_ = false;
198 #endif 197 #endif
199 } 198 }
200 199
201 bool VisitedLinkMaster::Init() { 200 bool VisitedLinkMaster::Init() {
202 // We probably shouldn't be loading this from the UI thread, 201 // We probably shouldn't be loading this from the UI thread,
203 // but it does need to happen early on in startup. 202 // but it does need to happen early on in startup.
204 // http://code.google.com/p/chromium/issues/detail?id=24163 203 // http://code.google.com/p/chromium/issues/detail?id=24163
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // If the table is "full", we don't add URLs and just drop them on the floor. 235 // If the table is "full", we don't add URLs and just drop them on the floor.
237 // This can happen if we get thousands of new URLs and something causes 236 // This can happen if we get thousands of new URLs and something causes
238 // the table resizing to fail. This check prevents a hang in that case. Note 237 // the table resizing to fail. This check prevents a hang in that case. Note
239 // that this is *not* the resize limit, this is just a sanity check. 238 // that this is *not* the resize limit, this is just a sanity check.
240 if (used_items_ / 8 > table_length_ / 10) 239 if (used_items_ / 8 > table_length_ / 10)
241 return null_hash_; // Table is more than 80% full. 240 return null_hash_; // Table is more than 80% full.
242 241
243 return AddFingerprint(fingerprint, true); 242 return AddFingerprint(fingerprint, true);
244 } 243 }
245 244
246 void VisitedLinkMaster::PostIOTask(const tracked_objects::Location& from_here,
247 const base::Closure& task) {
248 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask(sequence_token_,
249 from_here, task);
250 }
251
252 void VisitedLinkMaster::AddURL(const GURL& url) { 245 void VisitedLinkMaster::AddURL(const GURL& url) {
253 Hash index = TryToAddURL(url); 246 Hash index = TryToAddURL(url);
254 if (!table_builder_ && index != null_hash_) { 247 if (!table_builder_ && index != null_hash_) {
255 // Not rebuilding, so we want to keep the file on disk up-to-date. 248 // Not rebuilding, so we want to keep the file on disk up-to-date.
256 WriteUsedItemCountToFile(); 249 WriteUsedItemCountToFile();
257 WriteHashRangeToFile(index, index); 250 WriteHashRangeToFile(index, index);
258 ResizeTableIfNecessary(); 251 ResizeTableIfNecessary();
259 } 252 }
260 } 253 }
261 254
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 header[2] = table_length_; 473 header[2] = table_length_;
481 header[3] = used_items_; 474 header[3] = used_items_;
482 WriteToFile(file_, 0, header, sizeof(header)); 475 WriteToFile(file_, 0, header, sizeof(header));
483 WriteToFile(file_, sizeof(header), salt_, LINK_SALT_LENGTH); 476 WriteToFile(file_, sizeof(header), salt_, LINK_SALT_LENGTH);
484 477
485 // Write the hash data. 478 // Write the hash data.
486 WriteToFile(file_, kFileHeaderSize, 479 WriteToFile(file_, kFileHeaderSize,
487 hash_table_, table_length_ * sizeof(Fingerprint)); 480 hash_table_, table_length_ * sizeof(Fingerprint));
488 481
489 // The hash table may have shrunk, so make sure this is the end. 482 // The hash table may have shrunk, so make sure this is the end.
490 PostIOTask(FROM_HERE, base::Bind(base::IgnoreResult(&TruncateFile), file_)); 483 BrowserThread::PostTask(
484 BrowserThread::FILE,
485 FROM_HERE,
486 base::Bind(base::IgnoreResult(&TruncateFile), file_));
491 return true; 487 return true;
492 } 488 }
493 489
494 bool VisitedLinkMaster::InitFromFile() { 490 bool VisitedLinkMaster::InitFromFile() {
495 DCHECK(file_ == NULL); 491 DCHECK(file_ == NULL);
496 492
497 FilePath filename; 493 FilePath filename;
498 GetDatabaseFileName(&filename); 494 GetDatabaseFileName(&filename);
499 ScopedFILE file_closer(OpenFile(filename, "rb+")); 495 ScopedFILE file_closer(OpenFile(filename, "rb+"));
500 if (!file_closer.get()) 496 if (!file_closer.get())
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 return true; 666 return true;
671 } 667 }
672 668
673 void VisitedLinkMaster::FreeURLTable() { 669 void VisitedLinkMaster::FreeURLTable() {
674 if (shared_memory_) { 670 if (shared_memory_) {
675 delete shared_memory_; 671 delete shared_memory_;
676 shared_memory_ = NULL; 672 shared_memory_ = NULL;
677 } 673 }
678 if (!file_) 674 if (!file_)
679 return; 675 return;
680 PostIOTask(FROM_HERE, base::Bind(base::IgnoreResult(&fclose), file_)); 676
677 BrowserThread::PostTask(
678 BrowserThread::FILE,
679 FROM_HERE,
680 base::Bind(base::IgnoreResult(&fclose), file_));
681 } 681 }
682 682
683 bool VisitedLinkMaster::ResizeTableIfNecessary() { 683 bool VisitedLinkMaster::ResizeTableIfNecessary() {
684 DCHECK(table_length_ > 0) << "Must have a table"; 684 DCHECK(table_length_ > 0) << "Must have a table";
685 685
686 // Load limits for good performance/space. We are pretty conservative about 686 // Load limits for good performance/space. We are pretty conservative about
687 // keeping the table not very full. This is because we use linear probing 687 // keeping the table not very full. This is because we use linear probing
688 // which increases the likelihood of clumps of entries which will reduce 688 // which increases the likelihood of clumps of entries which will reduce
689 // performance. 689 // performance.
690 const float max_table_load = 0.5f; // Grow when we're > this full. 690 const float max_table_load = 0.5f; // Grow when we're > this full.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 } 853 }
854 } 854 }
855 855
856 void VisitedLinkMaster::WriteToFile(FILE* file, 856 void VisitedLinkMaster::WriteToFile(FILE* file,
857 off_t offset, 857 off_t offset,
858 void* data, 858 void* data,
859 int32 data_size) { 859 int32 data_size) {
860 #ifndef NDEBUG 860 #ifndef NDEBUG
861 posted_asynchronous_operation_ = true; 861 posted_asynchronous_operation_ = true;
862 #endif 862 #endif
863 PostIOTask(FROM_HERE, 863
864 BrowserThread::PostTask(
865 BrowserThread::FILE, FROM_HERE,
864 base::Bind(&AsyncWrite, file, offset, 866 base::Bind(&AsyncWrite, file, offset,
865 std::string(static_cast<const char*>(data), data_size))); 867 std::string(static_cast<const char*>(data), data_size)));
866 } 868 }
867 869
868 void VisitedLinkMaster::WriteUsedItemCountToFile() { 870 void VisitedLinkMaster::WriteUsedItemCountToFile() {
869 if (!file_) 871 if (!file_)
870 return; // See comment on the file_ variable for why this might happen. 872 return; // See comment on the file_ variable for why this might happen.
871 WriteToFile(file_, kFileHeaderUsedOffset, &used_items_, sizeof(used_items_)); 873 WriteToFile(file_, kFileHeaderUsedOffset, &used_items_, sizeof(used_items_));
872 } 874 }
873 875
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 } 946 }
945 947
946 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() { 948 void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() {
947 if (master_) 949 if (master_)
948 master_->OnTableRebuildComplete(success_, fingerprints_); 950 master_->OnTableRebuildComplete(success_, fingerprints_);
949 951
950 // WILL (generally) DELETE THIS! This balances the AddRef in 952 // WILL (generally) DELETE THIS! This balances the AddRef in
951 // VisitedLinkMaster::RebuildTableFromHistory. 953 // VisitedLinkMaster::RebuildTableFromHistory.
952 Release(); 954 Release();
953 } 955 }
OLDNEW
« no previous file with comments | « chrome/browser/visitedlink/visitedlink_master.h ('k') | content/browser/browser_main_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698