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

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

Powered by Google App Engine
This is Rietveld 408576698