OLD | NEW |
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 VisitRow visit_row; | 365 VisitRow visit_row; |
366 if (db_->GetRowForVisit(visit_id, &visit_row)) { | 366 if (db_->GetRowForVisit(visit_id, &visit_row)) { |
367 // We should never have a negative duration time even when time is skewed. | 367 // We should never have a negative duration time even when time is skewed. |
368 visit_row.visit_duration = end_ts > visit_row.visit_time | 368 visit_row.visit_duration = end_ts > visit_row.visit_time |
369 ? end_ts - visit_row.visit_time | 369 ? end_ts - visit_row.visit_time |
370 : TimeDelta::FromMicroseconds(0); | 370 : TimeDelta::FromMicroseconds(0); |
371 db_->UpdateVisitRow(visit_row); | 371 db_->UpdateVisitRow(visit_row); |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
| 375 bool HistoryBackend::IsUntypedIntranetHost(const GURL& url) { |
| 376 if (!url.SchemeIs(url::kHttpScheme) && !url.SchemeIs(url::kHttpsScheme) && |
| 377 !url.SchemeIs(url::kFtpScheme)) |
| 378 return false; |
| 379 |
| 380 const std::string host = url.host(); |
| 381 const size_t registry_length = |
| 382 net::registry_controlled_domains::GetCanonicalHostRegistryLength( |
| 383 host, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
| 384 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 385 return (registry_length == 0) && !db_->IsTypedHost(host); |
| 386 } |
| 387 |
375 TopHostsList HistoryBackend::TopHosts(size_t num_hosts) const { | 388 TopHostsList HistoryBackend::TopHosts(size_t num_hosts) const { |
376 if (!db_) | 389 if (!db_) |
377 return TopHostsList(); | 390 return TopHostsList(); |
378 | 391 |
379 auto top_hosts = db_->TopHosts(num_hosts); | 392 auto top_hosts = db_->TopHosts(num_hosts); |
380 | 393 |
381 host_ranks_.clear(); | 394 host_ranks_.clear(); |
382 int i = 0; | 395 int i = 0; |
383 for (const auto& host_count : top_hosts) | 396 for (const auto& host_count : top_hosts) |
384 host_ranks_[host_count.first] = i++; | 397 host_ranks_[host_count.first] = i++; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 request_transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED); | 456 request_transition, ui::PAGE_TRANSITION_KEYWORD_GENERATED); |
444 | 457 |
445 // If the user is navigating to a not-previously-typed intranet hostname, | 458 // If the user is navigating to a not-previously-typed intranet hostname, |
446 // change the transition to TYPED so that the omnibox will learn that this is | 459 // change the transition to TYPED so that the omnibox will learn that this is |
447 // a known host. | 460 // a known host. |
448 bool has_redirects = request.redirects.size() > 1; | 461 bool has_redirects = request.redirects.size() > 1; |
449 if (ui::PageTransitionIsMainFrame(request_transition) && | 462 if (ui::PageTransitionIsMainFrame(request_transition) && |
450 !ui::PageTransitionCoreTypeIs(request_transition, | 463 !ui::PageTransitionCoreTypeIs(request_transition, |
451 ui::PAGE_TRANSITION_TYPED) && | 464 ui::PAGE_TRANSITION_TYPED) && |
452 !is_keyword_generated) { | 465 !is_keyword_generated) { |
453 const GURL& origin_url(has_redirects ? request.redirects[0] : request.url); | 466 // Check both the start and end of a redirect chain, since the user will |
454 if (origin_url.SchemeIs(url::kHttpScheme) || | 467 // consider both to have been "navigated to". |
455 origin_url.SchemeIs(url::kHttpsScheme) || | 468 if (IsUntypedIntranetHost(request.url) || |
456 origin_url.SchemeIs(url::kFtpScheme)) { | 469 (has_redirects && IsUntypedIntranetHost(request.redirects[0]))) { |
457 std::string host(origin_url.host()); | 470 request_transition = ui::PageTransitionFromInt( |
458 size_t registry_length = | 471 ui::PAGE_TRANSITION_TYPED | |
459 net::registry_controlled_domains::GetCanonicalHostRegistryLength( | 472 ui::PageTransitionGetQualifier(request_transition)); |
460 host, | |
461 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | |
462 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | |
463 if (registry_length == 0 && !db_->IsTypedHost(host)) { | |
464 request_transition = ui::PageTransitionFromInt( | |
465 ui::PAGE_TRANSITION_TYPED | | |
466 ui::PageTransitionGetQualifier(request_transition)); | |
467 } | |
468 } | 473 } |
469 } | 474 } |
470 | 475 |
471 if (!has_redirects) { | 476 if (!has_redirects) { |
472 // The single entry is both a chain start and end. | 477 // The single entry is both a chain start and end. |
473 ui::PageTransition t = ui::PageTransitionFromInt( | 478 ui::PageTransition t = ui::PageTransitionFromInt( |
474 request_transition | ui::PAGE_TRANSITION_CHAIN_START | | 479 request_transition | ui::PAGE_TRANSITION_CHAIN_START | |
475 ui::PAGE_TRANSITION_CHAIN_END); | 480 ui::PAGE_TRANSITION_CHAIN_END); |
476 | 481 |
477 // No redirect case (one element means just the page itself). | 482 // No redirect case (one element means just the page itself). |
(...skipping 2123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2601 // transaction is currently open. | 2606 // transaction is currently open. |
2602 db_->CommitTransaction(); | 2607 db_->CommitTransaction(); |
2603 db_->Vacuum(); | 2608 db_->Vacuum(); |
2604 db_->BeginTransaction(); | 2609 db_->BeginTransaction(); |
2605 db_->GetStartDate(&first_recorded_time_); | 2610 db_->GetStartDate(&first_recorded_time_); |
2606 | 2611 |
2607 return true; | 2612 return true; |
2608 } | 2613 } |
2609 | 2614 |
2610 } // namespace history | 2615 } // namespace history |
OLD | NEW |