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

Side by Side Diff: chrome/browser/history/in_memory_url_index.cc

Issue 10909046: Boost HQP Scores for Bookmarks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Minor edits. Created 8 years, 3 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/history/in_memory_url_index.h" 5 #include "chrome/browser/history/in_memory_url_index.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/history/history_notifications.h" 9 #include "chrome/browser/history/history_notifications.h"
10 #include "chrome/browser/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 InMemoryURLIndex::RestoreCacheObserver::~RestoreCacheObserver() {} 52 InMemoryURLIndex::RestoreCacheObserver::~RestoreCacheObserver() {}
53 53
54 InMemoryURLIndex::SaveCacheObserver::~SaveCacheObserver() {} 54 InMemoryURLIndex::SaveCacheObserver::~SaveCacheObserver() {}
55 55
56 // RebuildPrivateDataFromHistoryDBTask ----------------------------------------- 56 // RebuildPrivateDataFromHistoryDBTask -----------------------------------------
57 57
58 InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask:: 58 InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::
59 RebuildPrivateDataFromHistoryDBTask( 59 RebuildPrivateDataFromHistoryDBTask(
60 InMemoryURLIndex* index, 60 InMemoryURLIndex* index,
61 Profile* profile,
sky 2012/09/05 20:57:49 Are you using this on the db thread?
mrossetti 2012/09/05 22:35:40 No, it was not referenced on the db thread, howeve
61 const std::string& languages, 62 const std::string& languages,
62 const std::set<std::string>& scheme_whitelist) 63 const std::set<std::string>& scheme_whitelist)
63 : index_(index), 64 : index_(index),
65 profile_(profile),
64 languages_(languages), 66 languages_(languages),
65 scheme_whitelist_(scheme_whitelist), 67 scheme_whitelist_(scheme_whitelist),
66 succeeded_(false) { 68 succeeded_(false) {
67 } 69 }
68 70
69 bool InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::RunOnDBThread( 71 bool InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::RunOnDBThread(
70 HistoryBackend* backend, 72 HistoryBackend* backend,
71 HistoryDatabase* db) { 73 HistoryDatabase* db) {
72 data_ = URLIndexPrivateData::RebuildFromHistory(db, languages_, 74 data_ = URLIndexPrivateData::RebuildFromHistory(profile_, db, languages_,
73 scheme_whitelist_); 75 scheme_whitelist_);
74 succeeded_ = data_.get() && !data_->Empty(); 76 succeeded_ = data_.get() && !data_->Empty();
75 if (!succeeded_ && data_.get()) 77 if (!succeeded_ && data_.get())
76 data_->Clear(); 78 data_->Clear();
77 return true; 79 return true;
78 } 80 }
79 81
80 void InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask:: 82 void InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::
81 DoneRunOnMainThread() { 83 DoneRunOnMainThread() {
82 index_->DoneRebuidingPrivateDataFromHistoryDB(succeeded_, data_); 84 index_->DoneRebuidingPrivateDataFromHistoryDB(succeeded_, data_);
83 } 85 }
84 86
85 InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask:: 87 InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::
86 ~RebuildPrivateDataFromHistoryDBTask() { 88 ~RebuildPrivateDataFromHistoryDBTask() {
87 } 89 }
88 90
89 // InMemoryURLIndex ------------------------------------------------------------ 91 // InMemoryURLIndex ------------------------------------------------------------
90 92
91 InMemoryURLIndex::InMemoryURLIndex(Profile* profile, 93 InMemoryURLIndex::InMemoryURLIndex(Profile* profile,
92 const FilePath& history_dir, 94 const FilePath& history_dir,
93 const std::string& languages) 95 const std::string& languages)
94 : profile_(profile), 96 : profile_(profile),
95 history_dir_(history_dir), 97 history_dir_(history_dir),
96 languages_(languages), 98 languages_(languages),
97 private_data_(new URLIndexPrivateData), 99 private_data_(new URLIndexPrivateData(profile)),
98 restore_cache_observer_(NULL), 100 restore_cache_observer_(NULL),
99 save_cache_observer_(NULL), 101 save_cache_observer_(NULL),
100 shutdown_(false), 102 shutdown_(false),
101 restored_(false), 103 restored_(false),
102 needs_to_be_cached_(false) { 104 needs_to_be_cached_(false) {
103 InitializeSchemeWhitelist(&scheme_whitelist_); 105 InitializeSchemeWhitelist(&scheme_whitelist_);
104 if (profile) { 106 if (profile) {
105 // TODO(mrossetti): Register for language change notifications. 107 // TODO(mrossetti): Register for language change notifications.
106 content::Source<Profile> source(profile); 108 content::Source<Profile> source(profile);
107 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, source); 109 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URL_VISITED, source);
108 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, 110 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
109 source); 111 source);
110 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source); 112 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source);
111 } 113 }
112 } 114 }
113 115
114 // Called only by unit tests. 116 // Called only by unit tests.
115 InMemoryURLIndex::InMemoryURLIndex() 117 InMemoryURLIndex::InMemoryURLIndex()
116 : profile_(NULL), 118 : profile_(NULL),
117 private_data_(new URLIndexPrivateData), 119 private_data_(new URLIndexPrivateData(NULL)),
118 restore_cache_observer_(NULL), 120 restore_cache_observer_(NULL),
119 save_cache_observer_(NULL), 121 save_cache_observer_(NULL),
120 shutdown_(false), 122 shutdown_(false),
121 restored_(false), 123 restored_(false),
122 needs_to_be_cached_(false) { 124 needs_to_be_cached_(false) {
123 InitializeSchemeWhitelist(&scheme_whitelist_); 125 InitializeSchemeWhitelist(&scheme_whitelist_);
124 } 126 }
125 127
126 InMemoryURLIndex::~InMemoryURLIndex() { 128 InMemoryURLIndex::~InMemoryURLIndex() {
127 // If there was a history directory (which there won't be for some unit tests) 129 // If there was a history directory (which there won't be for some unit tests)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 225
224 FilePath path; 226 FilePath path;
225 if (!GetCacheFilePath(&path) || shutdown_) { 227 if (!GetCacheFilePath(&path) || shutdown_) {
226 restored_ = true; 228 restored_ = true;
227 if (restore_cache_observer_) 229 if (restore_cache_observer_)
228 restore_cache_observer_->OnCacheRestoreFinished(false); 230 restore_cache_observer_->OnCacheRestoreFinished(false);
229 return; 231 return;
230 } 232 }
231 233
232 scoped_refptr<URLIndexPrivateData> restored_private_data = 234 scoped_refptr<URLIndexPrivateData> restored_private_data =
233 new URLIndexPrivateData; 235 new URLIndexPrivateData(profile_);
234 content::BrowserThread::PostTaskAndReply( 236 content::BrowserThread::PostTaskAndReply(
235 content::BrowserThread::FILE, FROM_HERE, 237 content::BrowserThread::FILE, FROM_HERE,
236 base::Bind(&URLIndexPrivateData::RestoreFromFileTask, path, 238 base::Bind(&URLIndexPrivateData::RestoreFromFileTask, profile_, path,
237 restored_private_data, languages_), 239 restored_private_data, languages_),
238 base::Bind(&InMemoryURLIndex::OnCacheLoadDone, AsWeakPtr(), 240 base::Bind(&InMemoryURLIndex::OnCacheLoadDone, AsWeakPtr(),
239 restored_private_data)); 241 restored_private_data));
240 } 242 }
241 243
242 void InMemoryURLIndex::OnCacheLoadDone( 244 void InMemoryURLIndex::OnCacheLoadDone(
243 scoped_refptr<URLIndexPrivateData> private_data) { 245 scoped_refptr<URLIndexPrivateData> private_data) {
244 if (private_data.get() && !private_data->Empty()) { 246 if (private_data.get() && !private_data->Empty()) {
245 private_data_ = private_data; 247 private_data_ = private_data;
246 restored_ = true; 248 restored_ = true;
(...skipping 20 matching lines...) Expand all
267 } 269 }
268 270
269 // Restoring from the History DB ----------------------------------------------- 271 // Restoring from the History DB -----------------------------------------------
270 272
271 void InMemoryURLIndex::ScheduleRebuildFromHistory() { 273 void InMemoryURLIndex::ScheduleRebuildFromHistory() {
272 HistoryService* service = 274 HistoryService* service =
273 HistoryServiceFactory::GetForProfile(profile_, 275 HistoryServiceFactory::GetForProfile(profile_,
274 Profile::EXPLICIT_ACCESS); 276 Profile::EXPLICIT_ACCESS);
275 service->ScheduleDBTask( 277 service->ScheduleDBTask(
276 new InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask( 278 new InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask(
277 this, languages_, scheme_whitelist_), 279 this, profile_, languages_, scheme_whitelist_),
278 &cache_reader_consumer_); 280 &cache_reader_consumer_);
279 } 281 }
280 282
281 void InMemoryURLIndex::DoneRebuidingPrivateDataFromHistoryDB( 283 void InMemoryURLIndex::DoneRebuidingPrivateDataFromHistoryDB(
282 bool succeeded, 284 bool succeeded,
283 scoped_refptr<URLIndexPrivateData> private_data) { 285 scoped_refptr<URLIndexPrivateData> private_data) {
284 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 286 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
285 if (succeeded) { 287 if (succeeded) {
286 private_data_ = private_data; 288 private_data_ = private_data;
287 PostSaveToCacheFileTask(); // Cache the newly rebuilt index. 289 PostSaveToCacheFileTask(); // Cache the newly rebuilt index.
288 } else { 290 } else {
289 private_data_->Clear(); // Dump the old private data. 291 private_data_->Clear(); // Dump the old private data.
290 // There is no need to do anything with the cache file as it was deleted 292 // There is no need to do anything with the cache file as it was deleted
291 // when the rebuild from the history operation was kicked off. 293 // when the rebuild from the history operation was kicked off.
292 } 294 }
293 restored_ = true; 295 restored_ = true;
294 if (restore_cache_observer_) 296 if (restore_cache_observer_)
295 restore_cache_observer_->OnCacheRestoreFinished(succeeded); 297 restore_cache_observer_->OnCacheRestoreFinished(succeeded);
296 } 298 }
297 299
298 void InMemoryURLIndex::RebuildFromHistory(HistoryDatabase* history_db) { 300 void InMemoryURLIndex::RebuildFromHistory(HistoryDatabase* history_db) {
299 private_data_ = URLIndexPrivateData::RebuildFromHistory(history_db, 301 private_data_ = URLIndexPrivateData::RebuildFromHistory(profile_,
302 history_db,
300 languages_, 303 languages_,
301 scheme_whitelist_); 304 scheme_whitelist_);
302 } 305 }
303 306
304 // Saving to Cache ------------------------------------------------------------- 307 // Saving to Cache -------------------------------------------------------------
305 308
306 void InMemoryURLIndex::PostSaveToCacheFileTask() { 309 void InMemoryURLIndex::PostSaveToCacheFileTask() {
307 FilePath path; 310 FilePath path;
308 if (!GetCacheFilePath(&path)) 311 if (!GetCacheFilePath(&path))
309 return; 312 return;
(...skipping 18 matching lines...) Expand all
328 } 331 }
329 } 332 }
330 333
331 void InMemoryURLIndex::OnCacheSaveDone( 334 void InMemoryURLIndex::OnCacheSaveDone(
332 scoped_refptr<RefCountedBool> succeeded) { 335 scoped_refptr<RefCountedBool> succeeded) {
333 if (save_cache_observer_) 336 if (save_cache_observer_)
334 save_cache_observer_->OnCacheSaveFinished(succeeded->value()); 337 save_cache_observer_->OnCacheSaveFinished(succeeded->value());
335 } 338 }
336 339
337 } // namespace history 340 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698