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

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 823273003: Switch the history backend from using page ids to navigation entry unique ids. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 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 "chrome/browser/history/history_backend.h" 5 #include "chrome/browser/history/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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 373
374 // Finally, increase the counter for that segment / day. 374 // Finally, increase the counter for that segment / day.
375 if (!db_->IncreaseSegmentVisitCount(segment_id, ts, 1)) { 375 if (!db_->IncreaseSegmentVisitCount(segment_id, ts, 1)) {
376 NOTREACHED(); 376 NOTREACHED();
377 return 0; 377 return 0;
378 } 378 }
379 return segment_id; 379 return segment_id;
380 } 380 }
381 381
382 void HistoryBackend::UpdateWithPageEndTime(ContextID context_id, 382 void HistoryBackend::UpdateWithPageEndTime(ContextID context_id,
383 int32 page_id, 383 int nav_entry_id,
384 const GURL& url, 384 const GURL& url,
385 Time end_ts) { 385 Time end_ts) {
386 // Will be filled with the URL ID and the visit ID of the last addition. 386 // Will be filled with the URL ID and the visit ID of the last addition.
387 VisitID visit_id = tracker_.GetLastVisit(context_id, page_id, url); 387 VisitID visit_id = tracker_.GetLastVisit(context_id, nav_entry_id, url);
388 UpdateVisitDuration(visit_id, end_ts); 388 UpdateVisitDuration(visit_id, end_ts);
389 } 389 }
390 390
391 void HistoryBackend::UpdateVisitDuration(VisitID visit_id, const Time end_ts) { 391 void HistoryBackend::UpdateVisitDuration(VisitID visit_id, const Time end_ts) {
392 if (!db_) 392 if (!db_)
393 return; 393 return;
394 394
395 // Get the starting visit_time for visit_id. 395 // Get the starting visit_time for visit_id.
396 VisitRow visit_row; 396 VisitRow visit_row;
397 if (db_->GetRowForVisit(visit_id, &visit_row)) { 397 if (db_->GetRowForVisit(visit_id, &visit_row)) {
398 // We should never have a negative duration time even when time is skewed. 398 // We should never have a negative duration time even when time is skewed.
399 visit_row.visit_duration = end_ts > visit_row.visit_time ? 399 visit_row.visit_duration = end_ts > visit_row.visit_time ?
400 end_ts - visit_row.visit_time : TimeDelta::FromMicroseconds(0); 400 end_ts - visit_row.visit_time : TimeDelta::FromMicroseconds(0);
401 db_->UpdateVisitRow(visit_row); 401 db_->UpdateVisitRow(visit_row);
402 } 402 }
403 } 403 }
404 404
405 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) { 405 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) {
406 if (!db_) 406 if (!db_)
407 return; 407 return;
408 408
409 // Will be filled with the URL ID and the visit ID of the last addition. 409 // Will be filled with the URL ID and the visit ID of the last addition.
410 std::pair<URLID, VisitID> last_ids(0, tracker_.GetLastVisit( 410 std::pair<URLID, VisitID> last_ids(0, tracker_.GetLastVisit(
411 request.context_id, request.page_id, request.referrer)); 411 request.context_id, request.nav_entry_id, request.referrer));
412 412
413 VisitID from_visit_id = last_ids.second; 413 VisitID from_visit_id = last_ids.second;
414 414
415 // If a redirect chain is given, we expect the last item in that chain to be 415 // If a redirect chain is given, we expect the last item in that chain to be
416 // the final URL. 416 // the final URL.
417 DCHECK(request.redirects.empty() || 417 DCHECK(request.redirects.empty() ||
418 request.redirects.back() == request.url); 418 request.redirects.back() == request.url);
419 419
420 // If the user is adding older history, we need to make sure our times 420 // If the user is adding older history, we need to make sure our times
421 // are correct. 421 // are correct.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // TODO(brettw) bug 1140015: Add an "add page" notification so the history 564 // TODO(brettw) bug 1140015: Add an "add page" notification so the history
565 // views can keep in sync. 565 // views can keep in sync.
566 566
567 // Add the last visit to the tracker so we can get outgoing transitions. 567 // Add the last visit to the tracker so we can get outgoing transitions.
568 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe 568 // TODO(evanm): Due to http://b/1194536 we lose the referrers of a subframe
569 // navigation anyway, so last_visit_id is always zero for them. But adding 569 // navigation anyway, so last_visit_id is always zero for them. But adding
570 // them here confuses main frame history, so we skip them for now. 570 // them here confuses main frame history, so we skip them for now.
571 if (stripped_transition != ui::PAGE_TRANSITION_AUTO_SUBFRAME && 571 if (stripped_transition != ui::PAGE_TRANSITION_AUTO_SUBFRAME &&
572 stripped_transition != ui::PAGE_TRANSITION_MANUAL_SUBFRAME && 572 stripped_transition != ui::PAGE_TRANSITION_MANUAL_SUBFRAME &&
573 !is_keyword_generated) { 573 !is_keyword_generated) {
574 tracker_.AddVisit(request.context_id, request.page_id, request.url, 574 tracker_.AddVisit(request.context_id, request.nav_entry_id, request.url,
575 last_ids.second); 575 last_ids.second);
576 } 576 }
577 577
578 ScheduleCommit(); 578 ScheduleCommit();
579 } 579 }
580 580
581 void HistoryBackend::InitImpl(const std::string& languages) { 581 void HistoryBackend::InitImpl(const std::string& languages) {
582 DCHECK(!db_) << "Initializing HistoryBackend twice"; 582 DCHECK(!db_) << "Initializing HistoryBackend twice";
583 // In the rare case where the db fails to initialize a dialog may get shown 583 // In the rare case where the db fails to initialize a dialog may get shown
584 // the blocks the caller, yet allows other messages through. For this reason 584 // the blocks the caller, yet allows other messages through. For this reason
(...skipping 2105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 info.url_id = visit.url_id; 2690 info.url_id = visit.url_id;
2691 info.time = visit.visit_time; 2691 info.time = visit.visit_time;
2692 info.transition = visit.transition; 2692 info.transition = visit.transition;
2693 // If we don't have a delegate yet during setup or shutdown, we will drop 2693 // If we don't have a delegate yet during setup or shutdown, we will drop
2694 // these notifications. 2694 // these notifications.
2695 if (delegate_) 2695 if (delegate_)
2696 delegate_->NotifyAddVisit(info); 2696 delegate_->NotifyAddVisit(info);
2697 } 2697 }
2698 2698
2699 } // namespace history 2699 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.h ('k') | chrome/browser/history/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698