Commit 74aed422 authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Rename TabLifecycleUnit to TabLifecycleUnitExternal.

With this CL, TabLifecycleUnit is renamed to TabLifecycleUnitExternal
and it no longer inherits from LifecycleUnit. The name
"TabLifecycleUnitExternal" makes it clear that this interface is
exposed outside of chrome/browser/resource_coordinator/, and not
inheriting from LifecycleUnit restricts what's available outside
of chrome/browser/resource_coordinator/.

Also, this CL removes TabLifecycleUnitHolder.
TabLifecycleUnitExternal::FromWebContents will be implemented by
a map lookup in TabLifecycleUnitSource.

Bug: 775644
Change-Id: Ia8fa3b3a8c7f1d4289fc15f3f4d983192dda4db6
Reviewed-on: https://chromium-review.googlesource.com/788271
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521352}
parent da79010c
...@@ -2562,8 +2562,8 @@ split_static_library("browser") { ...@@ -2562,8 +2562,8 @@ split_static_library("browser") {
"resource_coordinator/lifecycle_unit.h", "resource_coordinator/lifecycle_unit.h",
"resource_coordinator/lifecycle_unit_source_observer.h", "resource_coordinator/lifecycle_unit_source_observer.h",
"resource_coordinator/tab_lifecycle_observer.h", "resource_coordinator/tab_lifecycle_observer.h",
"resource_coordinator/tab_lifecycle_unit.cc", "resource_coordinator/tab_lifecycle_unit_external.cc",
"resource_coordinator/tab_lifecycle_unit.h", "resource_coordinator/tab_lifecycle_unit_external.h",
"resource_coordinator/tab_manager.cc", "resource_coordinator/tab_manager.cc",
"resource_coordinator/tab_manager.h", "resource_coordinator/tab_manager.h",
"resource_coordinator/tab_manager_delegate_chromeos.cc", "resource_coordinator/tab_manager_delegate_chromeos.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit.h"
#include "base/macros.h"
#include "content/public/browser/web_contents_user_data.h"
namespace resource_coordinator {
namespace {
class TabLifecycleUnitHolder
: public content::WebContentsUserData<TabLifecycleUnitHolder> {
public:
explicit TabLifecycleUnitHolder(content::WebContents*) {}
TabLifecycleUnit* tab_lifecycle_unit() const { return tab_lifecycle_unit_; }
void set_tab_lifecycle_unit(TabLifecycleUnit* tab_lifecycle_unit) {
tab_lifecycle_unit_ = tab_lifecycle_unit;
}
private:
TabLifecycleUnit* tab_lifecycle_unit_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(TabLifecycleUnitHolder);
};
} // namespace
// static
TabLifecycleUnit* TabLifecycleUnit::FromWebContents(
content::WebContents* web_contents) {
TabLifecycleUnitHolder* holder =
TabLifecycleUnitHolder::FromWebContents(web_contents);
return holder ? holder->tab_lifecycle_unit() : nullptr;
}
// static
void TabLifecycleUnit::SetForWebContents(content::WebContents* web_contents,
TabLifecycleUnit* tab_lifecycle_unit) {
TabLifecycleUnitHolder::CreateForWebContents(web_contents);
TabLifecycleUnitHolder::FromWebContents(web_contents)
->set_tab_lifecycle_unit(tab_lifecycle_unit);
}
} // namespace resource_coordinator
DEFINE_WEB_CONTENTS_USER_DATA_KEY(resource_coordinator::TabLifecycleUnitHolder);
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
namespace resource_coordinator {
// static
TabLifecycleUnitExternal* TabLifecycleUnitExternal::FromWebContents(
content::WebContents* web_contents) {
// TODO(fdoray): Implement this. https://crbug.com/775644
return nullptr;
}
} // namespace resource_coordinator
...@@ -2,47 +2,42 @@ ...@@ -2,47 +2,42 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_LIFECYCLE_UNIT_H_ #ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_LIFECYCLE_UNIT_EXTERNAL_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_LIFECYCLE_UNIT_H_ #define CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_LIFECYCLE_UNIT_EXTERNAL_H_
#include "chrome/browser/resource_coordinator/lifecycle_unit.h"
namespace content { namespace content {
class RenderProcessHost;
class WebContents; class WebContents;
} // namespace content } // namespace content
namespace resource_coordinator { namespace resource_coordinator {
// Represents a tab. // Interface to control the lifecycle of a tab exposed outside of
class TabLifecycleUnit : public LifecycleUnit { // chrome/browser/resource_coordinator/.
class TabLifecycleUnitExternal {
public: public:
// Returns the TabLifecycleUnit associated with |web_contents|, or nullptr if // Returns the TabLifecycleUnitExternal associated with |web_contents|, or
// the WebContents is not associated with a tab. // nullptr if the WebContents is not associated with a tab.
static TabLifecycleUnit* FromWebContents(content::WebContents* web_contents); static TabLifecycleUnitExternal* FromWebContents(
content::WebContents* web_contents);
virtual ~TabLifecycleUnitExternal() = default;
// Returns the WebContents associated with this tab. // Returns the WebContents associated with this tab.
virtual content::WebContents* GetWebContents() const = 0; virtual content::WebContents* GetWebContents() const = 0;
// Returns the RenderProcessHost associated with this tab.
virtual content::RenderProcessHost* GetRenderProcessHost() const = 0;
// Returns true if the tab is playing audio, has played audio recently, is
// accessing the microphone, is accessing the camera or is being mirrored.
virtual bool IsMediaTab() const = 0;
// Returns true if this tab can be automatically discarded. // Returns true if this tab can be automatically discarded.
virtual bool IsAutoDiscardable() const = 0; virtual bool IsAutoDiscardable() const = 0;
// Allows/disallows this tab to be automatically discarded. // Allows/disallows this tab to be automatically discarded.
virtual void SetAutoDiscardable(bool auto_discardable) = 0; virtual void SetAutoDiscardable(bool auto_discardable) = 0;
protected: // Discards the tab.
// Sets the TabLifecycleUnit associated with |web_contents|. virtual void DiscardTab() = 0;
static void SetForWebContents(content::WebContents* web_contents,
TabLifecycleUnit* tab_lifecycle_unit); // Returns true if the tab is discarded.
virtual bool IsDiscarded() const = 0;
}; };
} // namespace resource_coordinator } // namespace resource_coordinator
#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_LIFECYCLE_UNIT_H_ #endif // CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_LIFECYCLE_UNIT_EXTERNAL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit.h"
#include "base/macros.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace resource_coordinator {
namespace {
class DummyTabLifecycleUnit : public TabLifecycleUnit {
public:
explicit DummyTabLifecycleUnit(content::WebContents* contents)
: contents_(contents) {
TabLifecycleUnit::SetForWebContents(contents_, this);
}
~DummyTabLifecycleUnit() override {
TabLifecycleUnit::SetForWebContents(contents_, nullptr);
}
// TabLifecycleUnit:
content::WebContents* GetWebContents() const override { return nullptr; }
content::RenderProcessHost* GetRenderProcessHost() const override {
return nullptr;
}
bool IsMediaTab() const override { return false; }
bool IsAutoDiscardable() const override { return false; }
void SetAutoDiscardable(bool) override {}
// LifecycleUnit:
base::string16 GetTitle() const override { return base::string16(); }
std::string GetIconURL() const override { return std::string(); }
SortKey GetSortKey() const override { return SortKey(); }
State GetState() const override { return State::LOADED; }
int GetEstimatedMemoryFreedOnDiscardKB() const override { return 0; }
bool CanDiscard(DiscardReason) const override { return false; }
bool Discard(DiscardReason) override { return false; }
private:
content::WebContents* const contents_;
DISALLOW_COPY_AND_ASSIGN(DummyTabLifecycleUnit);
};
} // namespace
using TabLifecycleUnitTest = ChromeRenderViewHostTestHarness;
TEST_F(TabLifecycleUnitTest, FromWebContentsNullByDefault) {
EXPECT_FALSE(TabLifecycleUnit::FromWebContents(web_contents()));
}
TEST_F(TabLifecycleUnitTest, SetForWebContents) {
{
DummyTabLifecycleUnit tab_lifecycle_unit(web_contents());
EXPECT_EQ(&tab_lifecycle_unit,
TabLifecycleUnit::FromWebContents(web_contents()));
}
EXPECT_FALSE(TabLifecycleUnit::FromWebContents(web_contents()));
{
DummyTabLifecycleUnit tab_lifecycle_unit(web_contents());
EXPECT_EQ(&tab_lifecycle_unit,
TabLifecycleUnit::FromWebContents(web_contents()));
}
EXPECT_FALSE(TabLifecycleUnit::FromWebContents(web_contents()));
}
} // namespace resource_coordinator
...@@ -2746,7 +2746,6 @@ test("unit_tests") { ...@@ -2746,7 +2746,6 @@ test("unit_tests") {
"../browser/page_load_metrics/observers/session_restore_page_load_metrics_observer_unittest.cc", "../browser/page_load_metrics/observers/session_restore_page_load_metrics_observer_unittest.cc",
"../browser/resource_coordinator/background_tab_navigation_throttle_unittest.cc", "../browser/resource_coordinator/background_tab_navigation_throttle_unittest.cc",
"../browser/resource_coordinator/lifecycle_unit_unittest.cc", "../browser/resource_coordinator/lifecycle_unit_unittest.cc",
"../browser/resource_coordinator/tab_lifecycle_unit_unittest.cc",
"../browser/resource_coordinator/tab_manager_delegate_chromeos_unittest.cc", "../browser/resource_coordinator/tab_manager_delegate_chromeos_unittest.cc",
"../browser/resource_coordinator/tab_manager_stats_collector_unittest.cc", "../browser/resource_coordinator/tab_manager_stats_collector_unittest.cc",
"../browser/resource_coordinator/tab_manager_unittest.cc", "../browser/resource_coordinator/tab_manager_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment