| Index: chrome/browser/custom_home_pages_table_model.cc
|
| diff --git a/chrome/browser/custom_home_pages_table_model.cc b/chrome/browser/custom_home_pages_table_model.cc
|
| index 95b25af4409ce3f2d38b600b348fc0ea79e7c05c..ba5ad19336da8a373fc0115e7c238d40885b4eb3 100644
|
| --- a/chrome/browser/custom_home_pages_table_model.cc
|
| +++ b/chrome/browser/custom_home_pages_table_model.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/i18n/rtl.h"
|
| #include "base/prefs/pref_service.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/history/history_service.h"
|
| #include "chrome/browser/history/history_service_factory.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| @@ -55,7 +56,7 @@ bool ShouldAddPage(const GURL& url) {
|
| } // namespace
|
|
|
| struct CustomHomePagesTableModel::Entry {
|
| - Entry() : title_handle(0) {}
|
| + Entry() : task_id(base::CancelableTaskTracker::kBadTaskId) {}
|
|
|
| // URL of the page.
|
| GURL url;
|
| @@ -63,8 +64,9 @@ struct CustomHomePagesTableModel::Entry {
|
| // Page title. If this is empty, we'll display the URL as the entry.
|
| base::string16 title;
|
|
|
| - // If non-zero, indicates we're loading the title for the page.
|
| - HistoryService::Handle title_handle;
|
| + // If not |base::CancelableTaskTracker::kBadTaskId|, indicates we're loading
|
| + // the title for the page.
|
| + base::CancelableTaskTracker::TaskId task_id;
|
| };
|
|
|
| CustomHomePagesTableModel::CustomHomePagesTableModel(Profile* profile)
|
| @@ -159,11 +161,9 @@ void CustomHomePagesTableModel::Remove(int index) {
|
| Entry* entry = &(entries_[index]);
|
| // Cancel any pending load requests now so we don't deref a bogus pointer when
|
| // we get the loaded notification.
|
| - if (entry->title_handle) {
|
| - HistoryService* history_service = HistoryServiceFactory::GetForProfile(
|
| - profile_, Profile::EXPLICIT_ACCESS);
|
| - if (history_service)
|
| - history_service->CancelRequest(entry->title_handle);
|
| + if (entry->task_id != base::CancelableTaskTracker::kBadTaskId) {
|
| + task_tracker_.TryCancel(entry->task_id);
|
| + entry->task_id = base::CancelableTaskTracker::kBadTaskId;
|
| }
|
| entries_.erase(entries_.begin() + static_cast<size_t>(index));
|
| if (observer_)
|
| @@ -224,46 +224,41 @@ void CustomHomePagesTableModel::LoadTitle(Entry* entry) {
|
| HistoryService* history_service = HistoryServiceFactory::GetForProfile(
|
| profile_, Profile::EXPLICIT_ACCESS);
|
| if (history_service) {
|
| - entry->title_handle = history_service->QueryURL(entry->url, false,
|
| - &history_query_consumer_,
|
| + entry->task_id = history_service->QueryURL(
|
| + entry->url,
|
| + false,
|
| base::Bind(&CustomHomePagesTableModel::OnGotTitle,
|
| - base::Unretained(this)));
|
| + base::Unretained(this),
|
| + entry->url),
|
| + &task_tracker_);
|
| }
|
| }
|
|
|
| -void CustomHomePagesTableModel::OnGotTitle(HistoryService::Handle handle,
|
| +void CustomHomePagesTableModel::OnGotTitle(const GURL& entry_url,
|
| bool found_url,
|
| - const history::URLRow* row,
|
| - history::VisitVector* visits) {
|
| - int entry_index;
|
| - Entry* entry =
|
| - GetEntryByLoadHandle(&Entry::title_handle, handle, &entry_index);
|
| + const history::URLRow& row,
|
| + const history::VisitVector& visits) {
|
| + int entry_index = 0;
|
| + Entry* entry = NULL;
|
| + for (size_t i = 0; i < entries_.size(); ++i) {
|
| + if (entries_[i].url == entry_url) {
|
| + entry = &entries_[i];
|
| + entry_index = i;
|
| + break;
|
| + }
|
| + }
|
| if (!entry) {
|
| // The URLs changed before we were called back.
|
| return;
|
| }
|
| - entry->title_handle = 0;
|
| - if (found_url && !row->title().empty()) {
|
| - entry->title = row->title();
|
| + entry->task_id = base::CancelableTaskTracker::kBadTaskId;
|
| + if (found_url && !row.title().empty()) {
|
| + entry->title = row.title();
|
| if (observer_)
|
| observer_->OnItemsChanged(static_cast<int>(entry_index), 1);
|
| }
|
| }
|
|
|
| -CustomHomePagesTableModel::Entry*
|
| - CustomHomePagesTableModel::GetEntryByLoadHandle(
|
| - CancelableRequestProvider::Handle Entry::* member,
|
| - CancelableRequestProvider::Handle handle,
|
| - int* index) {
|
| - for (size_t i = 0; i < entries_.size(); ++i) {
|
| - if (entries_[i].*member == handle) {
|
| - *index = static_cast<int>(i);
|
| - return &entries_[i];
|
| - }
|
| - }
|
| - return NULL;
|
| -}
|
| -
|
| base::string16 CustomHomePagesTableModel::FormattedURL(int row) const {
|
| std::string languages =
|
| profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
|
|
|