Commit 8f4ffc9a authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

RC: Connect the Local DB to TabHelper and add browsertests.

Bug: 773382
Change-Id: Ie7cbbf2c74bfbf1f1522b2a1f775a392545ad0a9
Reviewed-on: https://chromium-review.googlesource.com/1088196
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568519}
parent 001e5c67
...@@ -101,6 +101,8 @@ class LocalSiteCharacteristicsDataImpl ...@@ -101,6 +101,8 @@ class LocalSiteCharacteristicsDataImpl
return site_characteristics_; return site_characteristics_;
} }
size_t loaded_tabs_count_for_testing() const { return loaded_tabs_count_; }
size_t loaded_tabs_in_background_count_for_testing() const { size_t loaded_tabs_in_background_count_for_testing() const {
return loaded_tabs_in_background_count_; return loaded_tabs_in_background_count_;
} }
......
...@@ -66,6 +66,8 @@ void LocalSiteCharacteristicsDataWriter::NotifyUpdatesTitleInBackground() { ...@@ -66,6 +66,8 @@ void LocalSiteCharacteristicsDataWriter::NotifyUpdatesTitleInBackground() {
void LocalSiteCharacteristicsDataWriter::NotifyUsesAudioInBackground() { void LocalSiteCharacteristicsDataWriter::NotifyUsesAudioInBackground() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(TabVisibility::kBackground, tab_visibility_); DCHECK_EQ(TabVisibility::kBackground, tab_visibility_);
// TODO(sebmarchand): Do not advance the background audio observation time
// when the WebContents has never played audio.
impl_->NotifyUsesAudioInBackground(); impl_->NotifyUsesAudioInBackground();
} }
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
#include "services/resource_coordinator/public/mojom/service_constants.mojom.h" #include "services/resource_coordinator/public/mojom/service_constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/resource_coordinator/local_site_characteristics_webcontents_observer.h"
#endif
DEFINE_WEB_CONTENTS_USER_DATA_KEY( DEFINE_WEB_CONTENTS_USER_DATA_KEY(
resource_coordinator::ResourceCoordinatorTabHelper); resource_coordinator::ResourceCoordinatorTabHelper);
...@@ -62,6 +66,14 @@ ResourceCoordinatorTabHelper::ResourceCoordinatorTabHelper( ...@@ -62,6 +66,14 @@ ResourceCoordinatorTabHelper::ResourceCoordinatorTabHelper(
TabMemoryMetricsReporter::Get()->StartReporting(TabLoadTracker::Get()); TabMemoryMetricsReporter::Get()->StartReporting(TabLoadTracker::Get());
} }
#if !defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(features::kSiteCharacteristicsDatabase)) {
local_site_characteristics_wc_observer_ =
std::make_unique<LocalSiteCharacteristicsWebContentsObserver>(
web_contents);
}
#endif
} }
ResourceCoordinatorTabHelper::~ResourceCoordinatorTabHelper() = default; ResourceCoordinatorTabHelper::~ResourceCoordinatorTabHelper() = default;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
#include "services/metrics/public/cpp/ukm_source_id.h" #include "services/metrics/public/cpp/ukm_source_id.h"
...@@ -17,6 +18,7 @@ ...@@ -17,6 +18,7 @@
namespace resource_coordinator { namespace resource_coordinator {
class PageResourceCoordinator; class PageResourceCoordinator;
class LocalSiteCharacteristicsWebContentsObserver;
class ResourceCoordinatorTabHelper class ResourceCoordinatorTabHelper
: public content::WebContentsObserver, : public content::WebContentsObserver,
...@@ -63,6 +65,11 @@ class ResourceCoordinatorTabHelper ...@@ -63,6 +65,11 @@ class ResourceCoordinatorTabHelper
page_resource_coordinator_; page_resource_coordinator_;
ukm::SourceId ukm_source_id_ = ukm::kInvalidSourceId; ukm::SourceId ukm_source_id_ = ukm::kInvalidSourceId;
#if !defined(OS_ANDROID)
std::unique_ptr<LocalSiteCharacteristicsWebContentsObserver>
local_site_characteristics_wc_observer_;
#endif
// Favicon and title are set when a page is loaded, we only want to send // Favicon and title are set when a page is loaded, we only want to send
// signals to GRC about title and favicon update from the previous title and // signals to GRC about title and favicon update from the previous title and
// favicon, thus we want to ignore the very first update since it is always // favicon, thus we want to ignore the very first update since it is always
......
...@@ -697,6 +697,7 @@ test("browser_tests") { ...@@ -697,6 +697,7 @@ test("browser_tests") {
"../browser/renderer_host/render_process_host_chrome_browsertest.cc", "../browser/renderer_host/render_process_host_chrome_browsertest.cc",
"../browser/repost_form_warning_browsertest.cc", "../browser/repost_form_warning_browsertest.cc",
"../browser/resource_coordinator/local_site_characteristics_data_store_factory_browsertest.cc", "../browser/resource_coordinator/local_site_characteristics_data_store_factory_browsertest.cc",
"../browser/resource_coordinator/local_site_characteristics_database_browsertest.cc",
"../browser/resource_coordinator/render_process_probe_browsertest.cc", "../browser/resource_coordinator/render_process_probe_browsertest.cc",
"../browser/resource_coordinator/tab_activity_watcher_browsertest.cc", "../browser/resource_coordinator/tab_activity_watcher_browsertest.cc",
"../browser/resource_coordinator/tab_manager_browsertest.cc", "../browser/resource_coordinator/tab_manager_browsertest.cc",
......
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Site Characteristics Database Test Page</title>
</head>
<body>
<script>
// Requests permission to display Web Notifications.
function RequestNotificationsPermission() {
Notification.requestPermission(function (level) {
domAutomationController.send(level);
});
}
// Instantiates a new non-persistent notification with the given |title|
// and |options| and then closes it.
function DisplayAndCloseNonPersistentNotification(title, options) {
const notification = new Notification(title, options || {});
notification.addEventListener('show', e => {
notification.close();
});
notification.addEventListener('close', e => {
domAutomationController.send('ok');
});
}
// Play |test_audio.ogg|.
function PlayAudio() {
var audio = new Audio('test_audio.ogg');
audio.addEventListener('loadeddata', function () {
audio.play();
})
}
// Change the page title to |new_title|
function ChangeTitle(new_title) {
document.title = new_title;
}
// Change the favicon to |default_favicon.png|.
function ChangeFavicon() {
favicon = document.createElement('link');
favicon.setAttribute('rel', 'shortcut icon');
var head = document.querySelector('head');
head.appendChild(favicon);
favicon.setAttribute('type', 'image/png');
favicon.setAttribute('href', 'default_favicon.png');
}
</script>
</body>
</html>
\ No newline at end of file
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