Commit 7890f24a authored by Luna Lu's avatar Luna Lu Committed by Commit Bot

Add a flag in Settings for UseCounter to avoid measuring shadow pages.

Shadow page has a frame and upon service worker startup, UseCounter will
count page visits.
This CL adds a flag "is_shadow_page_" in Settings and sets the flag to
be true in WorkerPageShadow initialization (by default the flag's value
is false). In UseCounter it checks for shadow pages and drop counts for
shadow pages.

Note that this flag will eventually go away since browser side use
counter does not have problems with workers. So once the blink side
use counter is removed, this change can be undone.

This change has also been verified to work locally.

Bug: 694880
Change-Id: I1cbe857d776591098bbbbf256ef8aa546c399af5
Reviewed-on: https://chromium-review.googlesource.com/917028
Commit-Queue: Luna Lu <loonybear@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536736}
parent 46977205
......@@ -16,6 +16,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/statistics_recorder.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string16.h"
......@@ -970,6 +971,38 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartAndStop) {
stop_run_loop.Run();
}
IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest,
DropCountsOnBlinkUseCounter) {
StartServerAndNavigateToSetup();
RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread,
base::Unretained(this),
"/service_worker/worker.js"));
// Start a worker.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
base::RunLoop start_run_loop;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&self::StartOnIOThread, base::Unretained(this),
start_run_loop.QuitClosure(), &status));
start_run_loop.Run();
ASSERT_EQ(SERVICE_WORKER_OK, status);
// Expect no PageVisits count.
EXPECT_EQ(nullptr, base::StatisticsRecorder::FindHistogram(
"Blink.UseCounter.Features"));
// Stop the worker.
base::RunLoop stop_run_loop;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&self::StopOnIOThread, base::Unretained(this),
stop_run_loop.QuitClosure()));
stop_run_loop.Run();
// Expect no PageVisits count.
EXPECT_EQ(nullptr, base::StatisticsRecorder::FindHistogram(
"Blink.UseCounter.Features"));
}
IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, StartNotFound) {
StartServerAndNavigateToSetup();
RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread,
......
......@@ -5,6 +5,7 @@
#include "core/exported/WorkerShadowPage.h"
#include "core/exported/WebViewImpl.h"
#include "core/frame/Settings.h"
#include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/loader/FrameLoadRequest.h"
#include "platform/loader/fetch/SubstituteData.h"
......@@ -30,6 +31,10 @@ WorkerShadowPage::WorkerShadowPage(Client* client)
// TODO(http://crbug.com/363843): This needs to find a better way to
// not create graphics layers.
web_view_->GetSettings()->SetAcceleratedCompositingEnabled(false);
// TODO(lunalu): Service worker and shared worker count feature usage on the
// blink side use counter. Once the blink side use counter is removed
// (crbug.com/811948), remove this instant from Settings.
main_frame_->GetFrame()->GetSettings()->SetIsShadowPage(true);
main_frame_->SetDevToolsAgentImpl(
WebDevToolsAgentImpl::CreateForWorker(main_frame_, client_));
......
......@@ -62,7 +62,8 @@ static const bool kDefaultSelectTrailingWhitespaceEnabled = false;
#endif
Settings::Settings()
: text_autosizing_enabled_(false) SETTINGS_INITIALIZER_LIST {}
: text_autosizing_enabled_(false),
is_shadow_page_(false) SETTINGS_INITIALIZER_LIST {}
std::unique_ptr<Settings> Settings::Create() {
return WTF::WrapUnique(new Settings);
......@@ -106,4 +107,8 @@ bool Settings::MockScrollbarsEnabled() {
return ScrollbarTheme::MockScrollbarsEnabled();
}
void Settings::SetIsShadowPage(bool flag) {
is_shadow_page_ = flag;
}
} // namespace blink
......@@ -85,6 +85,12 @@ class CORE_EXPORT Settings {
void SetDelegate(SettingsDelegate*);
// TODO(lunalu): Service worker and shared worker count feature usage on the
// blink side use counter via the shadow page. Once blink side use counter is
// removed, this flag is no longer needed (crbug.com/811948).
void SetIsShadowPage(bool);
bool IsShadowPage() const { return is_shadow_page_; }
private:
Settings();
......@@ -95,6 +101,10 @@ class CORE_EXPORT Settings {
GenericFontFamilySettings generic_font_family_settings_;
IntSize text_autosizing_window_size_override_;
bool text_autosizing_enabled_ : 1;
// TODO(lunalu): Service worker is counting feature usage on the blink side
// use counter via the shadow page. Once blink side use counter is removed,
// this flag is no longer needed (crbug.com/811948).
bool is_shadow_page_;
SETTINGS_MEMBER_VARIABLES
......
......@@ -34,6 +34,7 @@
#include "core/frame/FrameConsole.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/LocalFrameClient.h"
#include "core/frame/Settings.h"
#include "core/inspector/ConsoleMessage.h"
#include "core/page/Page.h"
#include "core/workers/WorkerOrWorkletGlobalScope.h"
......@@ -1268,6 +1269,11 @@ void UseCounter::DidCommitLoad(const LocalFrame* frame) {
context_ = kDisabledContext;
else if (frame->GetDocument()->IsPrefetchOnly())
context_ = kDisabledContext;
// TODO(lunalu): Service worker and shared worker count feature usage on the
// blink side use counter. Once the blink side use counter is removed
// (crbug.com/811948), the checker for shadow pages should be removed.
else if (frame->GetSettings()->IsShadowPage())
context_ = kDisabledContext;
else if (SchemeRegistry::ShouldTrackUsageMetricsForScheme(url.Protocol()))
context_ = kDefaultContext;
else
......
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