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

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2338133006: [NTP] Fix article suggestion clicks contributing to Most Visited tiles (Closed)
Patch Set: Moved URL to constant. Created 4 years, 3 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 "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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 VisitDatabase (stores a list of visits for the URLs) 64 VisitDatabase (stores a list of visits for the URLs)
65 VisitSegmentDatabase (stores groups of URLs for the most visited view). 65 VisitSegmentDatabase (stores groups of URLs for the most visited view).
66 66
67 ExpireHistoryBackend (manages deleting things older than 3 months) 67 ExpireHistoryBackend (manages deleting things older than 3 months)
68 */ 68 */
69 69
70 namespace history { 70 namespace history {
71 71
72 namespace { 72 namespace {
73 73
74 // Referrer used for clicks on article suggestions on the NTP.
75 const char kChromeContentSuggestionsReferrer[] =
76 "https://www.googleapis.com/auth/chrome-content-suggestions";
sky 2016/09/15 17:46:26 I like this approach much better, but I don't want
mastiz 2016/09/15 18:12:07 Would you be fine if we instead verify the referre
77
74 void RunUnlessCanceled( 78 void RunUnlessCanceled(
75 const base::Closure& closure, 79 const base::Closure& closure,
76 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { 80 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) {
77 if (!is_canceled.Run()) 81 if (!is_canceled.Run())
78 closure.Run(); 82 closure.Run();
79 } 83 }
80 84
81 } // namespace 85 } // namespace
82 86
83 // How long we'll wait to do a commit, so that things are batched together. 87 // How long we'll wait to do a commit, so that things are batched together.
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 if (visit_set.find(visit_id) != visit_set.end()) { 312 if (visit_set.find(visit_id) != visit_set.end()) {
309 NOTREACHED() << "Loop in referer chain, giving up"; 313 NOTREACHED() << "Loop in referer chain, giving up";
310 break; 314 break;
311 } 315 }
312 visit_set.insert(visit_id); 316 visit_set.insert(visit_id);
313 } 317 }
314 return 0; 318 return 0;
315 } 319 }
316 320
317 SegmentID HistoryBackend::UpdateSegments(const GURL& url, 321 SegmentID HistoryBackend::UpdateSegments(const GURL& url,
322 const GURL& referrer,
318 VisitID from_visit, 323 VisitID from_visit,
319 VisitID visit_id, 324 VisitID visit_id,
320 ui::PageTransition transition_type, 325 ui::PageTransition transition_type,
321 const Time ts) { 326 const Time ts) {
322 if (!db_) 327 if (!db_)
323 return 0; 328 return 0;
324 329
325 // We only consider main frames. 330 // We only consider main frames.
326 if (!ui::PageTransitionIsMainFrame(transition_type)) 331 if (!ui::PageTransitionIsMainFrame(transition_type))
327 return 0; 332 return 0;
328 333
329 SegmentID segment_id = 0; 334 SegmentID segment_id = 0;
330 335
331 // Are we at the beginning of a new segment? 336 // Are we at the beginning of a new segment?
332 // Note that navigating to an existing entry (with back/forward) reuses the 337 // Note that navigating to an existing entry (with back/forward) reuses the
333 // same transition type. We are not adding it as a new segment in that case 338 // same transition type. We are not adding it as a new segment in that case
334 // because if this was the target of a redirect, we might end up with 339 // because if this was the target of a redirect, we might end up with
335 // 2 entries for the same final URL. Ex: User types google.net, gets 340 // 2 entries for the same final URL. Ex: User types google.net, gets
336 // redirected to google.com. A segment is created for google.net. On 341 // redirected to google.com. A segment is created for google.net. On
337 // google.com users navigates through a link, then press back. That last 342 // google.com users navigates through a link, then press back. That last
338 // navigation is for the entry google.com transition typed. We end up adding 343 // navigation is for the entry google.com transition typed. We end up adding
339 // a segment for that one as well. So we end up with google.net and google.com 344 // a segment for that one as well. So we end up with google.net and google.com
340 // in the segment table, showing as 2 entries in the NTP. 345 // in the segment table, showing as 2 entries in the NTP.
341 // Note also that we should still be updating the visit count for that segment 346 // Note also that we should still be updating the visit count for that segment
342 // which we are not doing now. It should be addressed when 347 // which we are not doing now. It should be addressed when
343 // http://crbug.com/96860 is fixed. 348 // http://crbug.com/96860 is fixed.
344 if ((ui::PageTransitionCoreTypeIs(transition_type, 349 if ((ui::PageTransitionCoreTypeIs(transition_type,
345 ui::PAGE_TRANSITION_TYPED) || 350 ui::PAGE_TRANSITION_TYPED) ||
346 ui::PageTransitionCoreTypeIs(transition_type, 351 (ui::PageTransitionCoreTypeIs(transition_type,
347 ui::PAGE_TRANSITION_AUTO_BOOKMARK)) && 352 ui::PAGE_TRANSITION_AUTO_BOOKMARK) &&
353 referrer != GURL(kChromeContentSuggestionsReferrer))) &&
348 (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) == 0) { 354 (transition_type & ui::PAGE_TRANSITION_FORWARD_BACK) == 0) {
349 // If so, create or get the segment. 355 // If so, create or get the segment.
350 std::string segment_name = db_->ComputeSegmentName(url); 356 std::string segment_name = db_->ComputeSegmentName(url);
351 URLID url_id = db_->GetRowForURL(url, nullptr); 357 URLID url_id = db_->GetRowForURL(url, nullptr);
352 if (!url_id) 358 if (!url_id)
353 return 0; 359 return 0;
354 360
355 segment_id = db_->GetSegmentNamed(segment_name); 361 segment_id = db_->GetSegmentNamed(segment_name);
356 if (!segment_id) { 362 if (!segment_id) {
357 segment_id = db_->CreateSegment(url_id, segment_name); 363 segment_id = db_->CreateSegment(url_id, segment_name);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 ui::PAGE_TRANSITION_CHAIN_END); 522 ui::PAGE_TRANSITION_CHAIN_END);
517 523
518 // No redirect case (one element means just the page itself). 524 // No redirect case (one element means just the page itself).
519 last_ids = AddPageVisit(request.url, request.time, last_ids.second, t, 525 last_ids = AddPageVisit(request.url, request.time, last_ids.second, t,
520 request.visit_source); 526 request.visit_source);
521 527
522 // Update the segment for this visit. KEYWORD_GENERATED visits should not 528 // Update the segment for this visit. KEYWORD_GENERATED visits should not
523 // result in changing most visited, so we don't update segments (most 529 // result in changing most visited, so we don't update segments (most
524 // visited db). 530 // visited db).
525 if (!is_keyword_generated) { 531 if (!is_keyword_generated) {
526 UpdateSegments(request.url, from_visit_id, last_ids.second, t, 532 UpdateSegments(request.url, request.referrer, from_visit_id,
527 request.time); 533 last_ids.second, t, request.time);
528 534
529 // Update the referrer's duration. 535 // Update the referrer's duration.
530 UpdateVisitDuration(from_visit_id, request.time); 536 UpdateVisitDuration(from_visit_id, request.time);
531 } 537 }
532 } else { 538 } else {
533 // Redirect case. Add the redirect chain. 539 // Redirect case. Add the redirect chain.
534 540
535 ui::PageTransition redirect_info = ui::PAGE_TRANSITION_CHAIN_START; 541 ui::PageTransition redirect_info = ui::PAGE_TRANSITION_CHAIN_START;
536 542
537 RedirectList redirects = request.redirects; 543 RedirectList redirects = request.redirects;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 t = ui::PageTransitionFromInt(t | ui::PAGE_TRANSITION_CHAIN_END); 592 t = ui::PageTransitionFromInt(t | ui::PAGE_TRANSITION_CHAIN_END);
587 } 593 }
588 594
589 // Record all redirect visits with the same timestamp. We don't display 595 // Record all redirect visits with the same timestamp. We don't display
590 // them anyway, and if we ever decide to, we can reconstruct their order 596 // them anyway, and if we ever decide to, we can reconstruct their order
591 // from the redirect chain. 597 // from the redirect chain.
592 last_ids = AddPageVisit(redirects[redirect_index], request.time, 598 last_ids = AddPageVisit(redirects[redirect_index], request.time,
593 last_ids.second, t, request.visit_source); 599 last_ids.second, t, request.visit_source);
594 if (t & ui::PAGE_TRANSITION_CHAIN_START) { 600 if (t & ui::PAGE_TRANSITION_CHAIN_START) {
595 // Update the segment for this visit. 601 // Update the segment for this visit.
596 UpdateSegments(redirects[redirect_index], from_visit_id, 602 UpdateSegments(redirects[redirect_index], request.referrer,
597 last_ids.second, t, request.time); 603 from_visit_id, last_ids.second, t, request.time);
598 604
599 // Update the visit_details for this visit. 605 // Update the visit_details for this visit.
600 UpdateVisitDuration(from_visit_id, request.time); 606 UpdateVisitDuration(from_visit_id, request.time);
601 } 607 }
602 608
603 // Subsequent transitions in the redirect list must all be server 609 // Subsequent transitions in the redirect list must all be server
604 // redirects. 610 // redirects.
605 redirect_info = ui::PAGE_TRANSITION_SERVER_REDIRECT; 611 redirect_info = ui::PAGE_TRANSITION_SERVER_REDIRECT;
606 } 612 }
607 613
(...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after
2648 // transaction is currently open. 2654 // transaction is currently open.
2649 db_->CommitTransaction(); 2655 db_->CommitTransaction();
2650 db_->Vacuum(); 2656 db_->Vacuum();
2651 db_->BeginTransaction(); 2657 db_->BeginTransaction();
2652 db_->GetStartDate(&first_recorded_time_); 2658 db_->GetStartDate(&first_recorded_time_);
2653 2659
2654 return true; 2660 return true;
2655 } 2661 }
2656 2662
2657 } // namespace history 2663 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.h ('k') | components/history/core/browser/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698