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

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

Issue 466173003: Merge 288515 "Omnibox: Clobber HQP Cache File when user mucks wi..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2062/src/
Patch Set: Created 6 years, 4 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/history/in_memory_url_index.h ('k') | no next file » | 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) 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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) { 227 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) {
228 if (details->all_history) { 228 if (details->all_history) {
229 ClearPrivateData(); 229 ClearPrivateData();
230 needs_to_be_cached_ = true; 230 needs_to_be_cached_ = true;
231 } else { 231 } else {
232 for (URLRows::const_iterator row = details->rows.begin(); 232 for (URLRows::const_iterator row = details->rows.begin();
233 row != details->rows.end(); ++row) 233 row != details->rows.end(); ++row)
234 needs_to_be_cached_ |= private_data_->DeleteURL(row->url()); 234 needs_to_be_cached_ |= private_data_->DeleteURL(row->url());
235 } 235 }
236 // If we made changes, destroy the previous cache. Otherwise, if we go
237 // through an unclean shutdown (and therefore fail to write a new cache file),
238 // when Chrome restarts and we restore from the previous cache, we'll end up
239 // searching over URLs that may be deleted. This would be wrong, and
240 // surprising to the user who bothered to delete some URLs from his/her
241 // history. In this situation, deleting the cache is a better solution than
242 // writing a new cache (after deleting the URLs from the in-memory structure)
243 // because deleting the cache forces it to be rebuilt from history upon
244 // startup. If we instead write a new, updated cache then at the time of next
245 // startup (after an unclean shutdown) we will not rebuild the in-memory data
246 // structures from history but rather use the cache. This solution is
247 // mediocre because this cache may not have the most-recently-visited URLs
248 // in it (URLs visited after user deleted some URLs from history), which
249 // would be odd and confusing. It's better to force a rebuild.
250 base::FilePath path;
251 if (needs_to_be_cached_ && GetCacheFilePath(&path)) {
252 content::BrowserThread::PostBlockingPoolTask(
253 FROM_HERE, base::Bind(DeleteCacheFile, path));
254 }
236 } 255 }
237 256
238 // Restoring from Cache -------------------------------------------------------- 257 // Restoring from Cache --------------------------------------------------------
239 258
240 void InMemoryURLIndex::PostRestoreFromCacheFileTask() { 259 void InMemoryURLIndex::PostRestoreFromCacheFileTask() {
241 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 260 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
242 TRACE_EVENT0("browser", "InMemoryURLIndex::PostRestoreFromCacheFileTask"); 261 TRACE_EVENT0("browser", "InMemoryURLIndex::PostRestoreFromCacheFileTask");
243 262
244 base::FilePath path; 263 base::FilePath path;
245 if (!GetCacheFilePath(&path) || shutdown_) { 264 if (!GetCacheFilePath(&path) || shutdown_) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 base::Bind(DeleteCacheFile, path)); 362 base::Bind(DeleteCacheFile, path));
344 } 363 }
345 } 364 }
346 365
347 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { 366 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) {
348 if (save_cache_observer_) 367 if (save_cache_observer_)
349 save_cache_observer_->OnCacheSaveFinished(succeeded); 368 save_cache_observer_->OnCacheSaveFinished(succeeded);
350 } 369 }
351 370
352 } // namespace history 371 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_url_index.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698