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

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

Issue 10115001: Added page score to the ntp suggestions tab. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } else { 102 } else {
103 mv.redirects = redirects; 103 mv.redirects = redirects;
104 if (mv.redirects[mv.redirects.size() - 1] != mv.url) { 104 if (mv.redirects[mv.redirects.size() - 1] != mv.url) {
105 // The last url must be the target url. 105 // The last url must be the target url.
106 mv.redirects.push_back(mv.url); 106 mv.redirects.push_back(mv.url);
107 } 107 }
108 } 108 }
109 return mv; 109 return mv;
110 } 110 }
111 111
112 // Converts from PageUsageData to FilteredURL.
113 FilteredURL MakeFilteredURL(const PageUsageData& page_data) {
GeorgeY 2012/04/19 01:16:24 May be add an explicit constructor explicit Filte
Rune Fevang 2012/04/25 00:52:45 Done.
114 FilteredURL filtered_url;
115 filtered_url.url = page_data.GetURL();
116 filtered_url.title = page_data.GetTitle();
117 filtered_url.score = page_data.GetScore();
118 return filtered_url;
119 }
120
112 // This task is run on a timer so that commits happen at regular intervals 121 // This task is run on a timer so that commits happen at regular intervals
113 // so they are batched together. The important thing about this class is that 122 // so they are batched together. The important thing about this class is that
114 // it supports canceling of the task so the reference to the backend will be 123 // it supports canceling of the task so the reference to the backend will be
115 // freed. The problem is that when history is shutting down, there is likely 124 // freed. The problem is that when history is shutting down, there is likely
116 // to be one of these commits still pending and holding a reference. 125 // to be one of these commits still pending and holding a reference.
117 // 126 //
118 // The backend can call Cancel to have this task release the reference. The 127 // The backend can call Cancel to have this task release the reference. The
119 // task will still run (if we ever get to processing the event before 128 // task will still run (if we ever get to processing the event before
120 // shutdown), but it will not do anything. 129 // shutdown), but it will not do anything.
121 // 130 //
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 request->ForwardResult(request->handle(), MostVisitedURLList()); 1431 request->ForwardResult(request->handle(), MostVisitedURLList());
1423 return; 1432 return;
1424 } 1433 }
1425 1434
1426 MostVisitedURLList* result = &request->value; 1435 MostVisitedURLList* result = &request->value;
1427 QueryMostVisitedURLsImpl(result_count, days_back, result); 1436 QueryMostVisitedURLsImpl(result_count, days_back, result);
1428 request->ForwardResult(request->handle(), *result); 1437 request->ForwardResult(request->handle(), *result);
1429 } 1438 }
1430 1439
1431 void HistoryBackend::QueryFilteredURLs( 1440 void HistoryBackend::QueryFilteredURLs(
1432 scoped_refptr<QueryMostVisitedURLsRequest> request, 1441 scoped_refptr<QueryFilteredURLsRequest> request,
1433 int result_count, 1442 int result_count,
1434 const history::VisitFilter& filter) { 1443 const history::VisitFilter& filter) {
1435 if (request->canceled()) 1444 if (request->canceled())
1436 return; 1445 return;
1437 1446
1438 base::Time request_start = base::Time::Now(); 1447 base::Time request_start = base::Time::Now();
1439 1448
1440 if (!db_.get()) { 1449 if (!db_.get()) {
1441 // No History Database - return an empty list. 1450 // No History Database - return an empty list.
1442 request->ForwardResult(request->handle(), MostVisitedURLList()); 1451 request->ForwardResult(request->handle(),FilteredURLList());
1443 return; 1452 return;
1444 } 1453 }
1445 1454
1446 VisitVector visits; 1455 VisitVector visits;
1447 db_->GetVisibleVisitsDuringTimes(filter, 0, &visits); 1456 db_->GetVisibleVisitsDuringTimes(filter, 0, &visits);
1448 1457
1449 std::map<VisitID, std::pair<VisitID, URLID> > segment_ids; 1458 std::map<VisitID, std::pair<VisitID, URLID> > segment_ids;
1450 for (size_t i = 0; i < visits.size(); ++i) { 1459 for (size_t i = 0; i < visits.size(); ++i) {
1451 segment_ids[visits[i].visit_id] = 1460 segment_ids[visits[i].visit_id] =
1452 std::make_pair(visits[i].referring_visit, visits[i].segment_id); 1461 std::make_pair(visits[i].referring_visit, visits[i].segment_id);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 // Get URL data. 1531 // Get URL data.
1523 for (size_t i = 0; i < data.size(); ++i) { 1532 for (size_t i = 0; i < data.size(); ++i) {
1524 URLID url_id = db_->GetSegmentRepresentationURL(data[i]->GetID()); 1533 URLID url_id = db_->GetSegmentRepresentationURL(data[i]->GetID());
1525 URLRow info; 1534 URLRow info;
1526 if (db_->GetURLRow(url_id, &info)) { 1535 if (db_->GetURLRow(url_id, &info)) {
1527 data[i]->SetURL(info.url()); 1536 data[i]->SetURL(info.url());
1528 data[i]->SetTitle(info.title()); 1537 data[i]->SetTitle(info.title());
1529 } 1538 }
1530 } 1539 }
1531 1540
1532 MostVisitedURLList& result = request->value; 1541 FilteredURLList& result = request->value;
1533 for (size_t i = 0; i < data.size(); ++i) { 1542 for (size_t i = 0; i < data.size(); ++i) {
1534 PageUsageData* current_data = data[i]; 1543 PageUsageData* current_data = data[i];
1535 RedirectList redirects; 1544 FilteredURL url = MakeFilteredURL(*current_data);
1536 GetMostRecentRedirectsFrom(current_data->GetURL(), &redirects);
1537 MostVisitedURL url = MakeMostVisitedURL(*current_data, redirects);
1538 result.push_back(url); 1545 result.push_back(url);
1539 } 1546 }
1540 1547
1541 int delta_time = std::max(1, std::min(999, 1548 int delta_time = std::max(1, std::min(999,
1542 static_cast<int>((base::Time::Now() - request_start).InMilliseconds()))); 1549 static_cast<int>((base::Time::Now() - request_start).InMilliseconds())));
1543 STATIC_HISTOGRAM_POINTER_BLOCK( 1550 STATIC_HISTOGRAM_POINTER_BLOCK(
1544 "NewTabPage.SuggestedSitesLoadTime", 1551 "NewTabPage.SuggestedSitesLoadTime",
1545 Add(delta_time), 1552 Add(delta_time),
1546 base::LinearHistogram::FactoryGet("NewTabPage.SuggestedSitesLoadTime", 1553 base::LinearHistogram::FactoryGet("NewTabPage.SuggestedSitesLoadTime",
1547 1, 1000, 100, base::Histogram::kUmaTargetedHistogramFlag)); 1554 1, 1000, 100, base::Histogram::kUmaTargetedHistogramFlag));
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 return false; 2478 return false;
2472 2479
2473 favicon->expired = (Time::Now() - last_updated) > 2480 favicon->expired = (Time::Now() - last_updated) >
2474 TimeDelta::FromDays(kFaviconRefetchDays); 2481 TimeDelta::FromDays(kFaviconRefetchDays);
2475 favicon->known_icon = true; 2482 favicon->known_icon = true;
2476 favicon->image_data = data; 2483 favicon->image_data = data;
2477 return true; 2484 return true;
2478 } 2485 }
2479 2486
2480 } // namespace history 2487 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698