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

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

Issue 9316109: Move Ownership of IMUI to HistoryService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Qualify globally scoped friend classes. Created 8 years, 10 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/history.h ('k') | chrome/browser/history/history_backend.cc » ('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/threading/thread.h" 33 #include "base/threading/thread.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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return backend_loaded_; 177 return backend_loaded_;
175 } 178 }
176 179
177 void HistoryService::UnloadBackend() { 180 void HistoryService::UnloadBackend() {
178 if (!history_backend_) 181 if (!history_backend_)
179 return; // Already unloaded. 182 return; // Already unloaded.
180 183
181 // Get rid of the in-memory backend. 184 // Get rid of the in-memory backend.
182 in_memory_backend_.reset(); 185 in_memory_backend_.reset();
183 186
187 // Give the InMemoryURLIndex a chance to shutdown.
188 if (in_memory_url_index_.get())
189 in_memory_url_index_->ShutDown();
190
184 // The backend's destructor must run on the history thread since it is not 191 // The backend's destructor must run on the history thread since it is not
185 // threadsafe. So this thread must not be the last thread holding a reference 192 // threadsafe. So this thread must not be the last thread holding a reference
186 // to the backend, or a crash could happen. 193 // to the backend, or a crash could happen.
187 // 194 //
188 // We have a reference to the history backend. There is also an extra 195 // We have a reference to the history backend. There is also an extra
189 // reference held by our delegate installed in the backend, which 196 // reference held by our delegate installed in the backend, which
190 // HistoryBackend::Closing will release. This means if we scheduled a call 197 // HistoryBackend::Closing will release. This means if we scheduled a call
191 // to HistoryBackend::Closing and *then* released our backend reference, there 198 // to HistoryBackend::Closing and *then* released our backend reference, there
192 // will be a race between us and the backend's Closing function to see who is 199 // will be a race between us and the backend's Closing function to see who is
193 // the last holder of a reference. If the backend thread's Closing manages to 200 // the last holder of a reference. If the backend thread's Closing manages to
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 history::URLDatabase* HistoryService::InMemoryDatabase() { 243 history::URLDatabase* HistoryService::InMemoryDatabase() {
237 // NOTE: See comments in BackendLoaded() as to why we call 244 // NOTE: See comments in BackendLoaded() as to why we call
238 // LoadBackendIfNecessary() here even though it won't affect the return value 245 // LoadBackendIfNecessary() here even though it won't affect the return value
239 // for this call. 246 // for this call.
240 LoadBackendIfNecessary(); 247 LoadBackendIfNecessary();
241 if (in_memory_backend_.get()) 248 if (in_memory_backend_.get())
242 return in_memory_backend_->db(); 249 return in_memory_backend_->db();
243 return NULL; 250 return NULL;
244 } 251 }
245 252
246 history::InMemoryURLIndex* HistoryService::InMemoryIndex() {
247 // NOTE: See comments in BackendLoaded() as to why we call
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 }
255
256 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) { 253 void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) {
257 ScheduleAndForget(PRIORITY_UI, 254 ScheduleAndForget(PRIORITY_UI,
258 &HistoryBackend::SetSegmentPresentationIndex, 255 &HistoryBackend::SetSegmentPresentationIndex,
259 segment_id, index); 256 segment_id, index);
260 } 257 }
261 258
262 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url, 259 void HistoryService::SetKeywordSearchTermsForURL(const GURL& url,
263 TemplateURLID keyword_id, 260 TemplateURLID keyword_id,
264 const string16& term) { 261 const string16& term) {
265 ScheduleAndForget(PRIORITY_UI, 262 ScheduleAndForget(PRIORITY_UI,
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 bool no_db) { 680 bool no_db) {
684 if (!thread_->Start()) { 681 if (!thread_->Start()) {
685 Cleanup(); 682 Cleanup();
686 return false; 683 return false;
687 } 684 }
688 685
689 history_dir_ = history_dir; 686 history_dir_ = history_dir;
690 bookmark_service_ = bookmark_service; 687 bookmark_service_ = bookmark_service;
691 no_db_ = no_db; 688 no_db_ = no_db;
692 689
690 if (profile_ && !CommandLine::ForCurrentProcess()->HasSwitch(
691 switches::kDisableHistoryQuickProvider)) {
692 std::string languages =
693 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
694 in_memory_url_index_.reset(
695 new history::InMemoryURLIndex(profile_, history_dir_, languages));
696 in_memory_url_index_->Init();
697 }
698
693 // Create the history backend. 699 // Create the history backend.
694 LoadBackendIfNecessary(); 700 LoadBackendIfNecessary();
695 return true; 701 return true;
696 } 702 }
697 703
698 void HistoryService::ScheduleAutocomplete(HistoryURLProvider* provider, 704 void HistoryService::ScheduleAutocomplete(HistoryURLProvider* provider,
699 HistoryURLProviderParams* params) { 705 HistoryURLProviderParams* params) {
700 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::ScheduleAutocomplete, 706 ScheduleAndForget(PRIORITY_UI, &HistoryBackend::ScheduleAutocomplete,
701 scoped_refptr<HistoryURLProvider>(provider), params); 707 scoped_refptr<HistoryURLProvider>(provider), params);
702 } 708 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 history::TopSites* ts = profile_->GetTopSitesWithoutCreating(); 859 history::TopSites* ts = profile_->GetTopSitesWithoutCreating();
854 if (ts) 860 if (ts)
855 ts->MigrateFromHistory(); 861 ts->MigrateFromHistory();
856 } 862 }
857 } 863 }
858 864
859 void HistoryService::OnTopSitesReady() { 865 void HistoryService::OnTopSitesReady() {
860 ScheduleAndForget(PRIORITY_NORMAL, 866 ScheduleAndForget(PRIORITY_NORMAL,
861 &HistoryBackend::MigrateThumbnailsDatabase); 867 &HistoryBackend::MigrateThumbnailsDatabase);
862 } 868 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history.h ('k') | chrome/browser/history/history_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698