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

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

Issue 8275004: Revert 105300 - 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"
27 #include "chrome/browser/history/page_usage_data.h" 26 #include "chrome/browser/history/page_usage_data.h"
28 #include "chrome/browser/history/top_sites.h" 27 #include "chrome/browser/history/top_sites.h"
29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
34 #include "content/browser/cancelable_request.h" 31 #include "content/browser/cancelable_request.h"
35 #include "content/browser/download/download_persistent_store_info.h" 32 #include "content/browser/download/download_persistent_store_info.h"
36 #include "googleurl/src/gurl.h" 33 #include "googleurl/src/gurl.h"
37 #include "grit/chromium_strings.h" 34 #include "grit/chromium_strings.h"
38 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
39 #include "net/base/registry_controlled_domain.h" 36 #include "net/base/registry_controlled_domain.h"
40 37
41 using base::Time; 38 using base::Time;
42 using base::TimeDelta; 39 using base::TimeDelta;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 bool track_unique_; 192 bool track_unique_;
196 193
197 // When track_unique_ is set, this is updated with every URL seen so far. 194 // When track_unique_ is set, this is updated with every URL seen so far.
198 std::set<GURL> unique_urls_; 195 std::set<GURL> unique_urls_;
199 196
200 DISALLOW_COPY_AND_ASSIGN(URLQuerier); 197 DISALLOW_COPY_AND_ASSIGN(URLQuerier);
201 }; 198 };
202 199
203 // HistoryBackend -------------------------------------------------------------- 200 // HistoryBackend --------------------------------------------------------------
204 201
205 HistoryBackend::HistoryBackend(Profile* profile, 202 HistoryBackend::HistoryBackend(const FilePath& history_dir,
206 const FilePath& history_dir,
207 int id, 203 int id,
208 Delegate* delegate, 204 Delegate* delegate,
209 BookmarkService* bookmark_service) 205 BookmarkService* bookmark_service)
210 : delegate_(delegate), 206 : delegate_(delegate),
211 id_(id), 207 id_(id),
212 history_dir_(history_dir), 208 history_dir_(history_dir),
213 ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, bookmark_service)), 209 ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, bookmark_service)),
214 recent_redirects_(kMaxRedirectCount), 210 recent_redirects_(kMaxRedirectCount),
215 backend_destroy_message_loop_(NULL), 211 backend_destroy_message_loop_(NULL),
216 backend_destroy_task_(NULL), 212 backend_destroy_task_(NULL),
217 segment_queried_(false), 213 segment_queried_(false),
218 bookmark_service_(bookmark_service) { 214 bookmark_service_(bookmark_service) {
219 if (!CommandLine::ForCurrentProcess()->HasSwitch(
220 switches::kDisableHistoryQuickProvider))
221 in_memory_url_index_.reset(new InMemoryURLIndex(profile, history_dir_));
222 } 215 }
223 216
224 HistoryBackend::~HistoryBackend() { 217 HistoryBackend::~HistoryBackend() {
225 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; 218 DCHECK(!scheduled_commit_) << "Deleting without cleanup";
226 ReleaseDBTasks(); 219 ReleaseDBTasks();
227 220
228 // First close the databases before optionally running the "destroy" task. 221 // First close the databases before optionally running the "destroy" task.
229 if (db_.get()) { 222 if (db_.get()) {
230 // Commit the long-running transaction. 223 // Commit the long-running transaction.
231 db_->CommitTransaction(); 224 db_->CommitTransaction();
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 // to delete the archived database and need to do so before we try to 623 // to delete the archived database and need to do so before we try to
631 // open the file. We can ignore any error (maybe the file doesn't exist). 624 // open the file. We can ignore any error (maybe the file doesn't exist).
632 file_util::Delete(archived_name, false); 625 file_util::Delete(archived_name, false);
633 } 626 }
634 archived_db_.reset(new ArchivedDatabase()); 627 archived_db_.reset(new ArchivedDatabase());
635 if (!archived_db_->Init(archived_name)) { 628 if (!archived_db_->Init(archived_name)) {
636 LOG(WARNING) << "Could not initialize the archived database."; 629 LOG(WARNING) << "Could not initialize the archived database.";
637 archived_db_.reset(); 630 archived_db_.reset();
638 } 631 }
639 632
640 if (in_memory_url_index_.get())
641 in_memory_url_index_->Init(db_.get(), languages);
642
643 // Tell the expiration module about all the nice databases we made. This must 633 // Tell the expiration module about all the nice databases we made. This must
644 // happen before db_->Init() is called since the callback ForceArchiveHistory 634 // happen before db_->Init() is called since the callback ForceArchiveHistory
645 // may need to expire stuff. 635 // may need to expire stuff.
646 // 636 //
647 // *sigh*, this can all be cleaned up when that migration code is removed. 637 // *sigh*, this can all be cleaned up when that migration code is removed.
648 // The main DB initialization should intuitively be first (not that it 638 // The main DB initialization should intuitively be first (not that it
649 // actually matters) and the expirer should be set last. 639 // actually matters) and the expirer should be set last.
650 expirer_.SetDatabases(db_.get(), archived_db_.get(), 640 expirer_.SetDatabases(db_.get(), archived_db_.get(),
651 thumbnail_db_.get(), text_database_.get()); 641 thumbnail_db_.get(), text_database_.get());
652 642
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 770
781 URLRow existing_url; 771 URLRow existing_url;
782 URLID url_id = url_database->GetRowForURL(i->url(), &existing_url); 772 URLID url_id = url_database->GetRowForURL(i->url(), &existing_url);
783 if (!url_id) { 773 if (!url_id) {
784 // Add the page if it doesn't exist. 774 // Add the page if it doesn't exist.
785 url_id = url_database->AddURL(*i); 775 url_id = url_database->AddURL(*i);
786 if (!url_id) { 776 if (!url_id) {
787 NOTREACHED() << "Could not add row to DB"; 777 NOTREACHED() << "Could not add row to DB";
788 return; 778 return;
789 } 779 }
780
790 if (i->typed_count() > 0) 781 if (i->typed_count() > 0)
791 modified->changed_urls.push_back(*i); 782 modified->changed_urls.push_back(*i);
792 } 783 }
793 784
794 // Add the page to the full text index. This function is also used for 785 // Add the page to the full text index. This function is also used for
795 // importing. Even though we don't have page contents, we can at least 786 // importing. Even though we don't have page contents, we can at least
796 // add the title and URL to the index so they can be searched. We don't 787 // add the title and URL to the index so they can be searched. We don't
797 // bother to delete any already-existing FTS entries for the URL, since 788 // bother to delete any already-existing FTS entries for the URL, since
798 // this is normally called on import. 789 // this is normally called on import.
799 // 790 //
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 } 857 }
867 858
868 bool typed_url_changed = false; 859 bool typed_url_changed = false;
869 std::vector<URLRow> changed_urls; 860 std::vector<URLRow> changed_urls;
870 for (size_t i = 0; i < redirects->size(); i++) { 861 for (size_t i = 0; i < redirects->size(); i++) {
871 URLRow row; 862 URLRow row;
872 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); 863 URLID row_id = db_->GetRowForURL(redirects->at(i), &row);
873 if (row_id && row.title() != title) { 864 if (row_id && row.title() != title) {
874 row.set_title(title); 865 row.set_title(title);
875 db_->UpdateURLRow(row_id, row); 866 db_->UpdateURLRow(row_id, row);
876 row.id_ = row_id;
877 changed_urls.push_back(row); 867 changed_urls.push_back(row);
878 if (row.typed_count() > 0) 868 if (row.typed_count() > 0)
879 typed_url_changed = true; 869 typed_url_changed = true;
880 } 870 }
881 } 871 }
882 872
883 // Broadcast notifications for typed URLs that have changed. This will 873 // Broadcast notifications for typed URLs that have changed. This will
884 // update the in-memory database. 874 // update the in-memory database.
885 // 875 //
886 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), 876 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed),
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 break; 2271 break;
2282 } 2272 }
2283 } 2273 }
2284 } 2274 }
2285 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name 2275 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name
2286 TimeTicks::Now() - beginning_time); 2276 TimeTicks::Now() - beginning_time);
2287 return success; 2277 return success;
2288 } 2278 }
2289 2279
2290 } // namespace history 2280 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698