| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 303 |
| 304 if (visit_set.find(visit_id) != visit_set.end()) { | 304 if (visit_set.find(visit_id) != visit_set.end()) { |
| 305 NOTREACHED() << "Loop in referer chain, giving up"; | 305 NOTREACHED() << "Loop in referer chain, giving up"; |
| 306 break; | 306 break; |
| 307 } | 307 } |
| 308 visit_set.insert(visit_id); | 308 visit_set.insert(visit_id); |
| 309 } | 309 } |
| 310 return 0; | 310 return 0; |
| 311 } | 311 } |
| 312 | 312 |
| 313 SegmentID HistoryBackend::UpdateSegments(const GURL& url, | 313 SegmentID HistoryBackend::UpdateSegments( |
| 314 VisitID from_visit, | 314 const GURL& url, |
| 315 VisitID visit_id, | 315 VisitID from_visit, |
| 316 PageTransition::Type transition_type, | 316 VisitID visit_id, |
| 317 const Time ts) { | 317 content::PageTransition transition_type, |
| 318 const Time ts) { |
| 318 if (!db_.get()) | 319 if (!db_.get()) |
| 319 return 0; | 320 return 0; |
| 320 | 321 |
| 321 // We only consider main frames. | 322 // We only consider main frames. |
| 322 if (!PageTransition::IsMainFrame(transition_type)) | 323 if (!content::PageTransitionIsMainFrame(transition_type)) |
| 323 return 0; | 324 return 0; |
| 324 | 325 |
| 325 SegmentID segment_id = 0; | 326 SegmentID segment_id = 0; |
| 326 PageTransition::Type t = PageTransition::StripQualifier(transition_type); | 327 content::PageTransition t = |
| 328 content::PageTransitionStripQualifier(transition_type); |
| 327 | 329 |
| 328 // Are we at the beginning of a new segment? | 330 // Are we at the beginning of a new segment? |
| 329 if (t == PageTransition::TYPED || t == PageTransition::AUTO_BOOKMARK) { | 331 if (t == content::PAGE_TRANSITION_TYPED || |
| 332 t == content::PAGE_TRANSITION_AUTO_BOOKMARK) { |
| 330 // If so, create or get the segment. | 333 // If so, create or get the segment. |
| 331 std::string segment_name = db_->ComputeSegmentName(url); | 334 std::string segment_name = db_->ComputeSegmentName(url); |
| 332 URLID url_id = db_->GetRowForURL(url, NULL); | 335 URLID url_id = db_->GetRowForURL(url, NULL); |
| 333 if (!url_id) | 336 if (!url_id) |
| 334 return 0; | 337 return 0; |
| 335 | 338 |
| 336 if (!(segment_id = db_->GetSegmentNamed(segment_name))) { | 339 if (!(segment_id = db_->GetSegmentNamed(segment_name))) { |
| 337 if (!(segment_id = db_->CreateSegment(url_id, segment_name))) { | 340 if (!(segment_id = db_->CreateSegment(url_id, segment_name))) { |
| 338 NOTREACHED(); | 341 NOTREACHED(); |
| 339 return 0; | 342 return 0; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } else { | 394 } else { |
| 392 last_requested_time_ = request->time; | 395 last_requested_time_ = request->time; |
| 393 last_recorded_time_ = last_requested_time_; | 396 last_recorded_time_ = last_requested_time_; |
| 394 } | 397 } |
| 395 | 398 |
| 396 // If the user is adding older history, we need to make sure our times | 399 // If the user is adding older history, we need to make sure our times |
| 397 // are correct. | 400 // are correct. |
| 398 if (request->time < first_recorded_time_) | 401 if (request->time < first_recorded_time_) |
| 399 first_recorded_time_ = request->time; | 402 first_recorded_time_ = request->time; |
| 400 | 403 |
| 401 PageTransition::Type transition = | 404 content::PageTransition transition = |
| 402 PageTransition::StripQualifier(request->transition); | 405 content::PageTransitionStripQualifier(request->transition); |
| 403 bool is_keyword_generated = (transition == PageTransition::KEYWORD_GENERATED); | 406 bool is_keyword_generated = |
| 407 (transition == content::PAGE_TRANSITION_KEYWORD_GENERATED); |
| 404 | 408 |
| 405 if (request->redirects.size() <= 1) { | 409 if (request->redirects.size() <= 1) { |
| 406 // The single entry is both a chain start and end. | 410 // The single entry is both a chain start and end. |
| 407 PageTransition::Type t = request->transition | | 411 content::PageTransition t = content::PageTransitionFromInt( |
| 408 PageTransition::CHAIN_START | PageTransition::CHAIN_END; | 412 request->transition | |
| 413 content::PAGE_TRANSITION_CHAIN_START | |
| 414 content::PAGE_TRANSITION_CHAIN_END); |
| 409 | 415 |
| 410 // No redirect case (one element means just the page itself). | 416 // No redirect case (one element means just the page itself). |
| 411 last_ids = AddPageVisit(request->url, last_recorded_time_, | 417 last_ids = AddPageVisit(request->url, last_recorded_time_, |
| 412 last_ids.second, t, request->visit_source); | 418 last_ids.second, t, request->visit_source); |
| 413 | 419 |
| 414 // Update the segment for this visit. KEYWORD_GENERATED visits should not | 420 // Update the segment for this visit. KEYWORD_GENERATED visits should not |
| 415 // result in changing most visited, so we don't update segments (most | 421 // result in changing most visited, so we don't update segments (most |
| 416 // visited db). | 422 // visited db). |
| 417 if (!is_keyword_generated) { | 423 if (!is_keyword_generated) { |
| 418 UpdateSegments(request->url, from_visit_id, last_ids.second, t, | 424 UpdateSegments(request->url, from_visit_id, last_ids.second, t, |
| 419 last_recorded_time_); | 425 last_recorded_time_); |
| 420 } | 426 } |
| 421 } else { | 427 } else { |
| 422 // Redirect case. Add the redirect chain. | 428 // Redirect case. Add the redirect chain. |
| 423 | 429 |
| 424 PageTransition::Type redirect_info = PageTransition::CHAIN_START; | 430 content::PageTransition redirect_info = |
| 431 content::PAGE_TRANSITION_CHAIN_START; |
| 425 | 432 |
| 426 if (request->redirects[0].SchemeIs(chrome::kAboutScheme)) { | 433 if (request->redirects[0].SchemeIs(chrome::kAboutScheme)) { |
| 427 // When the redirect source + referrer is "about" we skip it. This | 434 // When the redirect source + referrer is "about" we skip it. This |
| 428 // happens when a page opens a new frame/window to about:blank and then | 435 // happens when a page opens a new frame/window to about:blank and then |
| 429 // script sets the URL to somewhere else (used to hide the referrer). It | 436 // script sets the URL to somewhere else (used to hide the referrer). It |
| 430 // would be nice to keep all these redirects properly but we don't ever | 437 // would be nice to keep all these redirects properly but we don't ever |
| 431 // see the initial about:blank load, so we don't know where the | 438 // see the initial about:blank load, so we don't know where the |
| 432 // subsequent client redirect came from. | 439 // subsequent client redirect came from. |
| 433 // | 440 // |
| 434 // In this case, we just don't bother hooking up the source of the | 441 // In this case, we just don't bother hooking up the source of the |
| 435 // redirects, so we remove it. | 442 // redirects, so we remove it. |
| 436 request->redirects.erase(request->redirects.begin()); | 443 request->redirects.erase(request->redirects.begin()); |
| 437 } else if (request->transition & PageTransition::CLIENT_REDIRECT) { | 444 } else if (request->transition & content::PAGE_TRANSITION_CLIENT_REDIRECT) { |
| 438 redirect_info = PageTransition::CLIENT_REDIRECT; | 445 redirect_info = content::PAGE_TRANSITION_CLIENT_REDIRECT; |
| 439 // The first entry in the redirect chain initiated a client redirect. | 446 // The first entry in the redirect chain initiated a client redirect. |
| 440 // We don't add this to the database since the referrer is already | 447 // We don't add this to the database since the referrer is already |
| 441 // there, so we skip over it but change the transition type of the first | 448 // there, so we skip over it but change the transition type of the first |
| 442 // transition to client redirect. | 449 // transition to client redirect. |
| 443 // | 450 // |
| 444 // The referrer is invalid when restoring a session that features an | 451 // The referrer is invalid when restoring a session that features an |
| 445 // https tab that redirects to a different host or to http. In this | 452 // https tab that redirects to a different host or to http. In this |
| 446 // case we don't need to reconnect the new redirect with the existing | 453 // case we don't need to reconnect the new redirect with the existing |
| 447 // chain. | 454 // chain. |
| 448 if (request->referrer.is_valid()) { | 455 if (request->referrer.is_valid()) { |
| 449 DCHECK(request->referrer == request->redirects[0]); | 456 DCHECK(request->referrer == request->redirects[0]); |
| 450 request->redirects.erase(request->redirects.begin()); | 457 request->redirects.erase(request->redirects.begin()); |
| 451 | 458 |
| 452 // If the navigation entry for this visit has replaced that for the | 459 // If the navigation entry for this visit has replaced that for the |
| 453 // first visit, remove the CHAIN_END marker from the first visit. This | 460 // first visit, remove the CHAIN_END marker from the first visit. This |
| 454 // can be called a lot, for example, the page cycler, and most of the | 461 // can be called a lot, for example, the page cycler, and most of the |
| 455 // time we won't have changed anything. | 462 // time we won't have changed anything. |
| 456 VisitRow visit_row; | 463 VisitRow visit_row; |
| 457 if (request->did_replace_entry && | 464 if (request->did_replace_entry && |
| 458 db_->GetRowForVisit(last_ids.second, &visit_row) && | 465 db_->GetRowForVisit(last_ids.second, &visit_row) && |
| 459 visit_row.transition | PageTransition::CHAIN_END) { | 466 visit_row.transition | content::PAGE_TRANSITION_CHAIN_END) { |
| 460 visit_row.transition &= ~PageTransition::CHAIN_END; | 467 visit_row.transition = content::PageTransitionFromInt( |
| 468 visit_row.transition & ~content::PAGE_TRANSITION_CHAIN_END); |
| 461 db_->UpdateVisitRow(visit_row); | 469 db_->UpdateVisitRow(visit_row); |
| 462 } | 470 } |
| 463 } | 471 } |
| 464 } | 472 } |
| 465 | 473 |
| 466 for (size_t redirect_index = 0; redirect_index < request->redirects.size(); | 474 for (size_t redirect_index = 0; redirect_index < request->redirects.size(); |
| 467 redirect_index++) { | 475 redirect_index++) { |
| 468 PageTransition::Type t = transition | redirect_info; | 476 content::PageTransition t = |
| 477 content::PageTransitionFromInt(transition | redirect_info); |
| 469 | 478 |
| 470 // If this is the last transition, add a CHAIN_END marker | 479 // If this is the last transition, add a CHAIN_END marker |
| 471 if (redirect_index == (request->redirects.size() - 1)) | 480 if (redirect_index == (request->redirects.size() - 1)) { |
| 472 t = t | PageTransition::CHAIN_END; | 481 t = content::PageTransitionFromInt( |
| 482 t | content::PAGE_TRANSITION_CHAIN_END); |
| 483 } |
| 473 | 484 |
| 474 // Record all redirect visits with the same timestamp. We don't display | 485 // Record all redirect visits with the same timestamp. We don't display |
| 475 // them anyway, and if we ever decide to, we can reconstruct their order | 486 // them anyway, and if we ever decide to, we can reconstruct their order |
| 476 // from the redirect chain. | 487 // from the redirect chain. |
| 477 last_ids = AddPageVisit(request->redirects[redirect_index], | 488 last_ids = AddPageVisit(request->redirects[redirect_index], |
| 478 last_recorded_time_, last_ids.second, | 489 last_recorded_time_, last_ids.second, |
| 479 t, request->visit_source); | 490 t, request->visit_source); |
| 480 if (t & PageTransition::CHAIN_START) { | 491 if (t & content::PAGE_TRANSITION_CHAIN_START) { |
| 481 // Update the segment for this visit. | 492 // Update the segment for this visit. |
| 482 UpdateSegments(request->redirects[redirect_index], | 493 UpdateSegments(request->redirects[redirect_index], |
| 483 from_visit_id, last_ids.second, t, last_recorded_time_); | 494 from_visit_id, last_ids.second, t, last_recorded_time_); |
| 484 } | 495 } |
| 485 | 496 |
| 486 // Subsequent transitions in the redirect list must all be sever | 497 // Subsequent transitions in the redirect list must all be sever |
| 487 // redirects. | 498 // redirects. |
| 488 redirect_info = PageTransition::SERVER_REDIRECT; | 499 redirect_info = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 489 } | 500 } |
| 490 | 501 |
| 491 // Last, save this redirect chain for later so we can set titles & favicons | 502 // Last, save this redirect chain for later so we can set titles & favicons |
| 492 // on the redirected pages properly. It is indexed by the destination page. | 503 // on the redirected pages properly. It is indexed by the destination page. |
| 493 recent_redirects_.Put(request->url, request->redirects); | 504 recent_redirects_.Put(request->url, request->redirects); |
| 494 } | 505 } |
| 495 | 506 |
| 496 // TODO(brettw) bug 1140015: Add an "add page" notification so the history | 507 // TODO(brettw) bug 1140015: Add an "add page" notification so the history |
| 497 // views can keep in sync. | 508 // views can keep in sync. |
| 498 | 509 |
| 499 // Add the last visit to the tracker so we can get outgoing transitions. | 510 // Add the last visit to the tracker so we can get outgoing transitions. |
| 500 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe | 511 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe |
| 501 // navigation anyway, so last_visit_id is always zero for them. But adding | 512 // navigation anyway, so last_visit_id is always zero for them. But adding |
| 502 // them here confuses main frame history, so we skip them for now. | 513 // them here confuses main frame history, so we skip them for now. |
| 503 if (transition != PageTransition::AUTO_SUBFRAME && | 514 if (transition != content::PAGE_TRANSITION_AUTO_SUBFRAME && |
| 504 transition != PageTransition::MANUAL_SUBFRAME && !is_keyword_generated) { | 515 transition != content::PAGE_TRANSITION_MANUAL_SUBFRAME && |
| 516 !is_keyword_generated) { |
| 505 tracker_.AddVisit(request->id_scope, request->page_id, request->url, | 517 tracker_.AddVisit(request->id_scope, request->page_id, request->url, |
| 506 last_ids.second); | 518 last_ids.second); |
| 507 } | 519 } |
| 508 | 520 |
| 509 if (text_database_.get()) { | 521 if (text_database_.get()) { |
| 510 text_database_->AddPageURL(request->url, last_ids.first, last_ids.second, | 522 text_database_->AddPageURL(request->url, last_ids.first, last_ids.second, |
| 511 last_recorded_time_); | 523 last_recorded_time_); |
| 512 } | 524 } |
| 513 | 525 |
| 514 ScheduleCommit(); | 526 ScheduleCommit(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold)); | 656 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold)); |
| 645 | 657 |
| 646 HISTOGRAM_TIMES("History.InitTime", | 658 HISTOGRAM_TIMES("History.InitTime", |
| 647 TimeTicks::Now() - beginning_time); | 659 TimeTicks::Now() - beginning_time); |
| 648 } | 660 } |
| 649 | 661 |
| 650 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( | 662 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( |
| 651 const GURL& url, | 663 const GURL& url, |
| 652 Time time, | 664 Time time, |
| 653 VisitID referring_visit, | 665 VisitID referring_visit, |
| 654 PageTransition::Type transition, | 666 content::PageTransition transition, |
| 655 VisitSource visit_source) { | 667 VisitSource visit_source) { |
| 656 // Top-level frame navigations are visible, everything else is hidden | 668 // Top-level frame navigations are visible, everything else is hidden |
| 657 bool new_hidden = !PageTransition::IsMainFrame(transition); | 669 bool new_hidden = !content::PageTransitionIsMainFrame(transition); |
| 658 | 670 |
| 659 // NOTE: This code must stay in sync with | 671 // NOTE: This code must stay in sync with |
| 660 // ExpireHistoryBackend::ExpireURLsForVisits(). | 672 // ExpireHistoryBackend::ExpireURLsForVisits(). |
| 661 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as | 673 // TODO(pkasting): http://b/1148304 We shouldn't be marking so many URLs as |
| 662 // typed, which would eliminate the need for this code. | 674 // typed, which would eliminate the need for this code. |
| 663 int typed_increment = 0; | 675 int typed_increment = 0; |
| 664 PageTransition::Type transition_type = | 676 content::PageTransition transition_type = |
| 665 PageTransition::StripQualifier(transition); | 677 content::PageTransitionStripQualifier(transition); |
| 666 if ((transition_type == PageTransition::TYPED && | 678 if ((transition_type == content::PAGE_TRANSITION_TYPED && |
| 667 !PageTransition::IsRedirect(transition)) || | 679 !content::PageTransitionIsRedirect(transition)) || |
| 668 transition_type == PageTransition::KEYWORD_GENERATED) | 680 transition_type == content::PAGE_TRANSITION_KEYWORD_GENERATED) |
| 669 typed_increment = 1; | 681 typed_increment = 1; |
| 670 | 682 |
| 671 // See if this URL is already in the DB. | 683 // See if this URL is already in the DB. |
| 672 URLRow url_info(url); | 684 URLRow url_info(url); |
| 673 URLID url_id = db_->GetRowForURL(url, &url_info); | 685 URLID url_id = db_->GetRowForURL(url, &url_info); |
| 674 if (url_id) { | 686 if (url_id) { |
| 675 // Update of an existing row. | 687 // Update of an existing row. |
| 676 if (PageTransition::StripQualifier(transition) != PageTransition::RELOAD) | 688 if (content::PageTransitionStripQualifier(transition) != |
| 689 content::PAGE_TRANSITION_RELOAD) |
| 677 url_info.set_visit_count(url_info.visit_count() + 1); | 690 url_info.set_visit_count(url_info.visit_count() + 1); |
| 678 if (typed_increment) | 691 if (typed_increment) |
| 679 url_info.set_typed_count(url_info.typed_count() + typed_increment); | 692 url_info.set_typed_count(url_info.typed_count() + typed_increment); |
| 680 url_info.set_last_visit(time); | 693 url_info.set_last_visit(time); |
| 681 | 694 |
| 682 // Only allow un-hiding of pages, never hiding. | 695 // Only allow un-hiding of pages, never hiding. |
| 683 if (!new_hidden) | 696 if (!new_hidden) |
| 684 url_info.set_hidden(false); | 697 url_info.set_hidden(false); |
| 685 | 698 |
| 686 db_->UpdateURLRow(url_id, url_info); | 699 db_->UpdateURLRow(url_id, url_info); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 // create the visit entry with the indexed flag set. | 799 // create the visit entry with the indexed flag set. |
| 787 has_indexed = text_database_->AddPageData(i->url(), url_id, 0, | 800 has_indexed = text_database_->AddPageData(i->url(), url_id, 0, |
| 788 i->last_visit(), | 801 i->last_visit(), |
| 789 i->title(), string16()); | 802 i->title(), string16()); |
| 790 } | 803 } |
| 791 | 804 |
| 792 // Sync code manages the visits itself. | 805 // Sync code manages the visits itself. |
| 793 if (visit_source != SOURCE_SYNCED) { | 806 if (visit_source != SOURCE_SYNCED) { |
| 794 // Make up a visit to correspond to the last visit to the page. | 807 // Make up a visit to correspond to the last visit to the page. |
| 795 VisitRow visit_info(url_id, i->last_visit(), 0, | 808 VisitRow visit_info(url_id, i->last_visit(), 0, |
| 796 PageTransition::LINK | PageTransition::CHAIN_START | | 809 content::PageTransitionFromInt( |
| 797 PageTransition::CHAIN_END, 0); | 810 content::PAGE_TRANSITION_LINK | |
| 811 content::PAGE_TRANSITION_CHAIN_START | |
| 812 content::PAGE_TRANSITION_CHAIN_END), 0); |
| 798 visit_info.is_indexed = has_indexed; | 813 visit_info.is_indexed = has_indexed; |
| 799 if (!visit_database->AddVisit(&visit_info, visit_source)) { | 814 if (!visit_database->AddVisit(&visit_info, visit_source)) { |
| 800 NOTREACHED() << "Adding visit failed."; | 815 NOTREACHED() << "Adding visit failed."; |
| 801 return; | 816 return; |
| 802 } | 817 } |
| 803 | 818 |
| 804 if (visit_info.visit_time < first_recorded_time_) | 819 if (visit_info.visit_time < first_recorded_time_) |
| 805 first_recorded_time_ = visit_info.visit_time; | 820 first_recorded_time_ = visit_info.visit_time; |
| 806 } | 821 } |
| 807 } | 822 } |
| (...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2256 break; | 2271 break; |
| 2257 } | 2272 } |
| 2258 } | 2273 } |
| 2259 } | 2274 } |
| 2260 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name | 2275 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name |
| 2261 TimeTicks::Now() - beginning_time); | 2276 TimeTicks::Now() - beginning_time); |
| 2262 return success; | 2277 return success; |
| 2263 } | 2278 } |
| 2264 | 2279 |
| 2265 } // namespace history | 2280 } // namespace history |
| OLD | NEW |