1 // Copyright 2020 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 
5 #include "chrome/browser/chromeos/login/screens/parental_handoff_screen.h"
6 
7 #include <string>
8 
9 #include "base/strings/string16.h"
10 #include "chrome/browser/chromeos/login/oobe_screen.h"
11 #include "chrome/browser/chromeos/profiles/profile_helper.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/supervised_user/supervised_user_features.h"
15 #include "chrome/browser/ui/webui/chromeos/login/parental_handoff_screen_handler.h"
16 #include "chrome/grit/chromium_strings.h"
17 #include "chrome/grit/generated_resources.h"
18 #include "components/user_manager/user.h"
19 #include "components/user_manager/user_manager.h"
20 #include "ui/base/l10n/l10n_util.h"
21 
22 namespace chromeos {
23 
24 namespace {
25 
26 constexpr char kUserActionNext[] = "next";
27 
GetActiveUserName()28 base::string16 GetActiveUserName() {
29   const user_manager::User* user =
30       user_manager::UserManager::Get()->GetActiveUser();
31   if (!user || !user->IsChild())
32     return base::string16();
33   return user->GetDisplayName();
34 }
35 
36 }  // namespace
37 
38 // static
GetResultString(ParentalHandoffScreen::Result result)39 std::string ParentalHandoffScreen::GetResultString(
40     ParentalHandoffScreen::Result result) {
41   switch (result) {
42     case ParentalHandoffScreen::Result::DONE:
43       return "Done";
44     case ParentalHandoffScreen::Result::SKIPPED:
45       return BaseScreen::kNotApplicable;
46   }
47 }
48 
ParentalHandoffScreen(ParentalHandoffScreenView * view,const ScreenExitCallback & exit_callback)49 ParentalHandoffScreen::ParentalHandoffScreen(
50     ParentalHandoffScreenView* view,
51     const ScreenExitCallback& exit_callback)
52     : BaseScreen(ParentalHandoffScreenView::kScreenId,
53                  OobeScreenPriority::DEFAULT),
54       view_(view),
55       exit_callback_(exit_callback) {
56   if (view_)
57     view_->Bind(this);
58 }
59 
~ParentalHandoffScreen()60 ParentalHandoffScreen::~ParentalHandoffScreen() {
61   if (view_)
62     view_->Unbind();
63 }
64 
OnViewDestroyed(ParentalHandoffScreenView * view)65 void ParentalHandoffScreen::OnViewDestroyed(ParentalHandoffScreenView* view) {
66   if (view_ == view)
67     view_ = nullptr;
68 }
69 
MaybeSkip(WizardContext * context)70 bool ParentalHandoffScreen::MaybeSkip(WizardContext* context) {
71   Profile* profile = ProfileManager::GetActiveUserProfile();
72   if (profile->IsChild() && supervised_users::IsEduCoexistenceFlowV2Enabled()) {
73     return false;
74   }
75 
76   exit_callback_.Run(Result::SKIPPED);
77   return true;
78 }
79 
ShowImpl()80 void ParentalHandoffScreen::ShowImpl() {
81   if (!view_)
82     return;
83 
84   base::string16 user_name = GetActiveUserName();
85 
86   view_->Show(l10n_util::GetStringFUTF16(
87                   IDS_LOGIN_PARENTAL_HANDOFF_SCREEN_TITLE, user_name),
88               l10n_util::GetStringFUTF16(
89                   IDS_LOGIN_PARENTAL_HANDOFF_SCREEN_SUBTITLE, user_name));
90 }
HideImpl()91 void ParentalHandoffScreen::HideImpl() {}
92 
OnUserAction(const std::string & action_id)93 void ParentalHandoffScreen::OnUserAction(const std::string& action_id) {
94   if (action_id == kUserActionNext) {
95     exit_callback_.Run(Result::DONE);
96   } else {
97     BaseScreen::OnUserAction(action_id);
98   }
99 }
100 
101 }  // namespace chromeos
102