Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
fixup! FIXME: LifecycleUnits are now used for tab discarding
Browse files Browse the repository at this point in the history
  • Loading branch information
hferreiro committed Apr 27, 2018
1 parent 59183f9 commit 06917c6
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 83 deletions.
136 changes: 68 additions & 68 deletions brave/browser/resource_coordinator/guest_tab_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,71 +33,71 @@ void RestoreHelper::RemoveRestoreHelper() {

DEFINE_WEB_CONTENTS_USER_DATA_KEY(content::RestoreHelper);

namespace resource_coordinator {

GuestTabManager::GuestTabManager() : TabManager() {}

// WebContents* GuestTabManager::CreateNullContents(
// TabStripModel* model, WebContents* old_contents) {
// DCHECK_CURRENTLY_ON(BrowserThread::UI);
//
// auto tab_helper = extensions::TabHelper::FromWebContents(old_contents);
// DCHECK(tab_helper && tab_helper->guest());
//
// auto embedder = tab_helper->guest()->embedder_web_contents();
//
// WebContents::CreateParams params(old_contents->GetBrowserContext());
// params.initially_hidden = true;
// auto contents = extensions::TabHelper::CreateTab(embedder, params);
// content::RestoreHelper::CreateForWebContents(contents);
// return contents;
// }
//
// void GuestTabManager::DestroyOldContents(WebContents* old_contents) {
// DCHECK_CURRENTLY_ON(BrowserThread::UI);
//
// auto tab_helper = extensions::TabHelper::FromWebContents(old_contents);
// DCHECK(tab_helper && tab_helper->guest());
// // Let the guest destroy itself after the detach message has been
// received
// tab_helper->guest()->SetCanRunInDetachedState(false);
// }

void GuestTabManager::TabReplacedAt(TabStripModel* tab_strip_model,
content::WebContents* old_contents,
content::WebContents* new_contents,
int index) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

TabManager::TabReplacedAt(tab_strip_model, old_contents, new_contents, index);

auto helper = content::RestoreHelper::FromWebContents(new_contents);
// prevent the navigation controller from trying to autoload on
// controller->SetActive(true)
if (helper)
helper->ClearNeedsReload();
}

void GuestTabManager::ActiveTabChanged(content::WebContents* old_contents,
content::WebContents* new_contents,
int index,
int reason) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

TabManager::ActiveTabChanged(old_contents, new_contents, index, reason);
auto helper = content::RestoreHelper::FromWebContents(new_contents);
if (helper) {
helper->RemoveRestoreHelper();

new_contents->WasHidden();
new_contents->WasShown();

auto tab_helper = extensions::TabHelper::FromWebContents(new_contents);
if (!tab_helper->is_placeholder()) {
// if the helper is set this is a discarded tab so we need to reload
new_contents->GetController().Reload(content::ReloadType::NORMAL, true);
}
}
}

} // namespace resource_coordinator
//namespace resource_coordinator {
//
//GuestTabManager::GuestTabManager() : TabManager() {}
//
//WebContents* GuestTabManager::CreateNullContents(
// TabStripModel* model, WebContents* old_contents) {
// DCHECK_CURRENTLY_ON(BrowserThread::UI);
//
// auto tab_helper = extensions::TabHelper::FromWebContents(old_contents);
// DCHECK(tab_helper && tab_helper->guest());
//
// auto embedder = tab_helper->guest()->embedder_web_contents();
//
// WebContents::CreateParams params(old_contents->GetBrowserContext());
// params.initially_hidden = true;
// auto contents = extensions::TabHelper::CreateTab(embedder, params);
// content::RestoreHelper::CreateForWebContents(contents);
// return contents;
//}
//
//void GuestTabManager::DestroyOldContents(WebContents* old_contents) {
// DCHECK_CURRENTLY_ON(BrowserThread::UI);
//
// auto tab_helper = extensions::TabHelper::FromWebContents(old_contents);
// DCHECK(tab_helper && tab_helper->guest());
// // Let the guest destroy itself after the detach message has been
// received
// tab_helper->guest()->SetCanRunInDetachedState(false);
//}
//
//void GuestTabManager::TabReplacedAt(TabStripModel* tab_strip_model,
// content::WebContents* old_contents,
// content::WebContents* new_contents,
// int index) {
// DCHECK_CURRENTLY_ON(BrowserThread::UI);
//
// TabManager::TabReplacedAt(tab_strip_model, old_contents, new_contents, index);
//
// auto helper = content::RestoreHelper::FromWebContents(new_contents);
// // prevent the navigation controller from trying to autoload on
// // controller->SetActive(true)
// if (helper)
// helper->ClearNeedsReload();
//}
//
//void GuestTabManager::ActiveTabChanged(content::WebContents* old_contents,
// content::WebContents* new_contents,
// int index,
// int reason) {
// DCHECK_CURRENTLY_ON(BrowserThread::UI);
//
// TabManager::ActiveTabChanged(old_contents, new_contents, index, reason);
// auto helper = content::RestoreHelper::FromWebContents(new_contents);
// if (helper) {
// helper->RemoveRestoreHelper();
//
// new_contents->WasHidden();
// new_contents->WasShown();
//
// auto tab_helper = extensions::TabHelper::FromWebContents(new_contents);
// if (!tab_helper->is_placeholder()) {
// // if the helper is set this is a discarded tab so we need to reload
// new_contents->GetController().Reload(content::ReloadType::NORMAL, true);
// }
// }
//}
//
//} // namespace resource_coordinator
19 changes: 19 additions & 0 deletions chromium_src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,29 @@ source_set("tab_manager") {
"chrome/browser/engagement/site_engagement_service.cc",
"//chrome/browser/memory/oom_memory_details.cc",
"//chrome/browser/memory/oom_memory_details.h",
"//chrome/browser/resource_coordinator/discard_metrics_lifecycle_unit_observer.cc",
"//chrome/browser/resource_coordinator/discard_metrics_lifecycle_unit_observer.h",
"//chrome/browser/resource_coordinator/lifecycle_unit.cc",
"//chrome/browser/resource_coordinator/lifecycle_unit.h",
"//chrome/browser/resource_coordinator/lifecycle_unit_base.cc",
"//chrome/browser/resource_coordinator/lifecycle_unit_base.h",
"//chrome/browser/resource_coordinator/lifecycle_unit_observer.cc",
"//chrome/browser/resource_coordinator/lifecycle_unit_observer.h",
"//chrome/browser/resource_coordinator/lifecycle_unit_source_base.cc",
"//chrome/browser/resource_coordinator/lifecycle_unit_source_base.h",
"//chrome/browser/resource_coordinator/page_signal_receiver.cc",
"//chrome/browser/resource_coordinator/page_signal_receiver.h",
"//chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc",
"//chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.h",
"//chrome/browser/resource_coordinator/tab_lifecycle_observer.h",
"//chrome/browser/resource_coordinator/tab_lifecycle_unit.cc",
"//chrome/browser/resource_coordinator/tab_lifecycle_unit.h",
"//chrome/browser/resource_coordinator/tab_lifecycle_unit_external.cc",
"//chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h",
"//chrome/browser/resource_coordinator/tab_lifecycle_unit_source.cc",
"//chrome/browser/resource_coordinator/tab_lifecycle_unit_source.h",
"//chrome/browser/resource_coordinator/tab_load_tracker.cc",
"//chrome/browser/resource_coordinator/tab_load_tracker.h",
"//chrome/browser/resource_coordinator/tab_manager.cc",
"//chrome/browser/resource_coordinator/tab_manager.h",
"//chrome/browser/resource_coordinator/tab_manager_features.cc",
Expand Down
2 changes: 1 addition & 1 deletion chromium_src/chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ resource_coordinator::TabManager* BrowserProcessImpl::GetTabManager() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
if (!tab_manager_) {
tab_manager_ = std::make_unique<resource_coordinator::GuestTabManager>();
tab_manager_ = std::make_unique<resource_coordinator::TabManager>();
tab_lifecycle_unit_source_ =
std::make_unique<resource_coordinator::TabLifecycleUnitSource>();
tab_lifecycle_unit_source_->AddObserver(tab_manager_.get());
Expand Down
42 changes: 28 additions & 14 deletions patches/master_patch.patch
Original file line number Diff line number Diff line change
Expand Up @@ -391,39 +391,53 @@ index 9f0003bc2d80d7c76ab9dd17393d0188fe1ac6fd..88d75d4091fb3dc282998a5d44e63cbf
// content::NotificationObserver implementation.
void Observe(int type,
diff --git a/chrome/browser/resource_coordinator/tab_lifecycle_unit.cc b/chrome/browser/resource_coordinator/tab_lifecycle_unit.cc
index 1b5026face136534578062e4d3c9c0c955dadd20..a08512d67247feec1738bbc61a34665374384763 100644
index 1b5026face136534578062e4d3c9c0c955dadd20..27b2a5ce41ce523a67495f5b24d5a0be87fb501d 100644
--- a/chrome/browser/resource_coordinator/tab_lifecycle_unit.cc
+++ b/chrome/browser/resource_coordinator/tab_lifecycle_unit.cc
@@ -211,6 +211,19 @@ bool TabLifecycleUnitSource::TabLifecycleUnit::CanDiscard(
@@ -211,6 +211,26 @@ bool TabLifecycleUnitSource::TabLifecycleUnit::CanDiscard(
return true;
}

+// MUON(bridiver): see tab_lifecycle_unit.h
+WebContents* TabLifecycleUnitSource::TabLifecycleUnit::CreateNullContents(
+ content::WebContents::CreateParams create_params,
+ WebContents* old_contents) {
+ return WebContents::Create(WebContents::CreateParams(create_params));
+content::WebContents*
+TabLifecycleUnitSource::TabLifecycleUnit::CreateNullContents(
+ TabStripModel* model,
+ content::WebContents* old_contents) {
+ content::WebContents::CreateParams create_params(model->profile());
+ // TODO(fdoray): Consider setting |initially_hidden| to true when the tab is
+ // OCCLUDED. Will require checking that the tab reload correctly when it
+ // becomes VISIBLE.
+ create_params.initially_hidden =
+ old_contents->GetVisibility() == content::Visibility::HIDDEN;
+ return content::WebContents::Create(create_params);
+}
+
+// MUON(bridiver): see tab_lifecycle_unit.h
+void TabLifecycleUnitSource::TabLifecycleUnit::DestroyOldContents(
+ WebContents* old_contents) {
+ content::WebContents* old_contents) {
+ delete old_contents;
+}
+
bool TabLifecycleUnitSource::TabLifecycleUnit::Discard(
DiscardReason discard_reason) {
if (!tab_strip_model_ || IsDiscarded())
@@ -228,7 +241,7 @@ bool TabLifecycleUnitSource::TabLifecycleUnit::Discard(
create_params.initially_hidden =
old_contents->GetVisibility() == content::Visibility::HIDDEN;
@@ -221,14 +241,8 @@ bool TabLifecycleUnitSource::TabLifecycleUnit::Discard(
GetWebContents()->NeedToFireBeforeUnload());

content::WebContents* const old_contents = GetWebContents();
- content::WebContents::CreateParams create_params(tab_strip_model_->profile());
- // TODO(fdoray): Consider setting |initially_hidden| to true when the tab is
- // OCCLUDED. Will require checking that the tab reload correctly when it
- // becomes VISIBLE.
- create_params.initially_hidden =
- old_contents->GetVisibility() == content::Visibility::HIDDEN;
content::WebContents* const null_contents =
- content::WebContents::Create(create_params);
+ CreateNullContents(create_params, old_contents);
+ CreateNullContents(tab_strip_model_, old_contents);
// Copy over the state from the navigation controller to preserve the
// back/forward history and to continue to display the correct title/favicon.
//
@@ -279,7 +292,8 @@ bool TabLifecycleUnitSource::TabLifecycleUnit::Discard(
@@ -279,7 +293,8 @@ bool TabLifecycleUnitSource::TabLifecycleUnit::Discard(
// TODO(jamescook): This breaks script connections with other tabs. Find a
// different approach that doesn't do that, perhaps based on
// RenderFrameProxyHosts.
Expand All @@ -434,7 +448,7 @@ index 1b5026face136534578062e4d3c9c0c955dadd20..a08512d67247feec1738bbc61a346653
SetState(State::DISCARDED);
++discard_count_;
diff --git a/chrome/browser/resource_coordinator/tab_lifecycle_unit.h b/chrome/browser/resource_coordinator/tab_lifecycle_unit.h
index ae1fc02155c4c36f8f7015c052f58255933f88b5..d509c337c4df968df1bd9db0fdb56e30bcf9ef63 100644
index ae1fc02155c4c36f8f7015c052f58255933f88b5..be2e125ba8f07049c26c035b42bee57d02376328 100644
--- a/chrome/browser/resource_coordinator/tab_lifecycle_unit.h
+++ b/chrome/browser/resource_coordinator/tab_lifecycle_unit.h
@@ -89,6 +89,12 @@ class TabLifecycleUnitSource::TabLifecycleUnit
Expand All @@ -443,7 +457,7 @@ index ae1fc02155c4c36f8f7015c052f58255933f88b5..d509c337c4df968df1bd9db0fdb56e30

+ // MUON(bridiver): override to create/destroy guests webcontents
+ virtual content::WebContents* CreateNullContents(
+ content::WebContents::CreateParams create_params,
+ TabStripModel* model,
+ content::WebContents* old_contents);
+ virtual void DestroyOldContents(content::WebContents* old_contents);
+
Expand Down

0 comments on commit 06917c6

Please sign in to comment.