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

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

Issue 8120004: HQP Refactoring (in Preparation for SQLite Cache) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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
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 #include "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/history_backend.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "chrome/browser/autocomplete/history_url_provider.h" 21 #include "chrome/browser/autocomplete/history_url_provider.h"
22 #include "chrome/browser/bookmarks/bookmark_service.h" 22 #include "chrome/browser/bookmarks/bookmark_service.h"
23 #include "chrome/browser/history/history_notifications.h" 23 #include "chrome/browser/history/history_notifications.h"
24 #include "chrome/browser/history/history_publisher.h" 24 #include "chrome/browser/history/history_publisher.h"
25 #include "chrome/browser/history/in_memory_history_backend.h" 25 #include "chrome/browser/history/in_memory_history_backend.h"
26 #include "chrome/browser/history/in_memory_url_index.h"
26 #include "chrome/browser/history/page_usage_data.h" 27 #include "chrome/browser/history/page_usage_data.h"
27 #include "chrome/browser/history/top_sites.h" 28 #include "chrome/browser/history/top_sites.h"
29 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
29 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
31 #include "content/browser/download/download_persistent_store_info.h" 34 #include "content/browser/download/download_persistent_store_info.h"
32 #include "googleurl/src/gurl.h" 35 #include "googleurl/src/gurl.h"
33 #include "grit/chromium_strings.h" 36 #include "grit/chromium_strings.h"
34 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
35 #include "net/base/registry_controlled_domain.h" 38 #include "net/base/registry_controlled_domain.h"
36 39
37 using base::Time; 40 using base::Time;
38 using base::TimeDelta; 41 using base::TimeDelta;
39 using base::TimeTicks; 42 using base::TimeTicks;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 bool track_unique_; 194 bool track_unique_;
192 195
193 // When track_unique_ is set, this is updated with every URL seen so far. 196 // When track_unique_ is set, this is updated with every URL seen so far.
194 std::set<GURL> unique_urls_; 197 std::set<GURL> unique_urls_;
195 198
196 DISALLOW_COPY_AND_ASSIGN(URLQuerier); 199 DISALLOW_COPY_AND_ASSIGN(URLQuerier);
197 }; 200 };
198 201
199 // HistoryBackend -------------------------------------------------------------- 202 // HistoryBackend --------------------------------------------------------------
200 203
201 HistoryBackend::HistoryBackend(const FilePath& history_dir, 204 HistoryBackend::HistoryBackend(Profile* profile,
205 const FilePath& history_dir,
202 int id, 206 int id,
203 Delegate* delegate, 207 Delegate* delegate,
204 BookmarkService* bookmark_service) 208 BookmarkService* bookmark_service)
205 : delegate_(delegate), 209 : profile_(profile),
210 delegate_(delegate),
206 id_(id), 211 id_(id),
207 history_dir_(history_dir), 212 history_dir_(history_dir),
208 ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, bookmark_service)), 213 ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, bookmark_service)),
209 recent_redirects_(kMaxRedirectCount), 214 recent_redirects_(kMaxRedirectCount),
210 backend_destroy_message_loop_(NULL), 215 backend_destroy_message_loop_(NULL),
211 backend_destroy_task_(NULL), 216 backend_destroy_task_(NULL),
212 segment_queried_(false), 217 segment_queried_(false),
213 bookmark_service_(bookmark_service) { 218 bookmark_service_(bookmark_service) {
219 if (!CommandLine::ForCurrentProcess()->HasSwitch(
220 switches::kDisableHistoryQuickProvider)) {
Peter Kasting 2011/10/05 00:11:42 Nit: No need for {}
mrossetti 2011/10/07 17:04:14 Done.
221 in_memory_url_index_.reset(new InMemoryURLIndex(profile_, history_dir_));
222 }
214 } 223 }
215 224
216 HistoryBackend::~HistoryBackend() { 225 HistoryBackend::~HistoryBackend() {
217 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; 226 DCHECK(!scheduled_commit_) << "Deleting without cleanup";
218 ReleaseDBTasks(); 227 ReleaseDBTasks();
219 228
220 // First close the databases before optionally running the "destroy" task. 229 // First close the databases before optionally running the "destroy" task.
221 if (db_.get()) { 230 if (db_.get()) {
222 // Commit the long-running transaction. 231 // Commit the long-running transaction.
223 db_->CommitTransaction(); 232 db_->CommitTransaction();
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 // to delete the archived database and need to do so before we try to 619 // to delete the archived database and need to do so before we try to
611 // open the file. We can ignore any error (maybe the file doesn't exist). 620 // open the file. We can ignore any error (maybe the file doesn't exist).
612 file_util::Delete(archived_name, false); 621 file_util::Delete(archived_name, false);
613 } 622 }
614 archived_db_.reset(new ArchivedDatabase()); 623 archived_db_.reset(new ArchivedDatabase());
615 if (!archived_db_->Init(archived_name)) { 624 if (!archived_db_->Init(archived_name)) {
616 LOG(WARNING) << "Could not initialize the archived database."; 625 LOG(WARNING) << "Could not initialize the archived database.";
617 archived_db_.reset(); 626 archived_db_.reset();
618 } 627 }
619 628
629 if (in_memory_url_index_.get())
630 in_memory_url_index_->Init(db_.get(), languages);
631
620 // Tell the expiration module about all the nice databases we made. This must 632 // Tell the expiration module about all the nice databases we made. This must
621 // happen before db_->Init() is called since the callback ForceArchiveHistory 633 // happen before db_->Init() is called since the callback ForceArchiveHistory
622 // may need to expire stuff. 634 // may need to expire stuff.
623 // 635 //
624 // *sigh*, this can all be cleaned up when that migration code is removed. 636 // *sigh*, this can all be cleaned up when that migration code is removed.
625 // The main DB initialization should intuitively be first (not that it 637 // The main DB initialization should intuitively be first (not that it
626 // actually matters) and the expirer should be set last. 638 // actually matters) and the expirer should be set last.
627 expirer_.SetDatabases(db_.get(), archived_db_.get(), 639 expirer_.SetDatabases(db_.get(), archived_db_.get(),
628 thumbnail_db_.get(), text_database_.get()); 640 thumbnail_db_.get(), text_database_.get());
629 641
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 } 853 }
842 854
843 bool typed_url_changed = false; 855 bool typed_url_changed = false;
844 std::vector<URLRow> changed_urls; 856 std::vector<URLRow> changed_urls;
845 for (size_t i = 0; i < redirects->size(); i++) { 857 for (size_t i = 0; i < redirects->size(); i++) {
846 URLRow row; 858 URLRow row;
847 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); 859 URLID row_id = db_->GetRowForURL(redirects->at(i), &row);
848 if (row_id && row.title() != title) { 860 if (row_id && row.title() != title) {
849 row.set_title(title); 861 row.set_title(title);
850 db_->UpdateURLRow(row_id, row); 862 db_->UpdateURLRow(row_id, row);
863 row.id_ = row_id;
851 changed_urls.push_back(row); 864 changed_urls.push_back(row);
852 if (row.typed_count() > 0) 865 if (row.typed_count() > 0)
853 typed_url_changed = true; 866 typed_url_changed = true;
854 } 867 }
855 } 868 }
856 869
857 // Broadcast notifications for typed URLs that have changed. This will 870 // Broadcast notifications for typed URLs that have changed. This will
858 // update the in-memory database. 871 // update the in-memory database.
859 // 872 //
860 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), 873 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed),
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 break; 2284 break;
2272 } 2285 }
2273 } 2286 }
2274 } 2287 }
2275 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name 2288 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name
2276 TimeTicks::Now() - beginning_time); 2289 TimeTicks::Now() - beginning_time);
2277 return success; 2290 return success;
2278 } 2291 }
2279 2292
2280 } // namespace history 2293 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698