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