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

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

Issue 8451009: HQP Refactoring (in Preparation for SQLite Cache) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // The history system runs on a background thread so that potentially slow 5 // The history system runs on a background thread so that potentially slow
6 // database operations don't delay the browser. This backend processing is 6 // database operations don't delay the browser. This backend processing is
7 // represented by HistoryBackend. The HistoryService's job is to dispatch to 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to
8 // that thread. 8 // that thread.
9 // 9 //
10 // Main thread History thread 10 // Main thread History thread
11 // ----------- -------------- 11 // ----------- --------------
12 // HistoryService <----------------> HistoryBackend 12 // HistoryService <----------------> HistoryBackend
13 // -> HistoryDatabase 13 // -> HistoryDatabase
14 // -> SQLite connection to History 14 // -> SQLite connection to History
15 // -> ArchivedDatabase 15 // -> ArchivedDatabase
16 // -> SQLite connection to Archived History 16 // -> SQLite connection to Archived History
17 // -> TextDatabaseManager 17 // -> TextDatabaseManager
18 // -> SQLite connection to one month's data 18 // -> SQLite connection to one month's data
19 // -> SQLite connection to one month's data 19 // -> SQLite connection to one month's data
20 // ... 20 // ...
21 // -> ThumbnailDatabase 21 // -> ThumbnailDatabase
22 // -> SQLite connection to Thumbnails 22 // -> SQLite connection to Thumbnails
23 // (and favicons) 23 // (and favicons)
24 24
25 #include "chrome/browser/history/history.h" 25 #include "chrome/browser/history/history.h"
26 26
27 #include "base/callback.h" 27 #include "base/callback.h"
28 #include "base/command_line.h"
28 #include "base/memory/ref_counted.h" 29 #include "base/memory/ref_counted.h"
29 #include "base/message_loop.h" 30 #include "base/message_loop.h"
30 #include "base/path_service.h" 31 #include "base/path_service.h"
31 #include "base/string_util.h" 32 #include "base/string_util.h"
32 #include "base/task.h" 33 #include "base/task.h"
33 #include "chrome/browser/autocomplete/history_url_provider.h" 34 #include "chrome/browser/autocomplete/history_url_provider.h"
34 #include "chrome/browser/browser_process.h" 35 #include "chrome/browser/browser_process.h"
35 #include "chrome/browser/history/history_backend.h" 36 #include "chrome/browser/history/history_backend.h"
36 #include "chrome/browser/history/history_notifications.h" 37 #include "chrome/browser/history/history_notifications.h"
37 #include "chrome/browser/history/history_types.h" 38 #include "chrome/browser/history/history_types.h"
38 #include "chrome/browser/history/in_memory_database.h" 39 #include "chrome/browser/history/in_memory_database.h"
39 #include "chrome/browser/history/in_memory_history_backend.h" 40 #include "chrome/browser/history/in_memory_history_backend.h"
41 #include "chrome/browser/history/in_memory_url_index.h"
40 #include "chrome/browser/history/top_sites.h" 42 #include "chrome/browser/history/top_sites.h"
41 #include "chrome/browser/prefs/pref_service.h" 43 #include "chrome/browser/prefs/pref_service.h"
42 #include "chrome/browser/profiles/profile.h" 44 #include "chrome/browser/profiles/profile.h"
43 #include "chrome/browser/ui/profile_error_dialog.h" 45 #include "chrome/browser/ui/profile_error_dialog.h"
44 #include "chrome/browser/visitedlink/visitedlink_master.h" 46 #include "chrome/browser/visitedlink/visitedlink_master.h"
45 #include "chrome/common/chrome_constants.h" 47 #include "chrome/common/chrome_constants.h"
46 #include "chrome/common/chrome_notification_types.h" 48 #include "chrome/common/chrome_notification_types.h"
49 #include "chrome/common/chrome_switches.h"
47 #include "chrome/common/pref_names.h" 50 #include "chrome/common/pref_names.h"
48 #include "chrome/common/thumbnail_score.h" 51 #include "chrome/common/thumbnail_score.h"
49 #include "chrome/common/url_constants.h" 52 #include "chrome/common/url_constants.h"
50 #include "content/browser/download/download_persistent_store_info.h" 53 #include "content/browser/download/download_persistent_store_info.h"
51 #include "content/public/browser/browser_thread.h" 54 #include "content/public/browser/browser_thread.h"
52 #include "content/public/browser/notification_service.h" 55 #include "content/public/browser/notification_service.h"
53 #include "grit/chromium_strings.h" 56 #include "grit/chromium_strings.h"
54 #include "grit/generated_resources.h" 57 #include "grit/generated_resources.h"
55 #include "third_party/skia/include/core/SkBitmap.h" 58 #include "third_party/skia/include/core/SkBitmap.h"
56 59
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 147
145 HistoryService::HistoryService(Profile* profile) 148 HistoryService::HistoryService(Profile* profile)
146 : thread_(new base::Thread(kHistoryThreadName)), 149 : thread_(new base::Thread(kHistoryThreadName)),
147 profile_(profile), 150 profile_(profile),
148 backend_loaded_(false), 151 backend_loaded_(false),
149 current_backend_id_(-1), 152 current_backend_id_(-1),
150 bookmark_service_(NULL), 153 bookmark_service_(NULL),
151 no_db_(false), 154 no_db_(false),
152 needs_top_sites_migration_(false) { 155 needs_top_sites_migration_(false) {
153 DCHECK(profile_); 156 DCHECK(profile_);
157 if (!CommandLine::ForCurrentProcess()->HasSwitch(
158 switches::kDisableHistoryQuickProvider)) {
159 in_memory_url_index_.reset(
160 new history::InMemoryURLIndex(profile, history_dir_));
Peter Kasting 2011/11/21 19:07:50 Nit: Use |profile_| for consistency.
mrossetti 2011/11/21 21:53:25 Done.
161 std::string languages;
162 if (profile) {
Peter Kasting 2011/11/21 19:07:50 Nit: This conditional is unnecessary given that we
mrossetti 2011/11/21 21:53:25 Done.
163 PrefService* prefs = profile_->GetPrefs();
164 languages = prefs->GetString(prefs::kAcceptLanguages);
165 }
166 in_memory_url_index_->Init(languages);
167 }
154 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 168 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
155 content::Source<Profile>(profile_)); 169 content::Source<Profile>(profile_));
156 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, 170 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED,
157 content::Source<Profile>(profile_)); 171 content::Source<Profile>(profile_));
158 } 172 }
159 173
160 HistoryService::~HistoryService() { 174 HistoryService::~HistoryService() {
161 // Shutdown the backend. This does nothing if Cleanup was already invoked. 175 // Shutdown the backend. This does nothing if Cleanup was already invoked.
162 Cleanup(); 176 Cleanup();
163 } 177 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 history_backend_ = NULL; 224 history_backend_ = NULL;
211 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr); 225 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr);
212 } 226 }
213 227
214 void HistoryService::Cleanup() { 228 void HistoryService::Cleanup() {
215 if (!thread_) { 229 if (!thread_) {
216 // We've already cleaned up. 230 // We've already cleaned up.
217 return; 231 return;
218 } 232 }
219 233
234 // Give the InMemoryURLIndex a chance to shutdown.
235 if (in_memory_url_index_.get())
236 in_memory_url_index_->ShutDown();
237
220 // Unload the backend. 238 // Unload the backend.
221 UnloadBackend(); 239 UnloadBackend();
222 240
223 // Delete the thread, which joins with the background thread. We defensively 241 // Delete the thread, which joins with the background thread. We defensively
224 // NULL the pointer before deleting it in case somebody tries to use it 242 // NULL the pointer before deleting it in case somebody tries to use it
225 // during shutdown, but this shouldn't happen. 243 // during shutdown, but this shouldn't happen.
226 base::Thread* thread = thread_; 244 base::Thread* thread = thread_;
227 thread_ = NULL; 245 thread_ = NULL;
228 delete thread; 246 delete thread;
229 } 247 }
230 248
231 void HistoryService::NotifyRenderProcessHostDestruction(const void* host) { 249 void HistoryService::NotifyRenderProcessHostDestruction(const void* host) {
232 ScheduleAndForget(PRIORITY_NORMAL, 250 ScheduleAndForget(PRIORITY_NORMAL,
233 &HistoryBackend::NotifyRenderProcessHostDestruction, host); 251 &HistoryBackend::NotifyRenderProcessHostDestruction, host);
234 } 252 }
235 253
236 history::URLDatabase* HistoryService::InMemoryDatabase() { 254 history::URLDatabase* HistoryService::InMemoryDatabase() {
237 // NOTE: See comments in BackendLoaded() as to why we call 255 // NOTE: See comments in BackendLoaded() as to why we call
238 // LoadBackendIfNecessary() here even though it won't affect the return value 256 // LoadBackendIfNecessary() here even though it won't affect the return value
239 // for this call. 257 // for this call.
240 LoadBackendIfNecessary(); 258 LoadBackendIfNecessary();
241 if (in_memory_backend_.get()) 259 if (in_memory_backend_.get())
242 return in_memory_backend_->db(); 260 return in_memory_backend_->db();
243 return NULL; 261 return NULL;
244 } 262 }
245 263
246 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { 264 history::URLDatabase* HistoryService::HistoryDatabase() {
247 // NOTE: See comments in BackendLoaded() as to why we call 265 return history_backend_->database();
248 // LoadBackendIfNecessary() here even though it won't affect the return value 266 }
249 // for this call. 267
250 LoadBackendIfNecessary(); 268 history::InMemoryURLIndex* HistoryService::InMemoryIndex() const {
251 if (in_memory_backend_.get()) 269 return in_memory_url_index_.get();
252 return in_memory_backend_->InMemoryIndex();
253 return NULL;
254 } 270 }
255 271
256 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { 272 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) {
257 ScheduleAndForget(PRIORITY_UI, 273 ScheduleAndForget(PRIORITY_UI,
258 &HistoryBackend::SetSegmentPresentationIndex, 274 &HistoryBackend::SetSegmentPresentationIndex,
259 segment_id, index); 275 segment_id, index);
260 } 276 }
261 277
262 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, 278 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url,
263 TemplateURLID keyword_id, 279 TemplateURLID keyword_id,
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); 860 history::TopSites* ts = profile_->GetTopSitesWithoutCreating();
845 if (ts) 861 if (ts)
846 ts->MigrateFromHistory(); 862 ts->MigrateFromHistory();
847 } 863 }
848 } 864 }
849 865
850 void HistoryService::OnTopSitesReady() { 866 void HistoryService::OnTopSitesReady() {
851 ScheduleAndForget(PRIORITY_NORMAL, 867 ScheduleAndForget(PRIORITY_NORMAL,
852 &HistoryBackend::MigrateThumbnailsDatabase); 868 &HistoryBackend::MigrateThumbnailsDatabase);
853 } 869 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698