| 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/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 Loading... |
| 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 : delegate_(delegate), |
| 206 id_(id), | 210 id_(id), |
| 207 history_dir_(history_dir), | 211 history_dir_(history_dir), |
| 208 ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, bookmark_service)), | 212 ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, bookmark_service)), |
| 209 recent_redirects_(kMaxRedirectCount), | 213 recent_redirects_(kMaxRedirectCount), |
| 210 backend_destroy_message_loop_(NULL), | 214 backend_destroy_message_loop_(NULL), |
| 211 backend_destroy_task_(NULL), | 215 backend_destroy_task_(NULL), |
| 212 segment_queried_(false), | 216 segment_queried_(false), |
| 213 bookmark_service_(bookmark_service) { | 217 bookmark_service_(bookmark_service) { |
| 218 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 219 switches::kDisableHistoryQuickProvider)) |
| 220 in_memory_url_index_.reset(new InMemoryURLIndex(profile, history_dir_)); |
| 214 } | 221 } |
| 215 | 222 |
| 216 HistoryBackend::~HistoryBackend() { | 223 HistoryBackend::~HistoryBackend() { |
| 217 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; | 224 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; |
| 218 ReleaseDBTasks(); | 225 ReleaseDBTasks(); |
| 219 | 226 |
| 220 // First close the databases before optionally running the "destroy" task. | 227 // First close the databases before optionally running the "destroy" task. |
| 221 if (db_.get()) { | 228 if (db_.get()) { |
| 222 // Commit the long-running transaction. | 229 // Commit the long-running transaction. |
| 223 db_->CommitTransaction(); | 230 db_->CommitTransaction(); |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 // to delete the archived database and need to do so before we try to | 617 // 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). | 618 // open the file. We can ignore any error (maybe the file doesn't exist). |
| 612 file_util::Delete(archived_name, false); | 619 file_util::Delete(archived_name, false); |
| 613 } | 620 } |
| 614 archived_db_.reset(new ArchivedDatabase()); | 621 archived_db_.reset(new ArchivedDatabase()); |
| 615 if (!archived_db_->Init(archived_name)) { | 622 if (!archived_db_->Init(archived_name)) { |
| 616 LOG(WARNING) << "Could not initialize the archived database."; | 623 LOG(WARNING) << "Could not initialize the archived database."; |
| 617 archived_db_.reset(); | 624 archived_db_.reset(); |
| 618 } | 625 } |
| 619 | 626 |
| 627 if (in_memory_url_index_.get()) |
| 628 in_memory_url_index_->Init(db_.get(), languages); |
| 629 |
| 620 // Tell the expiration module about all the nice databases we made. This must | 630 // Tell the expiration module about all the nice databases we made. This must |
| 621 // happen before db_->Init() is called since the callback ForceArchiveHistory | 631 // happen before db_->Init() is called since the callback ForceArchiveHistory |
| 622 // may need to expire stuff. | 632 // may need to expire stuff. |
| 623 // | 633 // |
| 624 // *sigh*, this can all be cleaned up when that migration code is removed. | 634 // *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 | 635 // The main DB initialization should intuitively be first (not that it |
| 626 // actually matters) and the expirer should be set last. | 636 // actually matters) and the expirer should be set last. |
| 627 expirer_.SetDatabases(db_.get(), archived_db_.get(), | 637 expirer_.SetDatabases(db_.get(), archived_db_.get(), |
| 628 thumbnail_db_.get(), text_database_.get()); | 638 thumbnail_db_.get(), text_database_.get()); |
| 629 | 639 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 | 766 |
| 757 URLRow existing_url; | 767 URLRow existing_url; |
| 758 URLID url_id = url_database->GetRowForURL(i->url(), &existing_url); | 768 URLID url_id = url_database->GetRowForURL(i->url(), &existing_url); |
| 759 if (!url_id) { | 769 if (!url_id) { |
| 760 // Add the page if it doesn't exist. | 770 // Add the page if it doesn't exist. |
| 761 url_id = url_database->AddURL(*i); | 771 url_id = url_database->AddURL(*i); |
| 762 if (!url_id) { | 772 if (!url_id) { |
| 763 NOTREACHED() << "Could not add row to DB"; | 773 NOTREACHED() << "Could not add row to DB"; |
| 764 return; | 774 return; |
| 765 } | 775 } |
| 766 | |
| 767 if (i->typed_count() > 0) | 776 if (i->typed_count() > 0) |
| 768 modified->changed_urls.push_back(*i); | 777 modified->changed_urls.push_back(*i); |
| 769 } | 778 } |
| 770 | 779 |
| 771 // Add the page to the full text index. This function is also used for | 780 // Add the page to the full text index. This function is also used for |
| 772 // importing. Even though we don't have page contents, we can at least | 781 // importing. Even though we don't have page contents, we can at least |
| 773 // add the title and URL to the index so they can be searched. We don't | 782 // add the title and URL to the index so they can be searched. We don't |
| 774 // bother to delete any already-existing FTS entries for the URL, since | 783 // bother to delete any already-existing FTS entries for the URL, since |
| 775 // this is normally called on import. | 784 // this is normally called on import. |
| 776 // | 785 // |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } | 850 } |
| 842 | 851 |
| 843 bool typed_url_changed = false; | 852 bool typed_url_changed = false; |
| 844 std::vector<URLRow> changed_urls; | 853 std::vector<URLRow> changed_urls; |
| 845 for (size_t i = 0; i < redirects->size(); i++) { | 854 for (size_t i = 0; i < redirects->size(); i++) { |
| 846 URLRow row; | 855 URLRow row; |
| 847 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); | 856 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); |
| 848 if (row_id && row.title() != title) { | 857 if (row_id && row.title() != title) { |
| 849 row.set_title(title); | 858 row.set_title(title); |
| 850 db_->UpdateURLRow(row_id, row); | 859 db_->UpdateURLRow(row_id, row); |
| 860 row.id_ = row_id; |
| 851 changed_urls.push_back(row); | 861 changed_urls.push_back(row); |
| 852 if (row.typed_count() > 0) | 862 if (row.typed_count() > 0) |
| 853 typed_url_changed = true; | 863 typed_url_changed = true; |
| 854 } | 864 } |
| 855 } | 865 } |
| 856 | 866 |
| 857 // Broadcast notifications for typed URLs that have changed. This will | 867 // Broadcast notifications for typed URLs that have changed. This will |
| 858 // update the in-memory database. | 868 // update the in-memory database. |
| 859 // | 869 // |
| 860 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), | 870 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), |
| (...skipping 1410 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 |