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

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 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/history.h ('k') | chrome/browser/history/history_backend.h » ('j') | 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) 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_));
161 std::string languages;
162 PrefService* prefs = profile_->GetPrefs();
163 languages = prefs->GetString(prefs::kAcceptLanguages);
164 in_memory_url_index_->Init(languages);
165 }
154 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 166 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
155 content::Source<Profile>(profile_)); 167 content::Source<Profile>(profile_));
156 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, 168 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED,
157 content::Source<Profile>(profile_)); 169 content::Source<Profile>(profile_));
158 } 170 }
159 171
160 HistoryService::~HistoryService() { 172 HistoryService::~HistoryService() {
161 // Shutdown the backend. This does nothing if Cleanup was already invoked. 173 // Shutdown the backend. This does nothing if Cleanup was already invoked.
162 Cleanup(); 174 Cleanup();
163 } 175 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 history_backend_ = NULL; 222 history_backend_ = NULL;
211 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr); 223 thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr);
212 } 224 }
213 225
214 void HistoryService::Cleanup() { 226 void HistoryService::Cleanup() {
215 if (!thread_) { 227 if (!thread_) {
216 // We've already cleaned up. 228 // We've already cleaned up.
217 return; 229 return;
218 } 230 }
219 231
232 // Give the InMemoryURLIndex a chance to shutdown.
233 if (in_memory_url_index_.get())
234 in_memory_url_index_->ShutDown();
235
220 // Unload the backend. 236 // Unload the backend.
221 UnloadBackend(); 237 UnloadBackend();
222 238
223 // Delete the thread, which joins with the background thread. We defensively 239 // 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 240 // NULL the pointer before deleting it in case somebody tries to use it
225 // during shutdown, but this shouldn't happen. 241 // during shutdown, but this shouldn't happen.
226 base::Thread* thread = thread_; 242 base::Thread* thread = thread_;
227 thread_ = NULL; 243 thread_ = NULL;
228 delete thread; 244 delete thread;
229 } 245 }
230 246
231 void HistoryService::NotifyRenderProcessHostDestruction(const void* host) { 247 void HistoryService::NotifyRenderProcessHostDestruction(const void* host) {
232 ScheduleAndForget(PRIORITY_NORMAL, 248 ScheduleAndForget(PRIORITY_NORMAL,
233 &HistoryBackend::NotifyRenderProcessHostDestruction, host); 249 &HistoryBackend::NotifyRenderProcessHostDestruction, host);
234 } 250 }
235 251
236 history::URLDatabase* HistoryService::InMemoryDatabase() { 252 history::URLDatabase* HistoryService::InMemoryDatabase() {
237 // NOTE: See comments in BackendLoaded() as to why we call 253 // NOTE: See comments in BackendLoaded() as to why we call
238 // LoadBackendIfNecessary() here even though it won't affect the return value 254 // LoadBackendIfNecessary() here even though it won't affect the return value
239 // for this call. 255 // for this call.
240 LoadBackendIfNecessary(); 256 LoadBackendIfNecessary();
241 if (in_memory_backend_.get()) 257 if (in_memory_backend_.get())
242 return in_memory_backend_->db(); 258 return in_memory_backend_->db();
243 return NULL; 259 return NULL;
244 } 260 }
245 261
262 history::URLDatabase* HistoryService::HistoryDatabase() {
263 return history_backend_->database();
264 }
265
246 history::InMemoryURLIndex* HistoryService::InMemoryIndex() { 266 history::InMemoryURLIndex* HistoryService::InMemoryIndex() {
247 // NOTE: See comments in BackendLoaded() as to why we call 267 return in_memory_url_index_.get();
248 // LoadBackendIfNecessary() here even though it won't affect the return value
249 // for this call.
250 LoadBackendIfNecessary();
251 if (in_memory_backend_.get())
252 return in_memory_backend_->InMemoryIndex();
253 return NULL;
254 } 268 }
255 269
256 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { 270 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) {
257 ScheduleAndForget(PRIORITY_UI, 271 ScheduleAndForget(PRIORITY_UI,
258 &HistoryBackend::SetSegmentPresentationIndex, 272 &HistoryBackend::SetSegmentPresentationIndex,
259 segment_id, index); 273 segment_id, index);
260 } 274 }
261 275
262 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, 276 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url,
263 TemplateURLID keyword_id, 277 TemplateURLID keyword_id,
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); 864 history::TopSites* ts = profile_->GetTopSitesWithoutCreating();
851 if (ts) 865 if (ts)
852 ts->MigrateFromHistory(); 866 ts->MigrateFromHistory();
853 } 867 }
854 } 868 }
855 869
856 void HistoryService::OnTopSitesReady() { 870 void HistoryService::OnTopSitesReady() {
857 ScheduleAndForget(PRIORITY_NORMAL, 871 ScheduleAndForget(PRIORITY_NORMAL,
858 &HistoryBackend::MigrateThumbnailsDatabase); 872 &HistoryBackend::MigrateThumbnailsDatabase);
859 } 873 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history.h ('k') | chrome/browser/history/history_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698