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

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

Issue 69013004: Renamed CanPruneAllButVisible and PruneAllButVisible in the Navigation Controller to CanPruneAllBut… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed some unit tests Created 7 years, 1 month 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 | Annotate | Revision Log
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 #include "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" // Temporary 10 #include "base/strings/string_number_conversions.h" // Temporary
(...skipping 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 1222
1223 // Copy the max page id map from the old tab to the new tab. This ensures 1223 // Copy the max page id map from the old tab to the new tab. This ensures
1224 // that new and existing navigations in the tab's current SiteInstances 1224 // that new and existing navigations in the tab's current SiteInstances
1225 // are identified properly. 1225 // are identified properly.
1226 delegate_->CopyMaxPageIDsFrom(source.delegate()->GetWebContents()); 1226 delegate_->CopyMaxPageIDsFrom(source.delegate()->GetWebContents());
1227 } 1227 }
1228 1228
1229 void NavigationControllerImpl::CopyStateFromAndPrune( 1229 void NavigationControllerImpl::CopyStateFromAndPrune(
1230 NavigationController* temp) { 1230 NavigationController* temp) {
1231 // It is up to callers to check the invariants before calling this. 1231 // It is up to callers to check the invariants before calling this.
1232 CHECK(CanPruneAllButVisible()); 1232 CHECK(CanPruneAllButLastCommitted());
1233 1233
1234 NavigationControllerImpl* source = 1234 NavigationControllerImpl* source =
1235 static_cast<NavigationControllerImpl*>(temp); 1235 static_cast<NavigationControllerImpl*>(temp);
1236 // The SiteInstance and page_id of the last committed entry needs to be 1236 // The SiteInstance and page_id of the last committed entry needs to be
1237 // remembered at this point, in case there is only one committed entry 1237 // remembered at this point, in case there is only one committed entry
1238 // and it is pruned. We use a scoped_refptr to ensure the SiteInstance 1238 // and it is pruned. We use a scoped_refptr to ensure the SiteInstance
1239 // can't be freed during this time period. 1239 // can't be freed during this time period.
1240 NavigationEntryImpl* last_committed = 1240 NavigationEntryImpl* last_committed =
1241 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); 1241 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry());
1242 scoped_refptr<SiteInstance> site_instance( 1242 scoped_refptr<SiteInstance> site_instance(
1243 last_committed->site_instance()); 1243 last_committed->site_instance());
1244 int32 minimum_page_id = last_committed->GetPageID(); 1244 int32 minimum_page_id = last_committed->GetPageID();
1245 int32 max_page_id = 1245 int32 max_page_id =
1246 delegate_->GetMaxPageIDForSiteInstance(site_instance.get()); 1246 delegate_->GetMaxPageIDForSiteInstance(site_instance.get());
1247 1247
1248 // Remove all the entries leaving the active entry. 1248 // Remove all the entries leaving the active entry.
1249 PruneAllButVisibleInternal(); 1249 PruneAllButLastCommittedInternal();
1250 1250
1251 // We now have one entry, possibly with a new pending entry. Ensure that 1251 // We now have one entry, possibly with a new pending entry. Ensure that
1252 // adding the entries from source won't put us over the limit. 1252 // adding the entries from source won't put us over the limit.
1253 DCHECK_EQ(1, GetEntryCount()); 1253 DCHECK_EQ(1, GetEntryCount());
1254 source->PruneOldestEntryIfFull(); 1254 source->PruneOldestEntryIfFull();
1255 1255
1256 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as 1256 // Insert the entries from source. Don't use source->GetCurrentEntryIndex as
1257 // we don't want to copy over the transient entry. Ignore any pending entry, 1257 // we don't want to copy over the transient entry. Ignore any pending entry,
1258 // since it has not committed in source. 1258 // since it has not committed in source.
1259 int max_source_index = source->last_committed_entry_index_; 1259 int max_source_index = source->last_committed_entry_index_;
(...skipping 16 matching lines...) Expand all
1276 delegate_->CopyMaxPageIDsFrom(source->delegate()->GetWebContents()); 1276 delegate_->CopyMaxPageIDsFrom(source->delegate()->GetWebContents());
1277 1277
1278 // If there is a last committed entry, be sure to include it in the new 1278 // If there is a last committed entry, be sure to include it in the new
1279 // max page ID map. 1279 // max page ID map.
1280 if (max_page_id > -1) { 1280 if (max_page_id > -1) {
1281 delegate_->UpdateMaxPageIDForSiteInstance(site_instance.get(), 1281 delegate_->UpdateMaxPageIDForSiteInstance(site_instance.get(),
1282 max_page_id); 1282 max_page_id);
1283 } 1283 }
1284 } 1284 }
1285 1285
1286 bool NavigationControllerImpl::CanPruneAllButVisible() { 1286 bool NavigationControllerImpl::CanPruneAllButLastCommitted() {
1287 // If there is no last committed entry, we cannot prune. Even if there is a 1287 // If there is no last committed entry, we cannot prune. Even if there is a
1288 // pending entry, it may not commit, leaving this WebContents blank, despite 1288 // pending entry, it may not commit, leaving this WebContents blank, despite
1289 // possibly giving it new entries via CopyStateFromAndPrune. 1289 // possibly giving it new entries via CopyStateFromAndPrune.
1290 if (last_committed_entry_index_ == -1) 1290 if (last_committed_entry_index_ == -1)
1291 return false; 1291 return false;
1292 1292
1293 // We cannot prune if there is a pending entry at an existing entry index. 1293 // We cannot prune if there is a pending entry at an existing entry index.
1294 // It may not commit, so we have to keep the last committed entry, and thus 1294 // It may not commit, so we have to keep the last committed entry, and thus
1295 // there is no sensible place to keep the pending entry. It is ok to have 1295 // there is no sensible place to keep the pending entry. It is ok to have
1296 // a new pending entry, which can optionally commit as a new navigation. 1296 // a new pending entry, which can optionally commit as a new navigation.
1297 if (pending_entry_index_ != -1) 1297 if (pending_entry_index_ != -1)
1298 return false; 1298 return false;
1299 1299
1300 // We should not prune if we are currently showing a transient entry. 1300 // We should not prune if we are currently showing a transient entry.
1301 if (transient_entry_index_ != -1) 1301 if (transient_entry_index_ != -1)
1302 return false; 1302 return false;
1303 1303
1304 return true; 1304 return true;
1305 } 1305 }
1306 1306
1307 void NavigationControllerImpl::PruneAllButVisible() { 1307 void NavigationControllerImpl::PruneAllButLastCommitted() {
1308 PruneAllButVisibleInternal(); 1308 PruneAllButLastCommittedInternal();
1309 1309
1310 // We should still have a last committed entry. 1310 // We should still have a last committed entry.
1311 DCHECK_NE(-1, last_committed_entry_index_); 1311 DCHECK_NE(-1, last_committed_entry_index_);
1312 1312
1313 // We pass 0 instead of GetEntryCount() for the history_length parameter of 1313 // We pass 0 instead of GetEntryCount() for the history_length parameter of
1314 // SetHistoryLengthAndPrune, because it will create history_length additional 1314 // SetHistoryLengthAndPrune, because it will create history_length additional
1315 // history entries. 1315 // history entries.
1316 // TODO(jochen): This API is confusing and we should clean it up. 1316 // TODO(jochen): This API is confusing and we should clean it up.
1317 // http://crbug.com/178491 1317 // http://crbug.com/178491
1318 NavigationEntryImpl* entry = 1318 NavigationEntryImpl* entry =
1319 NavigationEntryImpl::FromNavigationEntry(GetVisibleEntry()); 1319 NavigationEntryImpl::FromNavigationEntry(GetVisibleEntry());
1320 delegate_->SetHistoryLengthAndPrune( 1320 delegate_->SetHistoryLengthAndPrune(
1321 entry->site_instance(), 0, entry->GetPageID()); 1321 entry->site_instance(), 0, entry->GetPageID());
1322 } 1322 }
1323 1323
1324 void NavigationControllerImpl::PruneAllButVisibleInternal() { 1324 void NavigationControllerImpl::PruneAllButLastCommittedInternal() {
1325 // It is up to callers to check the invariants before calling this. 1325 // It is up to callers to check the invariants before calling this.
1326 CHECK(CanPruneAllButVisible()); 1326 CHECK(CanPruneAllButLastCommitted());
1327 1327
1328 // Erase all entries but the last committed entry. There may still be a 1328 // Erase all entries but the last committed entry. There may still be a
1329 // new pending entry after this. 1329 // new pending entry after this.
1330 entries_.erase(entries_.begin(), 1330 entries_.erase(entries_.begin(),
1331 entries_.begin() + last_committed_entry_index_); 1331 entries_.begin() + last_committed_entry_index_);
1332 entries_.erase(entries_.begin() + 1, entries_.end()); 1332 entries_.erase(entries_.begin() + 1, entries_.end());
1333 last_committed_entry_index_ = 0; 1333 last_committed_entry_index_ = 0;
1334 } 1334 }
1335 1335
1336 void NavigationControllerImpl::ClearAllScreenshots() { 1336 void NavigationControllerImpl::ClearAllScreenshots() {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 } 1681 }
1682 } 1682 }
1683 } 1683 }
1684 1684
1685 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1685 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1686 const base::Callback<base::Time()>& get_timestamp_callback) { 1686 const base::Callback<base::Time()>& get_timestamp_callback) {
1687 get_timestamp_callback_ = get_timestamp_callback; 1687 get_timestamp_callback_ = get_timestamp_callback;
1688 } 1688 }
1689 1689
1690 } // namespace content 1690 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698