| 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 "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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } | 360 } |
| 361 | 361 |
| 362 // Finally, increase the counter for that segment / day. | 362 // Finally, increase the counter for that segment / day. |
| 363 if (!db_->IncreaseSegmentVisitCount(segment_id, ts, 1)) { | 363 if (!db_->IncreaseSegmentVisitCount(segment_id, ts, 1)) { |
| 364 NOTREACHED(); | 364 NOTREACHED(); |
| 365 return 0; | 365 return 0; |
| 366 } | 366 } |
| 367 return segment_id; | 367 return segment_id; |
| 368 } | 368 } |
| 369 | 369 |
| 370 void HistoryBackend::UpdateWithPageEndTime(const void* host, |
| 371 int32 page_id, |
| 372 const GURL& url, |
| 373 Time end_ts) { |
| 374 // Will be filled with the URL ID and the visit ID of the last addition. |
| 375 VisitID visit_id = tracker_.GetLastVisit(host, page_id, url); |
| 376 UpdateVisitDuration(visit_id, end_ts); |
| 377 } |
| 378 |
| 379 void HistoryBackend::UpdateVisitDuration(VisitID visit_id, const Time end_ts) { |
| 380 if (!db_.get()) |
| 381 return; |
| 382 |
| 383 // Get the starting visit_time for visit_id. |
| 384 VisitRow visit_row; |
| 385 if (db_->GetRowForVisit(visit_id, &visit_row)) { |
| 386 // We should never have a negative duration time even when time is skewed. |
| 387 visit_row.visit_duration = end_ts > visit_row.visit_time ? |
| 388 end_ts - visit_row.visit_time : TimeDelta::FromMicroseconds(0); |
| 389 db_->UpdateVisitRow(visit_row); |
| 390 } |
| 391 } |
| 392 |
| 370 void HistoryBackend::AddPage(scoped_refptr<HistoryAddPageArgs> request) { | 393 void HistoryBackend::AddPage(scoped_refptr<HistoryAddPageArgs> request) { |
| 371 if (!db_.get()) | 394 if (!db_.get()) |
| 372 return; | 395 return; |
| 373 | 396 |
| 374 // Will be filled with the URL ID and the visit ID of the last addition. | 397 // Will be filled with the URL ID and the visit ID of the last addition. |
| 375 std::pair<URLID, VisitID> last_ids(0, tracker_.GetLastVisit( | 398 std::pair<URLID, VisitID> last_ids(0, tracker_.GetLastVisit( |
| 376 request->id_scope, request->page_id, request->referrer)); | 399 request->id_scope, request->page_id, request->referrer)); |
| 377 | 400 |
| 378 VisitID from_visit_id = last_ids.second; | 401 VisitID from_visit_id = last_ids.second; |
| 379 | 402 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // No redirect case (one element means just the page itself). | 457 // No redirect case (one element means just the page itself). |
| 435 last_ids = AddPageVisit(request->url, last_recorded_time_, | 458 last_ids = AddPageVisit(request->url, last_recorded_time_, |
| 436 last_ids.second, t, request->visit_source); | 459 last_ids.second, t, request->visit_source); |
| 437 | 460 |
| 438 // Update the segment for this visit. KEYWORD_GENERATED visits should not | 461 // Update the segment for this visit. KEYWORD_GENERATED visits should not |
| 439 // result in changing most visited, so we don't update segments (most | 462 // result in changing most visited, so we don't update segments (most |
| 440 // visited db). | 463 // visited db). |
| 441 if (!is_keyword_generated) { | 464 if (!is_keyword_generated) { |
| 442 UpdateSegments(request->url, from_visit_id, last_ids.second, t, | 465 UpdateSegments(request->url, from_visit_id, last_ids.second, t, |
| 443 last_recorded_time_); | 466 last_recorded_time_); |
| 467 |
| 468 // Update the referrer's duration. |
| 469 UpdateVisitDuration(from_visit_id, last_recorded_time_); |
| 444 } | 470 } |
| 445 } else { | 471 } else { |
| 446 // Redirect case. Add the redirect chain. | 472 // Redirect case. Add the redirect chain. |
| 447 | 473 |
| 448 content::PageTransition redirect_info = | 474 content::PageTransition redirect_info = |
| 449 content::PAGE_TRANSITION_CHAIN_START; | 475 content::PAGE_TRANSITION_CHAIN_START; |
| 450 | 476 |
| 451 if (request->redirects[0].SchemeIs(chrome::kAboutScheme)) { | 477 if (request->redirects[0].SchemeIs(chrome::kAboutScheme)) { |
| 452 // When the redirect source + referrer is "about" we skip it. This | 478 // When the redirect source + referrer is "about" we skip it. This |
| 453 // happens when a page opens a new frame/window to about:blank and then | 479 // happens when a page opens a new frame/window to about:blank and then |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // Record all redirect visits with the same timestamp. We don't display | 529 // Record all redirect visits with the same timestamp. We don't display |
| 504 // them anyway, and if we ever decide to, we can reconstruct their order | 530 // them anyway, and if we ever decide to, we can reconstruct their order |
| 505 // from the redirect chain. | 531 // from the redirect chain. |
| 506 last_ids = AddPageVisit(request->redirects[redirect_index], | 532 last_ids = AddPageVisit(request->redirects[redirect_index], |
| 507 last_recorded_time_, last_ids.second, | 533 last_recorded_time_, last_ids.second, |
| 508 t, request->visit_source); | 534 t, request->visit_source); |
| 509 if (t & content::PAGE_TRANSITION_CHAIN_START) { | 535 if (t & content::PAGE_TRANSITION_CHAIN_START) { |
| 510 // Update the segment for this visit. | 536 // Update the segment for this visit. |
| 511 UpdateSegments(request->redirects[redirect_index], | 537 UpdateSegments(request->redirects[redirect_index], |
| 512 from_visit_id, last_ids.second, t, last_recorded_time_); | 538 from_visit_id, last_ids.second, t, last_recorded_time_); |
| 539 |
| 540 // Update the visit_details for this visit. |
| 541 UpdateVisitDuration(from_visit_id, last_recorded_time_); |
| 513 } | 542 } |
| 514 | 543 |
| 515 // Subsequent transitions in the redirect list must all be sever | 544 // Subsequent transitions in the redirect list must all be sever |
| 516 // redirects. | 545 // redirects. |
| 517 redirect_info = content::PAGE_TRANSITION_SERVER_REDIRECT; | 546 redirect_info = content::PAGE_TRANSITION_SERVER_REDIRECT; |
| 518 } | 547 } |
| 519 | 548 |
| 520 // Last, save this redirect chain for later so we can set titles & favicons | 549 // Last, save this redirect chain for later so we can set titles & favicons |
| 521 // on the redirected pages properly. It is indexed by the destination page. | 550 // on the redirected pages properly. It is indexed by the destination page. |
| 522 recent_redirects_.Put(request->url, request->redirects); | 551 recent_redirects_.Put(request->url, request->redirects); |
| (...skipping 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2452 return false; | 2481 return false; |
| 2453 | 2482 |
| 2454 favicon->expired = (Time::Now() - last_updated) > | 2483 favicon->expired = (Time::Now() - last_updated) > |
| 2455 TimeDelta::FromDays(kFaviconRefetchDays); | 2484 TimeDelta::FromDays(kFaviconRefetchDays); |
| 2456 favicon->known_icon = true; | 2485 favicon->known_icon = true; |
| 2457 favicon->image_data = data; | 2486 favicon->image_data = data; |
| 2458 return true; | 2487 return true; |
| 2459 } | 2488 } |
| 2460 | 2489 |
| 2461 } // namespace history | 2490 } // namespace history |
| OLD | NEW |