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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl.cc

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 /* 5 /*
6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * 10 *
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 423 }
424 424
425 bool NavigationControllerImpl::IsInitialBlankNavigation() const { 425 bool NavigationControllerImpl::IsInitialBlankNavigation() const {
426 // TODO(creis): Once we create a NavigationEntry for the initial blank page, 426 // TODO(creis): Once we create a NavigationEntry for the initial blank page,
427 // we'll need to check for entry count 1 and restore_type RESTORE_NONE (to 427 // we'll need to check for entry count 1 and restore_type RESTORE_NONE (to
428 // exclude the cloned tab case). 428 // exclude the cloned tab case).
429 return IsInitialNavigation() && GetEntryCount() == 0; 429 return IsInitialNavigation() && GetEntryCount() == 0;
430 } 430 }
431 431
432 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID( 432 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID(
433 SiteInstance* instance, int32 page_id) const { 433 SiteInstance* instance,
434 int32_t page_id) const {
434 int index = GetEntryIndexWithPageID(instance, page_id); 435 int index = GetEntryIndexWithPageID(instance, page_id);
435 return (index != -1) ? entries_[index].get() : nullptr; 436 return (index != -1) ? entries_[index].get() : nullptr;
436 } 437 }
437 438
438 NavigationEntryImpl* 439 NavigationEntryImpl*
439 NavigationControllerImpl::GetEntryWithUniqueID(int nav_entry_id) const { 440 NavigationControllerImpl::GetEntryWithUniqueID(int nav_entry_id) const {
440 int index = GetEntryIndexWithUniqueID(nav_entry_id); 441 int index = GetEntryIndexWithUniqueID(nav_entry_id);
441 return (index != -1) ? entries_[index].get() : nullptr; 442 return (index != -1) ? entries_[index].get() : nullptr;
442 } 443 }
443 444
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 // Adjust indices such that the last entry and pending are at the end now. 1485 // Adjust indices such that the last entry and pending are at the end now.
1485 last_committed_entry_index_ = GetEntryCount() - 1; 1486 last_committed_entry_index_ = GetEntryCount() - 1;
1486 1487
1487 delegate_->SetHistoryOffsetAndLength(last_committed_entry_index_, 1488 delegate_->SetHistoryOffsetAndLength(last_committed_entry_index_,
1488 GetEntryCount()); 1489 GetEntryCount());
1489 1490
1490 // Copy the max page id map from the old tab to the new tab. This ensures that 1491 // Copy the max page id map from the old tab to the new tab. This ensures that
1491 // new and existing navigations in the tab's current SiteInstances are 1492 // new and existing navigations in the tab's current SiteInstances are
1492 // identified properly. 1493 // identified properly.
1493 NavigationEntryImpl* last_committed = GetLastCommittedEntry(); 1494 NavigationEntryImpl* last_committed = GetLastCommittedEntry();
1494 int32 site_max_page_id = 1495 int32_t site_max_page_id =
1495 delegate_->GetMaxPageIDForSiteInstance(last_committed->site_instance()); 1496 delegate_->GetMaxPageIDForSiteInstance(last_committed->site_instance());
1496 delegate_->CopyMaxPageIDsFrom(source->delegate()->GetWebContents()); 1497 delegate_->CopyMaxPageIDsFrom(source->delegate()->GetWebContents());
1497 delegate_->UpdateMaxPageIDForSiteInstance(last_committed->site_instance(), 1498 delegate_->UpdateMaxPageIDForSiteInstance(last_committed->site_instance(),
1498 site_max_page_id); 1499 site_max_page_id);
1499 max_restored_page_id_ = source->max_restored_page_id_; 1500 max_restored_page_id_ = source->max_restored_page_id_;
1500 } 1501 }
1501 1502
1502 bool NavigationControllerImpl::CanPruneAllButLastCommitted() { 1503 bool NavigationControllerImpl::CanPruneAllButLastCommitted() {
1503 // If there is no last committed entry, we cannot prune. Even if there is a 1504 // If there is no last committed entry, we cannot prune. Even if there is a
1504 // pending entry, it may not commit, leaving this WebContents blank, despite 1505 // pending entry, it may not commit, leaving this WebContents blank, despite
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 // Attempts to do so may give a tab access to another tab's session storage 1557 // Attempts to do so may give a tab access to another tab's session storage
1557 // so die hard on an error. 1558 // so die hard on an error.
1558 bool successful_insert = session_storage_namespace_map_.insert( 1559 bool successful_insert = session_storage_namespace_map_.insert(
1559 make_pair(partition_id, 1560 make_pair(partition_id,
1560 static_cast<SessionStorageNamespaceImpl*>( 1561 static_cast<SessionStorageNamespaceImpl*>(
1561 session_storage_namespace))) 1562 session_storage_namespace)))
1562 .second; 1563 .second;
1563 CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace"; 1564 CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace";
1564 } 1565 }
1565 1566
1566 void NavigationControllerImpl::SetMaxRestoredPageID(int32 max_id) { 1567 void NavigationControllerImpl::SetMaxRestoredPageID(int32_t max_id) {
1567 max_restored_page_id_ = max_id; 1568 max_restored_page_id_ = max_id;
1568 } 1569 }
1569 1570
1570 int32 NavigationControllerImpl::GetMaxRestoredPageID() const { 1571 int32_t NavigationControllerImpl::GetMaxRestoredPageID() const {
1571 return max_restored_page_id_; 1572 return max_restored_page_id_;
1572 } 1573 }
1573 1574
1574 bool NavigationControllerImpl::IsUnmodifiedBlankTab() const { 1575 bool NavigationControllerImpl::IsUnmodifiedBlankTab() const {
1575 return IsInitialNavigation() && 1576 return IsInitialNavigation() &&
1576 !GetLastCommittedEntry() && 1577 !GetLastCommittedEntry() &&
1577 !delegate_->HasAccessedInitialDocument(); 1578 !delegate_->HasAccessedInitialDocument();
1578 } 1579 }
1579 1580
1580 SessionStorageNamespace* 1581 SessionStorageNamespace*
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 // so don't copy anything. 1674 // so don't copy anything.
1674 if (pending_entry_ && pending_entry_index_ == -1) 1675 if (pending_entry_ && pending_entry_index_ == -1)
1675 entry->set_unique_id(pending_entry_->GetUniqueID()); 1676 entry->set_unique_id(pending_entry_->GetUniqueID());
1676 1677
1677 DiscardNonCommittedEntriesInternal(); 1678 DiscardNonCommittedEntriesInternal();
1678 1679
1679 int current_size = static_cast<int>(entries_.size()); 1680 int current_size = static_cast<int>(entries_.size());
1680 1681
1681 // When replacing, don't prune the forward history. 1682 // When replacing, don't prune the forward history.
1682 if (replace && current_size > 0) { 1683 if (replace && current_size > 0) {
1683 int32 page_id = entry->GetPageID(); 1684 int32_t page_id = entry->GetPageID();
1684 1685
1685 entries_[last_committed_entry_index_] = entry.Pass(); 1686 entries_[last_committed_entry_index_] = entry.Pass();
1686 1687
1687 // This is a new page ID, so we need everybody to know about it. 1688 // This is a new page ID, so we need everybody to know about it.
1688 delegate_->UpdateMaxPageID(page_id); 1689 delegate_->UpdateMaxPageID(page_id);
1689 return; 1690 return;
1690 } 1691 }
1691 1692
1692 // We shouldn't see replace == true when there's no committed entries. 1693 // We shouldn't see replace == true when there's no committed entries.
1693 DCHECK(!replace); 1694 DCHECK(!replace);
1694 1695
1695 if (current_size > 0) { 1696 if (current_size > 0) {
1696 // Prune any entries which are in front of the current entry. 1697 // Prune any entries which are in front of the current entry.
1697 // last_committed_entry_index_ must be updated here since calls to 1698 // last_committed_entry_index_ must be updated here since calls to
1698 // NotifyPrunedEntries() below may re-enter and we must make sure 1699 // NotifyPrunedEntries() below may re-enter and we must make sure
1699 // last_committed_entry_index_ is not left in an invalid state. 1700 // last_committed_entry_index_ is not left in an invalid state.
1700 int num_pruned = 0; 1701 int num_pruned = 0;
1701 while (last_committed_entry_index_ < (current_size - 1)) { 1702 while (last_committed_entry_index_ < (current_size - 1)) {
1702 num_pruned++; 1703 num_pruned++;
1703 entries_.pop_back(); 1704 entries_.pop_back();
1704 current_size--; 1705 current_size--;
1705 } 1706 }
1706 if (num_pruned > 0) // Only notify if we did prune something. 1707 if (num_pruned > 0) // Only notify if we did prune something.
1707 NotifyPrunedEntries(this, false, num_pruned); 1708 NotifyPrunedEntries(this, false, num_pruned);
1708 } 1709 }
1709 1710
1710 PruneOldestEntryIfFull(); 1711 PruneOldestEntryIfFull();
1711 1712
1712 int32 page_id = entry->GetPageID(); 1713 int32_t page_id = entry->GetPageID();
1713 entries_.push_back(entry.Pass()); 1714 entries_.push_back(entry.Pass());
1714 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; 1715 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1;
1715 1716
1716 // This is a new page ID, so we need everybody to know about it. 1717 // This is a new page ID, so we need everybody to know about it.
1717 delegate_->UpdateMaxPageID(page_id); 1718 delegate_->UpdateMaxPageID(page_id);
1718 } 1719 }
1719 1720
1720 void NavigationControllerImpl::PruneOldestEntryIfFull() { 1721 void NavigationControllerImpl::PruneOldestEntryIfFull() {
1721 if (entries_.size() >= max_entry_count()) { 1722 if (entries_.size() >= max_entry_count()) {
1722 DCHECK_EQ(max_entry_count(), entries_.size()); 1723 DCHECK_EQ(max_entry_count(), entries_.size());
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1943 NOTIFICATION_NAV_ENTRY_CHANGED, 1944 NOTIFICATION_NAV_ENTRY_CHANGED,
1944 Source<NavigationController>(this), 1945 Source<NavigationController>(this),
1945 Details<EntryChangedDetails>(&det)); 1946 Details<EntryChangedDetails>(&det));
1946 } 1947 }
1947 1948
1948 void NavigationControllerImpl::FinishRestore(int selected_index, 1949 void NavigationControllerImpl::FinishRestore(int selected_index,
1949 RestoreType type) { 1950 RestoreType type) {
1950 DCHECK(selected_index >= 0 && selected_index < GetEntryCount()); 1951 DCHECK(selected_index >= 0 && selected_index < GetEntryCount());
1951 ConfigureEntriesForRestore(&entries_, type); 1952 ConfigureEntriesForRestore(&entries_, type);
1952 1953
1953 SetMaxRestoredPageID(static_cast<int32>(GetEntryCount())); 1954 SetMaxRestoredPageID(static_cast<int32_t>(GetEntryCount()));
1954 1955
1955 last_committed_entry_index_ = selected_index; 1956 last_committed_entry_index_ = selected_index;
1956 } 1957 }
1957 1958
1958 void NavigationControllerImpl::DiscardNonCommittedEntriesInternal() { 1959 void NavigationControllerImpl::DiscardNonCommittedEntriesInternal() {
1959 DiscardPendingEntry(false); 1960 DiscardPendingEntry(false);
1960 DiscardTransientEntry(); 1961 DiscardTransientEntry();
1961 } 1962 }
1962 1963
1963 void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) { 1964 void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) {
(...skipping 19 matching lines...) Expand all
1983 1984
1984 void NavigationControllerImpl::DiscardTransientEntry() { 1985 void NavigationControllerImpl::DiscardTransientEntry() {
1985 if (transient_entry_index_ == -1) 1986 if (transient_entry_index_ == -1)
1986 return; 1987 return;
1987 entries_.erase(entries_.begin() + transient_entry_index_); 1988 entries_.erase(entries_.begin() + transient_entry_index_);
1988 if (last_committed_entry_index_ > transient_entry_index_) 1989 if (last_committed_entry_index_ > transient_entry_index_)
1989 last_committed_entry_index_--; 1990 last_committed_entry_index_--;
1990 transient_entry_index_ = -1; 1991 transient_entry_index_ = -1;
1991 } 1992 }
1992 1993
1993 int NavigationControllerImpl::GetEntryIndexWithPageID( 1994 int NavigationControllerImpl::GetEntryIndexWithPageID(SiteInstance* instance,
1994 SiteInstance* instance, int32 page_id) const { 1995 int32_t page_id) const {
1995 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { 1996 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) {
1996 if ((entries_[i]->site_instance() == instance) && 1997 if ((entries_[i]->site_instance() == instance) &&
1997 (entries_[i]->GetPageID() == page_id)) 1998 (entries_[i]->GetPageID() == page_id))
1998 return i; 1999 return i;
1999 } 2000 }
2000 return -1; 2001 return -1;
2001 } 2002 }
2002 2003
2003 int NavigationControllerImpl::GetEntryIndexWithUniqueID( 2004 int NavigationControllerImpl::GetEntryIndexWithUniqueID(
2004 int nav_entry_id) const { 2005 int nav_entry_id) const {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 } 2045 }
2045 } 2046 }
2046 } 2047 }
2047 2048
2048 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 2049 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
2049 const base::Callback<base::Time()>& get_timestamp_callback) { 2050 const base::Callback<base::Time()>& get_timestamp_callback) {
2050 get_timestamp_callback_ = get_timestamp_callback; 2051 get_timestamp_callback_ = get_timestamp_callback;
2051 } 2052 }
2052 2053
2053 } // namespace content 2054 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698