aw_enterprise_authentication_app_link_manager.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "android_webview/browser/aw_enterprise_authentication_app_link_manager.h"
  5. #include "components/url_matcher/url_util.h"
  6. namespace android_webview {
  7. namespace prefs {
  8. extern const char kEnterpriseAuthAppLinkPolicy[];
  9. }
  10. EnterpriseAuthenticationAppLinkManager::EnterpriseAuthenticationAppLinkManager(
  11. PrefService* pref_service) {
  12. pref_service_ = pref_service;
  13. pref_observer_.Init(pref_service);
  14. pref_observer_.Add(
  15. prefs::kEnterpriseAuthAppLinkPolicy,
  16. base::BindRepeating(
  17. &EnterpriseAuthenticationAppLinkManager::OnPolicyUpdated,
  18. base::Unretained(this)));
  19. // Call once to initialize the watcher with the current pref's values.
  20. OnPolicyUpdated();
  21. }
  22. EnterpriseAuthenticationAppLinkManager::
  23. ~EnterpriseAuthenticationAppLinkManager() = default;
  24. void EnterpriseAuthenticationAppLinkManager::OnPolicyUpdated() {
  25. const base::Value::List& authentication_urls_policy =
  26. pref_service_->GetValueList(prefs::kEnterpriseAuthAppLinkPolicy);
  27. url_matcher_ = std::make_unique<url_matcher::URLMatcher>();
  28. url_matcher::util::AddAllowFilters(url_matcher_.get(),
  29. authentication_urls_policy);
  30. }
  31. bool EnterpriseAuthenticationAppLinkManager::IsEnterpriseAuthenticationUrl(
  32. const GURL& url) {
  33. return url_matcher_ && !(url_matcher_->MatchURL(url).empty());
  34. }
  35. } // namespace android_webview