| OLD | NEW |
| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 231 |
| 232 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) { | 232 void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) { |
| 233 if (details->all_history) { | 233 if (details->all_history) { |
| 234 ClearPrivateData(); | 234 ClearPrivateData(); |
| 235 needs_to_be_cached_ = true; | 235 needs_to_be_cached_ = true; |
| 236 } else { | 236 } else { |
| 237 for (URLRows::const_iterator row = details->rows.begin(); | 237 for (URLRows::const_iterator row = details->rows.begin(); |
| 238 row != details->rows.end(); ++row) | 238 row != details->rows.end(); ++row) |
| 239 needs_to_be_cached_ |= private_data_->DeleteURL(row->url()); | 239 needs_to_be_cached_ |= private_data_->DeleteURL(row->url()); |
| 240 } | 240 } |
| 241 // If we made changes, destroy the previous cache. Otherwise, if we go |
| 242 // through an unclean shutdown (and therefore fail to write a new cache file), |
| 243 // when Chrome restarts and we restore from the previous cache, we'll end up |
| 244 // searching over URLs that may be deleted. This would be wrong, and |
| 245 // surprising to the user who bothered to delete some URLs from his/her |
| 246 // history. In this situation, deleting the cache is a better solution than |
| 247 // writing a new cache (after deleting the URLs from the in-memory structure) |
| 248 // because deleting the cache forces it to be rebuilt from history upon |
| 249 // startup. If we instead write a new, updated cache then at the time of next |
| 250 // startup (after an unclean shutdown) we will not rebuild the in-memory data |
| 251 // structures from history but rather use the cache. This solution is |
| 252 // mediocre because this cache may not have the most-recently-visited URLs |
| 253 // in it (URLs visited after user deleted some URLs from history), which |
| 254 // would be odd and confusing. It's better to force a rebuild. |
| 255 base::FilePath path; |
| 256 if (needs_to_be_cached_ && GetCacheFilePath(&path)) { |
| 257 content::BrowserThread::PostBlockingPoolTask( |
| 258 FROM_HERE, base::Bind(DeleteCacheFile, path)); |
| 259 } |
| 241 } | 260 } |
| 242 | 261 |
| 243 // Restoring from Cache -------------------------------------------------------- | 262 // Restoring from Cache -------------------------------------------------------- |
| 244 | 263 |
| 245 void InMemoryURLIndex::PostRestoreFromCacheFileTask() { | 264 void InMemoryURLIndex::PostRestoreFromCacheFileTask() { |
| 246 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 265 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 247 TRACE_EVENT0("browser", "InMemoryURLIndex::PostRestoreFromCacheFileTask"); | 266 TRACE_EVENT0("browser", "InMemoryURLIndex::PostRestoreFromCacheFileTask"); |
| 248 | 267 |
| 249 base::FilePath path; | 268 base::FilePath path; |
| 250 if (!GetCacheFilePath(&path) || shutdown_) { | 269 if (!GetCacheFilePath(&path) || shutdown_) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 base::Bind(DeleteCacheFile, path)); | 371 base::Bind(DeleteCacheFile, path)); |
| 353 } | 372 } |
| 354 } | 373 } |
| 355 | 374 |
| 356 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { | 375 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { |
| 357 if (save_cache_observer_) | 376 if (save_cache_observer_) |
| 358 save_cache_observer_->OnCacheSaveFinished(succeeded); | 377 save_cache_observer_->OnCacheSaveFinished(succeeded); |
| 359 } | 378 } |
| 360 | 379 |
| 361 } // namespace history | 380 } // namespace history |
| OLD | NEW |