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