Commit bdb95bb9 authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

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

This is a reland of 8f4ffc9a with a fix
for a flakiness in LocalSiteCharacteristicsDatabaseTest.PRE_ClearHistory,
the HistoryService::Delete task didn't always had time to run before we
assumed that the entry had been removed from the history, this fix this
by running RunUntilIdle() several time (until the deletion has
complete)



Original change's description:
> 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: François Doray <fdoray@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#568519}

Bug: 773382
Change-Id: I05072f974d70c200fff87e0239c8537c8d0bcfc8
Reviewed-on: https://chromium-review.googlesource.com/1106940
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569311}
parent cb9aed04
......@@ -101,6 +101,8 @@ class LocalSiteCharacteristicsDataImpl
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 {
return loaded_tabs_in_background_count_;
}
......
......@@ -66,6 +66,8 @@ void LocalSiteCharacteristicsDataWriter::NotifyUpdatesTitleInBackground() {
void LocalSiteCharacteristicsDataWriter::NotifyUsesAudioInBackground() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
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();
}
......
......@@ -27,6 +27,10 @@
#include "services/resource_coordinator/public/mojom/service_constants.mojom.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(
resource_coordinator::ResourceCoordinatorTabHelper);
......@@ -62,6 +66,14 @@ ResourceCoordinatorTabHelper::ResourceCoordinatorTabHelper(
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;
......
......@@ -9,6 +9,7 @@
#include "base/macros.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_user_data.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
......@@ -17,6 +18,7 @@
namespace resource_coordinator {
class PageResourceCoordinator;
class LocalSiteCharacteristicsWebContentsObserver;
class ResourceCoordinatorTabHelper
: public content::WebContentsObserver,
......@@ -63,6 +65,11 @@ class ResourceCoordinatorTabHelper
page_resource_coordinator_;
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
// 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
......
......@@ -697,6 +697,7 @@ test("browser_tests") {
"../browser/renderer_host/render_process_host_chrome_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_database_browsertest.cc",
"../browser/resource_coordinator/render_process_probe_browsertest.cc",
"../browser/resource_coordinator/tab_activity_watcher_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