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

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

Issue 2949023002: [WIP] Fix history.replaceState() not propagating back favicons (Closed)
Patch Set: Focus on history.replaceState() Created 3 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
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 namespace { 77 namespace {
78 78
79 void RunUnlessCanceled( 79 void RunUnlessCanceled(
80 const base::Closure& closure, 80 const base::Closure& closure,
81 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { 81 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) {
82 if (!is_canceled.Run()) 82 if (!is_canceled.Run())
83 closure.Run(); 83 closure.Run();
84 } 84 }
85 85
86 void ConcatMoveRedirectList(RedirectList* source, RedirectList* output) {
87 if (source->empty())
88 return;
89
90 if (output->empty()) {
91 *output = std::move(*source);
92 } else {
93 output->reserve(output->size() + source->size());
94 for (GURL& redirect : *source)
95 output->push_back(std::move(redirect));
96 }
97 }
98
86 } // namespace 99 } // namespace
87 100
88 // How long we'll wait to do a commit, so that things are batched together. 101 // How long we'll wait to do a commit, so that things are batched together.
89 const int kCommitIntervalSeconds = 10; 102 const int kCommitIntervalSeconds = 10;
90 103
91 // The amount of time before we re-fetch the favicon. 104 // The amount of time before we re-fetch the favicon.
92 const int kFaviconRefetchDays = 7; 105 const int kFaviconRefetchDays = 7;
93 106
94 // The maximum number of items we'll allow in the redirect list before 107 // The maximum number of items we'll allow in the redirect list before
95 // deleting some. 108 // deleting some.
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 // consider both to have been "navigated to". 497 // consider both to have been "navigated to".
485 if (IsUntypedIntranetHost(request.url) || 498 if (IsUntypedIntranetHost(request.url) ||
486 (has_redirects && IsUntypedIntranetHost(request.redirects[0]))) { 499 (has_redirects && IsUntypedIntranetHost(request.redirects[0]))) {
487 request_transition = ui::PageTransitionFromInt( 500 request_transition = ui::PageTransitionFromInt(
488 ui::PAGE_TRANSITION_TYPED | 501 ui::PAGE_TRANSITION_TYPED |
489 ui::PageTransitionGetQualifier(request_transition)); 502 ui::PageTransitionGetQualifier(request_transition));
490 } 503 }
491 } 504 }
492 505
493 RedirectList extended_redirect_chain; 506 RedirectList extended_redirect_chain;
507 RedirectList redirects = request.redirects;
494 508
495 if (!has_redirects) { 509 if (!has_redirects) {
496 // The single entry is both a chain start and end. 510 // The single entry is both a chain start and end.
497 ui::PageTransition t = ui::PageTransitionFromInt( 511 ui::PageTransition t = ui::PageTransitionFromInt(
498 request_transition | ui::PAGE_TRANSITION_CHAIN_START | 512 request_transition | ui::PAGE_TRANSITION_CHAIN_START |
499 ui::PAGE_TRANSITION_CHAIN_END); 513 ui::PAGE_TRANSITION_CHAIN_END);
500 514
501 // No redirect case (one element means just the page itself). 515 // No redirect case (one element means just the page itself).
502 last_ids = AddPageVisit(request.url, request.time, last_ids.second, t, 516 last_ids = AddPageVisit(request.url, request.time, last_ids.second, t,
503 request.visit_source); 517 request.visit_source);
504 518
505 // Update the segment for this visit. KEYWORD_GENERATED visits should not 519 // Update the segment for this visit. KEYWORD_GENERATED visits should not
506 // result in changing most visited, so we don't update segments (most 520 // result in changing most visited, so we don't update segments (most
507 // visited db). 521 // visited db).
508 if (!is_keyword_generated && request.consider_for_ntp_most_visited) { 522 if (!is_keyword_generated && request.consider_for_ntp_most_visited) {
509 UpdateSegments(request.url, from_visit_id, last_ids.second, t, 523 UpdateSegments(request.url, from_visit_id, last_ids.second, t,
510 request.time); 524 request.time);
511 525
512 // Update the referrer's duration. 526 // Update the referrer's duration.
513 UpdateVisitDuration(from_visit_id, request.time); 527 UpdateVisitDuration(from_visit_id, request.time);
514 } 528 }
515 } else { 529 } else {
516 // Redirect case. Add the redirect chain. 530 // Redirect case. Add the redirect chain.
517 531
518 ui::PageTransition redirect_info = ui::PAGE_TRANSITION_CHAIN_START; 532 ui::PageTransition redirect_info = ui::PAGE_TRANSITION_CHAIN_START;
519
520 RedirectList redirects = request.redirects;
521 if (redirects[0].SchemeIs(url::kAboutScheme)) { 533 if (redirects[0].SchemeIs(url::kAboutScheme)) {
522 // When the redirect source + referrer is "about" we skip it. This 534 // When the redirect source + referrer is "about" we skip it. This
523 // happens when a page opens a new frame/window to about:blank and then 535 // happens when a page opens a new frame/window to about:blank and then
524 // script sets the URL to somewhere else (used to hide the referrer). It 536 // script sets the URL to somewhere else (used to hide the referrer). It
525 // would be nice to keep all these redirects properly but we don't ever 537 // would be nice to keep all these redirects properly but we don't ever
526 // see the initial about:blank load, so we don't know where the 538 // see the initial about:blank load, so we don't know where the
527 // subsequent client redirect came from. 539 // subsequent client redirect came from.
528 // 540 //
529 // In this case, we just don't bother hooking up the source of the 541 // In this case, we just don't bother hooking up the source of the
530 // redirects, so we remove it. 542 // redirects, so we remove it.
(...skipping 11 matching lines...) Expand all
542 // chain. 554 // chain.
543 if (request.referrer.is_valid()) { 555 if (request.referrer.is_valid()) {
544 DCHECK_EQ(request.referrer, redirects[0]); 556 DCHECK_EQ(request.referrer, redirects[0]);
545 redirects.erase(redirects.begin()); 557 redirects.erase(redirects.begin());
546 558
547 // If the navigation entry for this visit has replaced that for the 559 // If the navigation entry for this visit has replaced that for the
548 // first visit, remove the CHAIN_END marker from the first visit. This 560 // first visit, remove the CHAIN_END marker from the first visit. This
549 // can be called a lot, for example, the page cycler, and most of the 561 // can be called a lot, for example, the page cycler, and most of the
550 // time we won't have changed anything. 562 // time we won't have changed anything.
551 VisitRow visit_row; 563 VisitRow visit_row;
552 if (request.did_replace_entry && 564 if (request.replaced_entry_url.has_value() &&
553 db_->GetRowForVisit(last_ids.second, &visit_row) && 565 db_->GetRowForVisit(last_ids.second, &visit_row) &&
554 visit_row.transition & ui::PAGE_TRANSITION_CHAIN_END) { 566 visit_row.transition & ui::PAGE_TRANSITION_CHAIN_END) {
555 visit_row.transition = ui::PageTransitionFromInt( 567 visit_row.transition = ui::PageTransitionFromInt(
556 visit_row.transition & ~ui::PAGE_TRANSITION_CHAIN_END); 568 visit_row.transition & ~ui::PAGE_TRANSITION_CHAIN_END);
557 db_->UpdateVisitRow(visit_row); 569 db_->UpdateVisitRow(visit_row);
558 } 570 }
559 571
560 GetCachedRecentRedirects(request.referrer, &extended_redirect_chain); 572 GetCachedRecentRedirects(request.referrer, &extended_redirect_chain);
561 } 573 }
562 } 574 }
(...skipping 20 matching lines...) Expand all
583 } 595 }
584 596
585 // Update the visit_details for this visit. 597 // Update the visit_details for this visit.
586 UpdateVisitDuration(from_visit_id, request.time); 598 UpdateVisitDuration(from_visit_id, request.time);
587 } 599 }
588 600
589 // Subsequent transitions in the redirect list must all be server 601 // Subsequent transitions in the redirect list must all be server
590 // redirects. 602 // redirects.
591 redirect_info = ui::PAGE_TRANSITION_SERVER_REDIRECT; 603 redirect_info = ui::PAGE_TRANSITION_SERVER_REDIRECT;
592 } 604 }
605 }
593 606
594 // Last, save this redirect chain for later so we can set titles & favicons 607 // If the page replaced another one in history, we treat is similarly as a
595 // on the redirected pages properly. For this we use the extended redirect 608 // redirect and propagate favicon and titles through.
596 // chain, which includes URLs from concatenated redirects. 609 if (request.replaced_entry_url.has_value()) {
597 if (extended_redirect_chain.empty()) { 610 RedirectList replaced_url_redirects;
598 extended_redirect_chain = std::move(redirects); 611 GetCachedRecentRedirects(*request.replaced_entry_url,
599 } else { 612 &replaced_url_redirects);
600 extended_redirect_chain.reserve(extended_redirect_chain.size() + 613 ConcatMoveRedirectList(&replaced_url_redirects, &extended_redirect_chain);
601 redirects.size()); 614 }
602 for (GURL& redirect : redirects) 615
603 extended_redirect_chain.push_back(std::move(redirect)); 616 // Last, save this redirect chain for later so we can set titles & favicons
604 } 617 // on the redirected pages properly.
618 ConcatMoveRedirectList(&redirects, &extended_redirect_chain);
619
620 if (extended_redirect_chain.size() > 1)
605 recent_redirects_.Put(request.url, extended_redirect_chain); 621 recent_redirects_.Put(request.url, extended_redirect_chain);
606 }
607 622
608 // TODO(brettw) bug 1140015: Add an "add page" notification so the history 623 // TODO(brettw) bug 1140015: Add an "add page" notification so the history
609 // views can keep in sync. 624 // views can keep in sync.
610 625
611 // Add the last visit to the tracker so we can get outgoing transitions. 626 // Add the last visit to the tracker so we can get outgoing transitions.
612 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe 627 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe
613 // navigation anyway, so last_visit_id is always zero for them. But adding 628 // navigation anyway, so last_visit_id is always zero for them. But adding
614 // them here confuses main frame history, so we skip them for now. 629 // them here confuses main frame history, so we skip them for now.
615 if (!ui::PageTransitionCoreTypeIs(request_transition, 630 if (!ui::PageTransitionCoreTypeIs(request_transition,
616 ui::PAGE_TRANSITION_AUTO_SUBFRAME) && 631 ui::PAGE_TRANSITION_AUTO_SUBFRAME) &&
(...skipping 2049 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 // transaction is currently open. 2681 // transaction is currently open.
2667 db_->CommitTransaction(); 2682 db_->CommitTransaction();
2668 db_->Vacuum(); 2683 db_->Vacuum();
2669 db_->BeginTransaction(); 2684 db_->BeginTransaction();
2670 db_->GetStartDate(&first_recorded_time_); 2685 db_->GetStartDate(&first_recorded_time_);
2671 2686
2672 return true; 2687 return true;
2673 } 2688 }
2674 2689
2675 } // namespace history 2690 } // namespace history
OLDNEW
« no previous file with comments | « chrome/test/data/favicon/replacestate_with_favicon.html ('k') | components/history/core/browser/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698