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 "components/history/core/browser/history_backend.h" | 5 #include "components/history/core/browser/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 } | 884 } |
885 | 885 |
886 // Broadcast notifications for any URLs that have changed. This will | 886 // Broadcast notifications for any URLs that have changed. This will |
887 // update the in-memory database and the InMemoryURLIndex. | 887 // update the in-memory database and the InMemoryURLIndex. |
888 if (!changed_urls.empty()) { | 888 if (!changed_urls.empty()) { |
889 NotifyURLsModified(changed_urls); | 889 NotifyURLsModified(changed_urls); |
890 ScheduleCommit(); | 890 ScheduleCommit(); |
891 } | 891 } |
892 } | 892 } |
893 | 893 |
| 894 void HistoryBackend::SetPageHistoryContext(const GURL& url, |
| 895 HistoryContext context) { |
| 896 if (!db_) |
| 897 return; |
| 898 |
| 899 // Search for recent redirects which should get the same title. We make a |
| 900 // dummy list containing the exact URL visited if there are no redirects so |
| 901 // the processing below can be the same. |
| 902 RedirectList dummy_list; |
| 903 RedirectList* redirects; |
| 904 RedirectCache::iterator iter = recent_redirects_.Get(url); |
| 905 if (iter != recent_redirects_.end()) { |
| 906 redirects = &iter->second; |
| 907 |
| 908 // This redirect chain should have the destination URL as the last item. |
| 909 DCHECK(!redirects->empty()); |
| 910 DCHECK(redirects->back() == url); |
| 911 } else { |
| 912 // No redirect chain stored, make up one containing the URL we want so we |
| 913 // can use the same logic below. |
| 914 dummy_list.push_back(url); |
| 915 redirects = &dummy_list; |
| 916 } |
| 917 |
| 918 URLRows changed_urls; |
| 919 for (size_t i = 0; i < redirects->size(); i++) { |
| 920 URLRow row; |
| 921 URLID row_id = db_->GetRowForURL(redirects->at(i), &row); |
| 922 VisitID cur_visit = db_->GetMostRecentVisitForURL(row_id, nullptr); |
| 923 if (row_id && row.context() != context) { |
| 924 row.set_context(context); |
| 925 |
| 926 VisitRow visit_row; |
| 927 if (db_->GetRowForVisit(cur_visit, &visit_row)) { |
| 928 visit_row.context = context; |
| 929 db_->UpdateVisitRow(visit_row); |
| 930 printf("\n1 HistoryBackend::SetPageHistoryContext %d\n", static_cast<int>(co
ntext)); |
| 931 } |
| 932 db_->UpdateURLRow(row_id, row); |
| 933 printf("\n2 HistoryBackend::SetPageHistoryContext %d\n", static_cast<int>(co
ntext)); |
| 934 changed_urls.push_back(row); |
| 935 } |
| 936 } |
| 937 |
| 938 // Broadcast notifications for any URLs that have changed. This will |
| 939 // update the in-memory database and the InMemoryURLIndex. |
| 940 if (!changed_urls.empty()) { |
| 941 NotifyURLsModified(changed_urls); |
| 942 ScheduleCommit(); |
| 943 } |
| 944 } |
| 945 |
894 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, | 946 void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, |
895 const base::string16& title) { | 947 const base::string16& title) { |
896 if (!db_) | 948 if (!db_) |
897 return; | 949 return; |
898 | 950 |
899 URLRow url_info(url); | 951 URLRow url_info(url); |
900 URLID url_id = db_->GetRowForURL(url, &url_info); | 952 URLID url_id = db_->GetRowForURL(url, &url_info); |
901 if (url_id) { | 953 if (url_id) { |
902 // URL is already known, nothing to do. | 954 // URL is already known, nothing to do. |
903 return; | 955 return; |
(...skipping 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2639 return true; | 2691 return true; |
2640 } | 2692 } |
2641 | 2693 |
2642 HistoryClient* HistoryBackend::GetHistoryClient() { | 2694 HistoryClient* HistoryBackend::GetHistoryClient() { |
2643 if (history_client_) | 2695 if (history_client_) |
2644 history_client_->BlockUntilBookmarksLoaded(); | 2696 history_client_->BlockUntilBookmarksLoaded(); |
2645 return history_client_; | 2697 return history_client_; |
2646 } | 2698 } |
2647 | 2699 |
2648 } // namespace history | 2700 } // namespace history |
OLD | NEW |