| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 if (visit_info.visit_time < first_recorded_time_) | 867 if (visit_info.visit_time < first_recorded_time_) |
| 868 first_recorded_time_ = visit_info.visit_time; | 868 first_recorded_time_ = visit_info.visit_time; |
| 869 } | 869 } |
| 870 } | 870 } |
| 871 | 871 |
| 872 // Broadcast a notification for typed URLs that have been modified. This | 872 // Broadcast a notification for typed URLs that have been modified. This |
| 873 // will be picked up by the in-memory URL database on the main thread. | 873 // will be picked up by the in-memory URL database on the main thread. |
| 874 // | 874 // |
| 875 // TODO(brettw) bug 1140015: Add an "add page" notification so the history | 875 // TODO(brettw) bug 1140015: Add an "add page" notification so the history |
| 876 // views can keep in sync. | 876 // views can keep in sync. |
| 877 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, | 877 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 878 modified.release()); | 878 modified.release()); |
| 879 | 879 |
| 880 ScheduleCommit(); | 880 ScheduleCommit(); |
| 881 } | 881 } |
| 882 | 882 |
| 883 bool HistoryBackend::IsExpiredVisitTime(const base::Time& time) { | 883 bool HistoryBackend::IsExpiredVisitTime(const base::Time& time) { |
| 884 return time < expirer_.GetCurrentArchiveTime(); | 884 return time < expirer_.GetCurrentArchiveTime(); |
| 885 } | 885 } |
| 886 | 886 |
| 887 void HistoryBackend::SetPageTitle(const GURL& url, | 887 void HistoryBackend::SetPageTitle(const GURL& url, |
| 888 const string16& title) { | 888 const string16& title) { |
| 889 if (!db_.get()) | 889 if (!db_.get()) |
| 890 return; | 890 return; |
| 891 | 891 |
| 892 // Update the full text index. |
| 893 if (text_database_.get()) |
| 894 text_database_->AddPageTitle(url, title); |
| 895 |
| 892 // Search for recent redirects which should get the same title. We make a | 896 // Search for recent redirects which should get the same title. We make a |
| 893 // dummy list containing the exact URL visited if there are no redirects so | 897 // dummy list containing the exact URL visited if there are no redirects so |
| 894 // the processing below can be the same. | 898 // the processing below can be the same. |
| 895 history::RedirectList dummy_list; | 899 history::RedirectList dummy_list; |
| 896 history::RedirectList* redirects; | 900 history::RedirectList* redirects; |
| 897 RedirectCache::iterator iter = recent_redirects_.Get(url); | 901 RedirectCache::iterator iter = recent_redirects_.Get(url); |
| 898 if (iter != recent_redirects_.end()) { | 902 if (iter != recent_redirects_.end()) { |
| 899 redirects = &iter->second; | 903 redirects = &iter->second; |
| 900 | 904 |
| 901 // This redirect chain should have the destination URL as the last item. | 905 // This redirect chain should have the destination URL as the last item. |
| 902 DCHECK(!redirects->empty()); | 906 DCHECK(!redirects->empty()); |
| 903 DCHECK(redirects->back() == url); | 907 DCHECK(redirects->back() == url); |
| 904 } else { | 908 } else { |
| 905 // No redirect chain stored, make up one containing the URL we want so we | 909 // No redirect chain stored, make up one containing the URL we want so we |
| 906 // can use the same logic below. | 910 // can use the same logic below. |
| 907 dummy_list.push_back(url); | 911 dummy_list.push_back(url); |
| 908 redirects = &dummy_list; | 912 redirects = &dummy_list; |
| 909 } | 913 } |
| 910 | 914 |
| 911 bool typed_url_changed = false; | 915 scoped_ptr<URLsModifiedDetails> details(new URLsModifiedDetails); |
| 912 URLRows changed_urls; | |
| 913 for (size_t i = 0; i < redirects->size(); i++) { | 916 for (size_t i = 0; i < redirects->size(); i++) { |
| 914 URLRow row; | 917 URLRow row; |
| 915 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); | 918 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); |
| 916 if (row_id && row.title() != title) { | 919 if (row_id && row.title() != title) { |
| 917 row.set_title(title); | 920 row.set_title(title); |
| 918 db_->UpdateURLRow(row_id, row); | 921 db_->UpdateURLRow(row_id, row); |
| 919 changed_urls.push_back(row); | 922 details->changed_urls.push_back(row); |
| 920 if (row.typed_count() > 0) | |
| 921 typed_url_changed = true; | |
| 922 } | 923 } |
| 923 } | 924 } |
| 924 | 925 |
| 925 // Broadcast notifications for typed URLs that have changed. This will | 926 // Broadcast notifications for any URLs that have changed. This will |
| 926 // update the in-memory database. | 927 // update the in-memory database and the InMemoryURLIndex. |
| 927 // | 928 if (!details->changed_urls.empty()) { |
| 928 // TODO(brettw) bug 1140020: Broadcast for all changes (not just typed), | 929 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_MODIFIED, |
| 929 // in which case some logic can be removed. | 930 details.release()); |
| 930 if (typed_url_changed) { | 931 ScheduleCommit(); |
| 931 URLsModifiedDetails* modified = | |
| 932 new URLsModifiedDetails; | |
| 933 for (size_t i = 0; i < changed_urls.size(); i++) { | |
| 934 if (changed_urls[i].typed_count() > 0) | |
| 935 modified->changed_urls.push_back(changed_urls[i]); | |
| 936 } | |
| 937 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED, | |
| 938 modified); | |
| 939 } | 932 } |
| 940 | |
| 941 // Update the full text index. | |
| 942 if (text_database_.get()) | |
| 943 text_database_->AddPageTitle(url, title); | |
| 944 | |
| 945 // Only bother committing if things changed. | |
| 946 if (!changed_urls.empty()) | |
| 947 ScheduleCommit(); | |
| 948 } | 933 } |
| 949 | 934 |
| 950 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url) { | 935 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url) { |
| 951 if (!db_.get()) | 936 if (!db_.get()) |
| 952 return; | 937 return; |
| 953 | 938 |
| 954 URLRow url_info(url); | 939 URLRow url_info(url); |
| 955 URLID url_id = db_->GetRowForURL(url, &url_info); | 940 URLID url_id = db_->GetRowForURL(url, &url_info); |
| 956 if (url_id) { | 941 if (url_id) { |
| 957 // URL is already known, nothing to do. | 942 // URL is already known, nothing to do. |
| (...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2486 return false; | 2471 return false; |
| 2487 | 2472 |
| 2488 favicon->expired = (Time::Now() - last_updated) > | 2473 favicon->expired = (Time::Now() - last_updated) > |
| 2489 TimeDelta::FromDays(kFaviconRefetchDays); | 2474 TimeDelta::FromDays(kFaviconRefetchDays); |
| 2490 favicon->known_icon = true; | 2475 favicon->known_icon = true; |
| 2491 favicon->image_data = data; | 2476 favicon->image_data = data; |
| 2492 return true; | 2477 return true; |
| 2493 } | 2478 } |
| 2494 | 2479 |
| 2495 } // namespace history | 2480 } // namespace history |
| OLD | NEW |