Commit 79024af7 authored by yilkal's avatar yilkal Committed by Commit Bot

Only use SupervisedUserNavigationObserver for child accounts.

This CL makes sure that SupervisedUserNavigationObserver is
created only for supervised user accounts. This saves memory
and processing time.

Bug: 1043232
Change-Id: I5d13ce0261d07c29384f5ba5dc83e420ed3138dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008315Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDan S <danan@chromium.org>
Commit-Queue: Yilkal Abe <yilkal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733750}
parent 1b50f2a9
......@@ -38,6 +38,22 @@ bool IsMainFrame(content::RenderFrameHost* render_frame_host) {
using content::NavigationEntry;
// static
void SupervisedUserNavigationObserver::MaybeCreateForWebContents(
content::WebContents* web_contents) {
DCHECK(web_contents);
Profile* user_profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
if (!user_profile->IsSupervised())
return;
if (!FromWebContents(web_contents)) {
web_contents->SetUserData(
UserDataKey(),
base::WrapUnique(new SupervisedUserNavigationObserver(web_contents)));
}
}
SupervisedUserNavigationObserver::~SupervisedUserNavigationObserver() {
supervised_user_service_->RemoveObserver(this);
}
......
......@@ -35,6 +35,10 @@ class SupervisedUserNavigationObserver
public SupervisedUserServiceObserver,
public supervised_user::mojom::SupervisedUserCommands {
public:
// Creates SupervisedUserNavigationObserver if the profile is a child user.
static void MaybeCreateForWebContents(content::WebContents* web_contents);
static void CreateForWebContents(content::WebContents* web_contents) = delete;
~SupervisedUserNavigationObserver() override;
const std::vector<std::unique_ptr<const sessions::SerializedNavigationEntry>>&
......
......@@ -372,7 +372,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
#endif
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
SupervisedUserNavigationObserver::CreateForWebContents(web_contents);
SupervisedUserNavigationObserver::MaybeCreateForWebContents(web_contents);
#endif
if (predictors::LoadingPredictorFactory::GetForProfile(profile))
......
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