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/autocomplete/in_memory_url_index.h" | 5 #include "chrome/browser/autocomplete/in_memory_url_index.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "chrome/browser/autocomplete/url_index_private_data.h" | 10 #include "chrome/browser/autocomplete/url_index_private_data.h" |
11 #include "chrome/browser/history/history_service.h" | 11 #include "chrome/browser/history/history_service.h" |
12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
13 #include "components/history/core/browser/url_database.h" | 13 #include "components/history/core/browser/url_database.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 | 15 |
16 using in_memory_url_index::InMemoryURLIndexCacheItem; | 16 using in_memory_url_index::InMemoryURLIndexCacheItem; |
17 | 17 |
18 namespace history { | |
19 | |
20 // Called by DoSaveToCacheFile to delete any old cache file at |path| when | 18 // Called by DoSaveToCacheFile to delete any old cache file at |path| when |
21 // there is no private data to save. Runs on the FILE thread. | 19 // there is no private data to save. Runs on the FILE thread. |
22 void DeleteCacheFile(const base::FilePath& path) { | 20 void DeleteCacheFile(const base::FilePath& path) { |
23 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 21 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
24 base::DeleteFile(path, false); | 22 base::DeleteFile(path, false); |
25 } | 23 } |
26 | 24 |
27 // Initializes a whitelist of URL schemes. | 25 // Initializes a whitelist of URL schemes. |
28 void InitializeSchemeWhitelist(std::set<std::string>* whitelist) { | 26 void InitializeSchemeWhitelist(std::set<std::string>* whitelist) { |
29 DCHECK(whitelist); | 27 DCHECK(whitelist); |
(...skipping 21 matching lines...) Expand all Loading... |
51 InMemoryURLIndex* index, | 49 InMemoryURLIndex* index, |
52 const std::string& languages, | 50 const std::string& languages, |
53 const std::set<std::string>& scheme_whitelist) | 51 const std::set<std::string>& scheme_whitelist) |
54 : index_(index), | 52 : index_(index), |
55 languages_(languages), | 53 languages_(languages), |
56 scheme_whitelist_(scheme_whitelist), | 54 scheme_whitelist_(scheme_whitelist), |
57 succeeded_(false) { | 55 succeeded_(false) { |
58 } | 56 } |
59 | 57 |
60 bool InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::RunOnDBThread( | 58 bool InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::RunOnDBThread( |
61 HistoryBackend* backend, | 59 history::HistoryBackend* backend, |
62 HistoryDatabase* db) { | 60 history::HistoryDatabase* db) { |
63 data_ = URLIndexPrivateData::RebuildFromHistory(db, languages_, | 61 data_ = URLIndexPrivateData::RebuildFromHistory(db, languages_, |
64 scheme_whitelist_); | 62 scheme_whitelist_); |
65 succeeded_ = data_.get() && !data_->Empty(); | 63 succeeded_ = data_.get() && !data_->Empty(); |
66 if (!succeeded_ && data_.get()) | 64 if (!succeeded_ && data_.get()) |
67 data_->Clear(); | 65 data_->Clear(); |
68 return true; | 66 return true; |
69 } | 67 } |
70 | 68 |
71 void InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask:: | 69 void InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask:: |
72 DoneRunOnMainThread() { | 70 DoneRunOnMainThread() { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 146 } |
149 | 147 |
150 // Updating -------------------------------------------------------------------- | 148 // Updating -------------------------------------------------------------------- |
151 | 149 |
152 void InMemoryURLIndex::DeleteURL(const GURL& url) { | 150 void InMemoryURLIndex::DeleteURL(const GURL& url) { |
153 private_data_->DeleteURL(url); | 151 private_data_->DeleteURL(url); |
154 } | 152 } |
155 | 153 |
156 void InMemoryURLIndex::OnURLVisited(HistoryService* history_service, | 154 void InMemoryURLIndex::OnURLVisited(HistoryService* history_service, |
157 ui::PageTransition transition, | 155 ui::PageTransition transition, |
158 const URLRow& row, | 156 const history::URLRow& row, |
159 const RedirectList& redirects, | 157 const history::RedirectList& redirects, |
160 base::Time visit_time) { | 158 base::Time visit_time) { |
161 DCHECK_EQ(history_service_, history_service); | 159 DCHECK_EQ(history_service_, history_service); |
162 needs_to_be_cached_ |= private_data_->UpdateURL(history_service_, | 160 needs_to_be_cached_ |= private_data_->UpdateURL(history_service_, |
163 row, | 161 row, |
164 languages_, | 162 languages_, |
165 scheme_whitelist_, | 163 scheme_whitelist_, |
166 &private_data_tracker_); | 164 &private_data_tracker_); |
167 } | 165 } |
168 | 166 |
169 void InMemoryURLIndex::OnURLsModified(HistoryService* history_service, | 167 void InMemoryURLIndex::OnURLsModified(HistoryService* history_service, |
170 const URLRows& changed_urls) { | 168 const history::URLRows& changed_urls) { |
171 DCHECK_EQ(history_service_, history_service); | 169 DCHECK_EQ(history_service_, history_service); |
172 for (const auto& row : changed_urls) { | 170 for (const auto& row : changed_urls) { |
173 needs_to_be_cached_ |= private_data_->UpdateURL(history_service_, | 171 needs_to_be_cached_ |= private_data_->UpdateURL(history_service_, |
174 row, | 172 row, |
175 languages_, | 173 languages_, |
176 scheme_whitelist_, | 174 scheme_whitelist_, |
177 &private_data_tracker_); | 175 &private_data_tracker_); |
178 } | 176 } |
179 } | 177 } |
180 | 178 |
181 void InMemoryURLIndex::OnURLsDeleted(HistoryService* history_service, | 179 void InMemoryURLIndex::OnURLsDeleted(HistoryService* history_service, |
182 bool all_history, | 180 bool all_history, |
183 bool expired, | 181 bool expired, |
184 const URLRows& deleted_rows, | 182 const history::URLRows& deleted_rows, |
185 const std::set<GURL>& favicon_urls) { | 183 const std::set<GURL>& favicon_urls) { |
186 if (all_history) { | 184 if (all_history) { |
187 ClearPrivateData(); | 185 ClearPrivateData(); |
188 needs_to_be_cached_ = true; | 186 needs_to_be_cached_ = true; |
189 } else { | 187 } else { |
190 for (const auto& row : deleted_rows) | 188 for (const auto& row : deleted_rows) |
191 needs_to_be_cached_ |= private_data_->DeleteURL(row.url()); | 189 needs_to_be_cached_ |= private_data_->DeleteURL(row.url()); |
192 } | 190 } |
193 // If we made changes, destroy the previous cache. Otherwise, if we go | 191 // If we made changes, destroy the previous cache. Otherwise, if we go |
194 // through an unclean shutdown (and therefore fail to write a new cache file), | 192 // through an unclean shutdown (and therefore fail to write a new cache file), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } else { | 283 } else { |
286 private_data_->Clear(); // Dump the old private data. | 284 private_data_->Clear(); // Dump the old private data. |
287 // There is no need to do anything with the cache file as it was deleted | 285 // There is no need to do anything with the cache file as it was deleted |
288 // when the rebuild from the history operation was kicked off. | 286 // when the rebuild from the history operation was kicked off. |
289 } | 287 } |
290 restored_ = true; | 288 restored_ = true; |
291 if (restore_cache_observer_) | 289 if (restore_cache_observer_) |
292 restore_cache_observer_->OnCacheRestoreFinished(succeeded); | 290 restore_cache_observer_->OnCacheRestoreFinished(succeeded); |
293 } | 291 } |
294 | 292 |
295 void InMemoryURLIndex::RebuildFromHistory(HistoryDatabase* history_db) { | 293 void InMemoryURLIndex::RebuildFromHistory( |
| 294 history::HistoryDatabase* history_db) { |
296 private_data_tracker_.TryCancelAll(); | 295 private_data_tracker_.TryCancelAll(); |
297 private_data_ = URLIndexPrivateData::RebuildFromHistory(history_db, | 296 private_data_ = URLIndexPrivateData::RebuildFromHistory(history_db, |
298 languages_, | 297 languages_, |
299 scheme_whitelist_); | 298 scheme_whitelist_); |
300 } | 299 } |
301 | 300 |
302 // Saving to Cache ------------------------------------------------------------- | 301 // Saving to Cache ------------------------------------------------------------- |
303 | 302 |
304 void InMemoryURLIndex::PostSaveToCacheFileTask() { | 303 void InMemoryURLIndex::PostSaveToCacheFileTask() { |
305 base::FilePath path; | 304 base::FilePath path; |
(...skipping 16 matching lines...) Expand all Loading... |
322 content::BrowserThread::PostBlockingPoolTask( | 321 content::BrowserThread::PostBlockingPoolTask( |
323 FROM_HERE, | 322 FROM_HERE, |
324 base::Bind(DeleteCacheFile, path)); | 323 base::Bind(DeleteCacheFile, path)); |
325 } | 324 } |
326 } | 325 } |
327 | 326 |
328 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { | 327 void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { |
329 if (save_cache_observer_) | 328 if (save_cache_observer_) |
330 save_cache_observer_->OnCacheSaveFinished(succeeded); | 329 save_cache_observer_->OnCacheSaveFinished(succeeded); |
331 } | 330 } |
332 | |
333 } // namespace history | |
OLD | NEW |