| 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 // Give the InMemoryURLIndex a chance to shutdown. |
| 229 if (in_memory_url_index_.get()) |
| 230 in_memory_url_index_->ShutDown(); |
| 231 |
| 232 // Close the databases before optionally running the "destroy" task. |
| 222 if (db_.get()) { | 233 if (db_.get()) { |
| 223 // Commit the long-running transaction. | 234 // Commit the long-running transaction. |
| 224 db_->CommitTransaction(); | 235 db_->CommitTransaction(); |
| 225 db_.reset(); | 236 db_.reset(); |
| 226 } | 237 } |
| 227 if (thumbnail_db_.get()) { | 238 if (thumbnail_db_.get()) { |
| 228 thumbnail_db_->CommitTransaction(); | 239 thumbnail_db_->CommitTransaction(); |
| 229 thumbnail_db_.reset(); | 240 thumbnail_db_.reset(); |
| 230 } | 241 } |
| 231 if (archived_db_.get()) { | 242 if (archived_db_.get()) { |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 // to delete the archived database and need to do so before we try to | 655 // to delete the archived database and need to do so before we try to |
| 645 // open the file. We can ignore any error (maybe the file doesn't exist). | 656 // open the file. We can ignore any error (maybe the file doesn't exist). |
| 646 file_util::Delete(archived_name, false); | 657 file_util::Delete(archived_name, false); |
| 647 } | 658 } |
| 648 archived_db_.reset(new ArchivedDatabase()); | 659 archived_db_.reset(new ArchivedDatabase()); |
| 649 if (!archived_db_->Init(archived_name)) { | 660 if (!archived_db_->Init(archived_name)) { |
| 650 LOG(WARNING) << "Could not initialize the archived database."; | 661 LOG(WARNING) << "Could not initialize the archived database."; |
| 651 archived_db_.reset(); | 662 archived_db_.reset(); |
| 652 } | 663 } |
| 653 | 664 |
| 665 if (in_memory_url_index_.get()) |
| 666 in_memory_url_index_->Init(db_.get(), languages); |
| 667 |
| 654 // Tell the expiration module about all the nice databases we made. This must | 668 // Tell the expiration module about all the nice databases we made. This must |
| 655 // happen before db_->Init() is called since the callback ForceArchiveHistory | 669 // happen before db_->Init() is called since the callback ForceArchiveHistory |
| 656 // may need to expire stuff. | 670 // may need to expire stuff. |
| 657 // | 671 // |
| 658 // *sigh*, this can all be cleaned up when that migration code is removed. | 672 // *sigh*, this can all be cleaned up when that migration code is removed. |
| 659 // The main DB initialization should intuitively be first (not that it | 673 // The main DB initialization should intuitively be first (not that it |
| 660 // actually matters) and the expirer should be set last. | 674 // actually matters) and the expirer should be set last. |
| 661 expirer_.SetDatabases(db_.get(), archived_db_.get(), | 675 expirer_.SetDatabases(db_.get(), archived_db_.get(), |
| 662 thumbnail_db_.get(), text_database_.get()); | 676 thumbnail_db_.get(), text_database_.get()); |
| 663 | 677 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 } | 892 } |
| 879 | 893 |
| 880 bool typed_url_changed = false; | 894 bool typed_url_changed = false; |
| 881 std::vector<URLRow> changed_urls; | 895 std::vector<URLRow> changed_urls; |
| 882 for (size_t i = 0; i < redirects->size(); i++) { | 896 for (size_t i = 0; i < redirects->size(); i++) { |
| 883 URLRow row; | 897 URLRow row; |
| 884 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); | 898 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); |
| 885 if (row_id && row.title() != title) { | 899 if (row_id && row.title() != title) { |
| 886 row.set_title(title); | 900 row.set_title(title); |
| 887 db_->UpdateURLRow(row_id, row); | 901 db_->UpdateURLRow(row_id, row); |
| 902 row.id_ = row_id; |
| 888 changed_urls.push_back(row); | 903 changed_urls.push_back(row); |
| 889 if (row.typed_count() > 0) | 904 if (row.typed_count() > 0) |
| 890 typed_url_changed = true; | 905 typed_url_changed = true; |
| 891 } | 906 } |
| 892 } | 907 } |
| 893 | 908 |
| 894 // Broadcast notifications for typed URLs that have changed. This will | 909 // Broadcast notifications for typed URLs that have changed. This will |
| 895 // update the in-memory database. | 910 // update the in-memory database. |
| 896 // | 911 // |
| 897 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), | 912 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), |
| (...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2301 break; | 2316 break; |
| 2302 } | 2317 } |
| 2303 } | 2318 } |
| 2304 } | 2319 } |
| 2305 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name | 2320 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name |
| 2306 TimeTicks::Now() - beginning_time); | 2321 TimeTicks::Now() - beginning_time); |
| 2307 return success; | 2322 return success; |
| 2308 } | 2323 } |
| 2309 | 2324 |
| 2310 } // namespace history | 2325 } // namespace history |
| OLD | NEW |