Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CSC] Save a pref if user navigated to exps success page
This CL adds a pref if the user navigated to the exps registration success page. This will be used to enable companion. (cherry picked from commit df8cc7f) Bug: b/285064611, 1449021 Change-Id: Ifa272a73c33ab49400cd89855b79c7dc37a80bd8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4583554 Reviewed-by: Tarun Bansal <tbansal@chromium.org> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org> Commit-Queue: Shakti Sahu <shaktisahu@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1155070} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4610163 Reviewed-by: Shakti Sahu <shaktisahu@chromium.org> Commit-Queue: Tarun Bansal <tbansal@chromium.org> Cr-Commit-Position: refs/branch-heads/5790@{#700} Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
- Loading branch information
Shakti Sahu
authored and
Chromium LUCI CQ
committed
Jun 13, 2023
1 parent
a0c15b6
commit 96d8cbe
Showing
9 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
chrome/browser/ui/side_panel/companion/exps_registration_success_observer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/side_panel/companion/exps_registration_success_observer.h" | ||
|
||
#include "base/strings/string_split.h" | ||
#include "chrome/browser/companion/core/constants.h" | ||
#include "chrome/browser/companion/core/features.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "content/public/browser/web_contents.h" | ||
|
||
namespace companion { | ||
|
||
ExpsRegistrationSuccessObserver::ExpsRegistrationSuccessObserver( | ||
content::WebContents* web_contents) | ||
: content::WebContentsObserver(web_contents), | ||
content::WebContentsUserData<ExpsRegistrationSuccessObserver>( | ||
*web_contents) { | ||
const auto& url_strings_to_match = base::SplitString( | ||
companion::features::kExpsRegistrationSuccessPageURLs.Get(), ",", | ||
base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | ||
for (const auto& url_string : url_strings_to_match) { | ||
urls_to_match_against_.emplace_back(url_string); | ||
} | ||
} | ||
|
||
ExpsRegistrationSuccessObserver::~ExpsRegistrationSuccessObserver() = default; | ||
|
||
void ExpsRegistrationSuccessObserver::PrimaryPageChanged(content::Page& page) { | ||
PrefService* pref_service = | ||
Profile::FromBrowserContext(web_contents()->GetBrowserContext()) | ||
->GetPrefs(); | ||
if (pref_service->GetBoolean(kHasNavigatedToExpsSuccessPage)) { | ||
return; | ||
} | ||
bool matches_exps_url = false; | ||
const GURL& url = page.GetMainDocument().GetLastCommittedURL(); | ||
for (const auto& url_to_match : urls_to_match_against_) { | ||
if (url == url_to_match) { | ||
matches_exps_url = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!matches_exps_url) { | ||
return; | ||
} | ||
|
||
// Save the status to a pref. | ||
pref_service->SetBoolean(kHasNavigatedToExpsSuccessPage, true); | ||
} | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_IMPL(ExpsRegistrationSuccessObserver); | ||
|
||
} // namespace companion |
50 changes: 50 additions & 0 deletions
50
chrome/browser/ui/side_panel/companion/exps_registration_success_observer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_SIDE_PANEL_COMPANION_EXPS_REGISTRATION_SUCCESS_OBSERVER_H_ | ||
#define CHROME_BROWSER_UI_SIDE_PANEL_COMPANION_EXPS_REGISTRATION_SUCCESS_OBSERVER_H_ | ||
|
||
#include <vector> | ||
|
||
#include "content/public/browser/web_contents_observer.h" | ||
#include "content/public/browser/web_contents_user_data.h" | ||
#include "url/gurl.h" | ||
|
||
namespace content { | ||
class Page; | ||
class WebContents; | ||
} // namespace content | ||
|
||
namespace companion { | ||
|
||
// An observer that observes page navigations on a tab and determines if the | ||
// user has laned on the success page of exps registration. . | ||
class ExpsRegistrationSuccessObserver | ||
: public content::WebContentsObserver, | ||
public content::WebContentsUserData<ExpsRegistrationSuccessObserver> { | ||
public: | ||
explicit ExpsRegistrationSuccessObserver(content::WebContents* web_contents); | ||
~ExpsRegistrationSuccessObserver() override; | ||
|
||
// Disallow copy/assign. | ||
ExpsRegistrationSuccessObserver(const ExpsRegistrationSuccessObserver&) = | ||
delete; | ||
ExpsRegistrationSuccessObserver& operator=( | ||
const ExpsRegistrationSuccessObserver&) = delete; | ||
|
||
private: | ||
friend class content::WebContentsUserData<ExpsRegistrationSuccessObserver>; | ||
|
||
// content::WebContentsObserver overrides. | ||
void PrimaryPageChanged(content::Page& page) override; | ||
|
||
// The list of URLs to search for a match. | ||
std::vector<GURL> urls_to_match_against_; | ||
|
||
WEB_CONTENTS_USER_DATA_KEY_DECL(); | ||
}; | ||
|
||
} // namespace companion | ||
|
||
#endif // CHROME_BROWSER_UI_SIDE_PANEL_COMPANION_EXPS_REGISTRATION_SUCCESS_OBSERVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters