File: browser_user.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (85 lines) | stat: -rw-r--r-- 3,349 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 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/test/supervised_user/browser_user.h"

#include <string_view>

#include "base/memory/scoped_refptr.h"
#include "base/test/bind.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/test_accounts.h"
#include "components/supervised_user/core/browser/family_link_user_capabilities.h"
#include "components/supervised_user/core/browser/supervised_user_service.h"
#include "components/supervised_user/test_support/account_repository.h"
#include "components/supervised_user/test_support/family_link_settings_state_management.h"
#include "google_apis/gaia/core_account_id.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"

namespace supervised_user {

BrowserUser::BrowserUser(
    test_accounts::FamilyMember credentials,
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
    signin::IdentityManager& identity_manager,
    Browser& browser,
    Profile& profile,
    const base::RepeatingCallback<bool(int, const GURL&, ui::PageTransition)>
        add_tab_function)
    : credentials_(credentials),
      url_loader_factory_(url_loader_factory),
      identity_manager_(identity_manager),
      browser_(browser),
      profile_(profile),
      sign_in_functions_(base::BindLambdaForTesting(
                             [&browser]() -> Browser* { return &browser; }),
                         add_tab_function) {}
BrowserUser::~BrowserUser() = default;

void BrowserUser::TurnOnSync() {
  sign_in_functions_.TurnOnSync({credentials_.username, credentials_.password},
                                /*previously_signed_in_accounts=*/0);
}

void BrowserUser::SignOutFromWeb() {
  sign_in_functions_.SignOutFromWeb();
}
void BrowserUser::SignInFromWeb() {
  sign_in_functions_.SignInFromSettings(
      {credentials_.username, credentials_.password},
      /*previously_signed_in_accounts=*/0);
}

FamilyLinkSettingsState::Services BrowserUser::GetServices() const {
  return {
      *SupervisedUserServiceFactory::GetForProfile(&profile_.get()),
      *profile_->GetPrefs(),
      *HostContentSettingsMapFactory::GetForProfile(&profile_.get()),
  };
}

CoreAccountId BrowserUser::GetAccountId() const {
  CHECK(supervised_user::IsPrimaryAccountSubjectToParentalControls(
            &identity_manager_.get()) == signin::Tribool::kTrue)
      << "Blocklist control page is only available to user who have that "
         "feature enabled. Check if member is a subject to parental controls. "
         "Account: "
      << credentials_.username;

  return identity_manager_->GetPrimaryAccountId(signin::ConsentLevel::kSignin);
}

std::string_view BrowserUser::GetAccountPassword() const {
  return credentials_.password;
}

}  // namespace supervised_user