Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 151168: Moved typedef of RedirectList from HistoryService class to history namespace.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <set> 7 #include <set>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 } 742 }
743 743
744 void HistoryBackend::SetPageTitle(const GURL& url, 744 void HistoryBackend::SetPageTitle(const GURL& url,
745 const std::wstring& title) { 745 const std::wstring& title) {
746 if (!db_.get()) 746 if (!db_.get())
747 return; 747 return;
748 748
749 // Search for recent redirects which should get the same title. We make a 749 // Search for recent redirects which should get the same title. We make a
750 // dummy list containing the exact URL visited if there are no redirects so 750 // dummy list containing the exact URL visited if there are no redirects so
751 // the processing below can be the same. 751 // the processing below can be the same.
752 HistoryService::RedirectList dummy_list; 752 history::RedirectList dummy_list;
753 HistoryService::RedirectList* redirects; 753 history::RedirectList* redirects;
754 RedirectCache::iterator iter = recent_redirects_.Get(url); 754 RedirectCache::iterator iter = recent_redirects_.Get(url);
755 if (iter != recent_redirects_.end()) { 755 if (iter != recent_redirects_.end()) {
756 redirects = &iter->second; 756 redirects = &iter->second;
757 757
758 // This redirect chain should have the destination URL as the last item. 758 // This redirect chain should have the destination URL as the last item.
759 DCHECK(!redirects->empty()); 759 DCHECK(!redirects->empty());
760 DCHECK(redirects->back() == url); 760 DCHECK(redirects->back() == url);
761 } else { 761 } else {
762 // No redirect chain stored, make up one containing the URL we want so we 762 // No redirect chain stored, make up one containing the URL we want so we
763 // can use the same logic below. 763 // can use the same logic below.
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 1168
1169 std::vector<GURL>* top_urls = &request->value.a; 1169 std::vector<GURL>* top_urls = &request->value.a;
1170 history::RedirectMap* redirects = &request->value.b; 1170 history::RedirectMap* redirects = &request->value.b;
1171 1171
1172 std::vector<PageUsageData*> data; 1172 std::vector<PageUsageData*> data;
1173 db_->QuerySegmentUsage(base::Time::Now() - base::TimeDelta::FromDays(90), 1173 db_->QuerySegmentUsage(base::Time::Now() - base::TimeDelta::FromDays(90),
1174 result_count, &data); 1174 result_count, &data);
1175 1175
1176 for (size_t i = 0; i < data.size(); ++i) { 1176 for (size_t i = 0; i < data.size(); ++i) {
1177 top_urls->push_back(data[i]->GetURL()); 1177 top_urls->push_back(data[i]->GetURL());
1178 HistoryService::RedirectList list; 1178 history::RedirectList list;
1179 GetMostRecentRedirectsFrom(top_urls->back(), &list); 1179 GetMostRecentRedirectsFrom(top_urls->back(), &list);
1180 (*redirects)[top_urls->back()] = new RefCountedVector<GURL>(list); 1180 (*redirects)[top_urls->back()] = new RefCountedVector<GURL>(list);
1181 } 1181 }
1182 1182
1183 request->ForwardResult(QueryTopURLsAndRedirectsRequest::TupleType( 1183 request->ForwardResult(QueryTopURLsAndRedirectsRequest::TupleType(
1184 top_urls, redirects)); 1184 top_urls, redirects));
1185 } 1185 }
1186 1186
1187 void HistoryBackend::GetRedirectsFromSpecificVisit( 1187 void HistoryBackend::GetRedirectsFromSpecificVisit(
1188 VisitID cur_visit, HistoryService::RedirectList* redirects) { 1188 VisitID cur_visit, history::RedirectList* redirects) {
1189 // Follow any redirects from the given visit and add them to the list. 1189 // Follow any redirects from the given visit and add them to the list.
1190 // It *should* be impossible to get a circular chain here, but we check 1190 // It *should* be impossible to get a circular chain here, but we check
1191 // just in case to avoid infinite loops. 1191 // just in case to avoid infinite loops.
1192 GURL cur_url; 1192 GURL cur_url;
1193 std::set<VisitID> visit_set; 1193 std::set<VisitID> visit_set;
1194 visit_set.insert(cur_visit); 1194 visit_set.insert(cur_visit);
1195 while (db_->GetRedirectFromVisit(cur_visit, &cur_visit, &cur_url)) { 1195 while (db_->GetRedirectFromVisit(cur_visit, &cur_visit, &cur_url)) {
1196 if (visit_set.find(cur_visit) != visit_set.end()) { 1196 if (visit_set.find(cur_visit) != visit_set.end()) {
1197 NOTREACHED() << "Loop in visit chain, giving up"; 1197 NOTREACHED() << "Loop in visit chain, giving up";
1198 return; 1198 return;
1199 } 1199 }
1200 visit_set.insert(cur_visit); 1200 visit_set.insert(cur_visit);
1201 redirects->push_back(cur_url); 1201 redirects->push_back(cur_url);
1202 } 1202 }
1203 } 1203 }
1204 1204
1205 void HistoryBackend::GetRedirectsToSpecificVisit( 1205 void HistoryBackend::GetRedirectsToSpecificVisit(
1206 VisitID cur_visit, 1206 VisitID cur_visit,
1207 HistoryService::RedirectList* redirects) { 1207 history::RedirectList* redirects) {
1208 // Follow redirects going to cur_visit. These are added to |redirects| in 1208 // Follow redirects going to cur_visit. These are added to |redirects| in
1209 // the order they are found. If a redirect chain looks like A -> B -> C and 1209 // the order they are found. If a redirect chain looks like A -> B -> C and
1210 // |cur_visit| = C, redirects will be {B, A} in that order. 1210 // |cur_visit| = C, redirects will be {B, A} in that order.
1211 if (!db_.get()) 1211 if (!db_.get())
1212 return; 1212 return;
1213 1213
1214 GURL cur_url; 1214 GURL cur_url;
1215 std::set<VisitID> visit_set; 1215 std::set<VisitID> visit_set;
1216 visit_set.insert(cur_visit); 1216 visit_set.insert(cur_visit);
1217 while (db_->GetRedirectToVisit(cur_visit, &cur_visit, &cur_url)) { 1217 while (db_->GetRedirectToVisit(cur_visit, &cur_visit, &cur_url)) {
1218 if (visit_set.find(cur_visit) != visit_set.end()) { 1218 if (visit_set.find(cur_visit) != visit_set.end()) {
1219 NOTREACHED() << "Loop in visit chain, giving up"; 1219 NOTREACHED() << "Loop in visit chain, giving up";
1220 return; 1220 return;
1221 } 1221 }
1222 visit_set.insert(cur_visit); 1222 visit_set.insert(cur_visit);
1223 redirects->push_back(cur_url); 1223 redirects->push_back(cur_url);
1224 } 1224 }
1225 } 1225 }
1226 1226
1227 bool HistoryBackend::GetMostRecentRedirectsFrom( 1227 bool HistoryBackend::GetMostRecentRedirectsFrom(
1228 const GURL& from_url, 1228 const GURL& from_url,
1229 HistoryService::RedirectList* redirects) { 1229 history::RedirectList* redirects) {
1230 redirects->clear(); 1230 redirects->clear();
1231 if (!db_.get()) 1231 if (!db_.get())
1232 return false; 1232 return false;
1233 1233
1234 URLID from_url_id = db_->GetRowForURL(from_url, NULL); 1234 URLID from_url_id = db_->GetRowForURL(from_url, NULL);
1235 VisitID cur_visit = db_->GetMostRecentVisitForURL(from_url_id, NULL); 1235 VisitID cur_visit = db_->GetMostRecentVisitForURL(from_url_id, NULL);
1236 if (!cur_visit) 1236 if (!cur_visit)
1237 return false; // No visits for URL. 1237 return false; // No visits for URL.
1238 1238
1239 GetRedirectsFromSpecificVisit(cur_visit, redirects); 1239 GetRedirectsFromSpecificVisit(cur_visit, redirects);
1240 return true; 1240 return true;
1241 } 1241 }
1242 1242
1243 bool HistoryBackend::GetMostRecentRedirectsTo( 1243 bool HistoryBackend::GetMostRecentRedirectsTo(
1244 const GURL& to_url, 1244 const GURL& to_url,
1245 HistoryService::RedirectList* redirects) { 1245 history::RedirectList* redirects) {
1246 redirects->clear(); 1246 redirects->clear();
1247 if (!db_.get()) 1247 if (!db_.get())
1248 return false; 1248 return false;
1249 1249
1250 URLID to_url_id = db_->GetRowForURL(to_url, NULL); 1250 URLID to_url_id = db_->GetRowForURL(to_url, NULL);
1251 VisitID cur_visit = db_->GetMostRecentVisitForURL(to_url_id, NULL); 1251 VisitID cur_visit = db_->GetMostRecentVisitForURL(to_url_id, NULL);
1252 if (!cur_visit) 1252 if (!cur_visit)
1253 return false; // No visits for URL. 1253 return false; // No visits for URL.
1254 1254
1255 GetRedirectsToSpecificVisit(cur_visit, redirects); 1255 GetRedirectsToSpecificVisit(cur_visit, redirects);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 1302
1303 void HistoryBackend::GetPageThumbnailDirectly( 1303 void HistoryBackend::GetPageThumbnailDirectly(
1304 const GURL& page_url, 1304 const GURL& page_url,
1305 scoped_refptr<RefCountedBytes>* data) { 1305 scoped_refptr<RefCountedBytes>* data) {
1306 if (thumbnail_db_.get()) { 1306 if (thumbnail_db_.get()) {
1307 *data = new RefCountedBytes; 1307 *data = new RefCountedBytes;
1308 1308
1309 // Time the result. 1309 // Time the result.
1310 TimeTicks beginning_time = TimeTicks::Now(); 1310 TimeTicks beginning_time = TimeTicks::Now();
1311 1311
1312 HistoryService::RedirectList redirects; 1312 history::RedirectList redirects;
1313 URLID url_id; 1313 URLID url_id;
1314 bool success = false; 1314 bool success = false;
1315 1315
1316 // If there are some redirects, try to get a thumbnail from the last 1316 // If there are some redirects, try to get a thumbnail from the last
1317 // redirect destination. 1317 // redirect destination.
1318 if (GetMostRecentRedirectsFrom(page_url, &redirects) && 1318 if (GetMostRecentRedirectsFrom(page_url, &redirects) &&
1319 !redirects.empty()) { 1319 !redirects.empty()) {
1320 if ((url_id = db_->GetRowForURL(redirects.back(), NULL))) 1320 if ((url_id = db_->GetRowForURL(redirects.back(), NULL)))
1321 success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data); 1321 success = thumbnail_db_->GetPageThumbnail(url_id, &(*data)->data);
1322 } 1322 }
(...skipping 27 matching lines...) Expand all
1350 static const int kVisitsToSearchForThumbnail = 4; 1350 static const int kVisitsToSearchForThumbnail = 4;
1351 db_->GetMostRecentVisitsForURL( 1351 db_->GetMostRecentVisitsForURL(
1352 page_url_id, kVisitsToSearchForThumbnail, &older_sessions); 1352 page_url_id, kVisitsToSearchForThumbnail, &older_sessions);
1353 1353
1354 // Iterate across all those previous visits, and see if any of the 1354 // Iterate across all those previous visits, and see if any of the
1355 // final destinations of those redirect chains have a good thumbnail 1355 // final destinations of those redirect chains have a good thumbnail
1356 // for us. 1356 // for us.
1357 bool success = false; 1357 bool success = false;
1358 for (VisitVector::const_iterator it = older_sessions.begin(); 1358 for (VisitVector::const_iterator it = older_sessions.begin();
1359 !success && it != older_sessions.end(); ++it) { 1359 !success && it != older_sessions.end(); ++it) {
1360 HistoryService::RedirectList redirects; 1360 history::RedirectList redirects;
1361 if (it->visit_id) { 1361 if (it->visit_id) {
1362 GetRedirectsFromSpecificVisit(it->visit_id, &redirects); 1362 GetRedirectsFromSpecificVisit(it->visit_id, &redirects);
1363 1363
1364 if (!redirects.empty()) { 1364 if (!redirects.empty()) {
1365 URLID url_id; 1365 URLID url_id;
1366 if ((url_id = db_->GetRowForURL(redirects.back(), NULL))) 1366 if ((url_id = db_->GetRowForURL(redirects.back(), NULL)))
1367 success = thumbnail_db_->GetPageThumbnail(url_id, data); 1367 success = thumbnail_db_->GetPageThumbnail(url_id, data);
1368 } 1368 }
1369 } 1369 }
1370 } 1370 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 // Set the image data. 1526 // Set the image data.
1527 thumbnail_db_->SetFavIcon(id, data->data, Time::Now()); 1527 thumbnail_db_->SetFavIcon(id, data->data, Time::Now());
1528 1528
1529 SetFavIconMapping(page_url, id); 1529 SetFavIconMapping(page_url, id);
1530 } 1530 }
1531 1531
1532 void HistoryBackend::SetFavIconMapping(const GURL& page_url, 1532 void HistoryBackend::SetFavIconMapping(const GURL& page_url,
1533 FavIconID id) { 1533 FavIconID id) {
1534 // Find all the pages whose favicons we should set, we want to set it for 1534 // Find all the pages whose favicons we should set, we want to set it for
1535 // all the pages in the redirect chain if it redirected. 1535 // all the pages in the redirect chain if it redirected.
1536 HistoryService::RedirectList dummy_list; 1536 history::RedirectList dummy_list;
1537 HistoryService::RedirectList* redirects; 1537 history::RedirectList* redirects;
1538 RedirectCache::iterator iter = recent_redirects_.Get(page_url); 1538 RedirectCache::iterator iter = recent_redirects_.Get(page_url);
1539 if (iter != recent_redirects_.end()) { 1539 if (iter != recent_redirects_.end()) {
1540 redirects = &iter->second; 1540 redirects = &iter->second;
1541 1541
1542 // This redirect chain should have the destination URL as the last item. 1542 // This redirect chain should have the destination URL as the last item.
1543 DCHECK(!redirects->empty()); 1543 DCHECK(!redirects->empty());
1544 DCHECK(redirects->back() == page_url); 1544 DCHECK(redirects->back() == page_url);
1545 } else { 1545 } else {
1546 // No redirect chain stored, make up one containing the URL we want to we 1546 // No redirect chain stored, make up one containing the URL we want to we
1547 // can use the same logic below. 1547 // can use the same logic below.
1548 dummy_list.push_back(page_url); 1548 dummy_list.push_back(page_url);
1549 redirects = &dummy_list; 1549 redirects = &dummy_list;
1550 } 1550 }
1551 1551
1552 std::set<GURL> favicons_changed; 1552 std::set<GURL> favicons_changed;
1553 1553
1554 // Save page <-> favicon association. 1554 // Save page <-> favicon association.
1555 for (HistoryService::RedirectList::const_iterator i(redirects->begin()); 1555 for (history::RedirectList::const_iterator i(redirects->begin());
1556 i != redirects->end(); ++i) { 1556 i != redirects->end(); ++i) {
1557 URLRow row; 1557 URLRow row;
1558 if (!db_->GetRowForURL(*i, &row) || row.favicon_id() == id) 1558 if (!db_->GetRowForURL(*i, &row) || row.favicon_id() == id)
1559 continue; 1559 continue;
1560 1560
1561 FavIconID old_id = row.favicon_id(); 1561 FavIconID old_id = row.favicon_id();
1562 if (old_id == id) 1562 if (old_id == id)
1563 continue; 1563 continue;
1564 row.set_favicon_id(id); 1564 row.set_favicon_id(id);
1565 db_->UpdateURLRow(row.id(), row); 1565 db_->UpdateURLRow(row.id(), row);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 return true; 1937 return true;
1938 } 1938 }
1939 1939
1940 BookmarkService* HistoryBackend::GetBookmarkService() { 1940 BookmarkService* HistoryBackend::GetBookmarkService() {
1941 if (bookmark_service_) 1941 if (bookmark_service_)
1942 bookmark_service_->BlockTillLoaded(); 1942 bookmark_service_->BlockTillLoaded();
1943 return bookmark_service_; 1943 return bookmark_service_;
1944 } 1944 }
1945 1945
1946 } // namespace history 1946 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698