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
86
87
88
89
90
91
92
ash / webui / graduation / graduation_ui_handler.cc [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/webui/graduation/graduation_ui_handler.h"
#include <memory>
#include <utility>
#include "ash/webui/graduation/graduation_state_tracker.h"
#include "ash/webui/graduation/mojom/graduation_ui.mojom-shared.h"
#include "ash/webui/graduation/mojom/graduation_ui.mojom.h"
#include "ash/webui/graduation/webview_auth_handler.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "components/user_manager/user.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/base/webui/web_ui_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep.h"
namespace ash::graduation {
GraduationUiHandler::TestApi::TestApi(GraduationUiHandler* handler)
: handler_(handler) {
CHECK(handler_);
}
GraduationUiHandler::TestApi::~TestApi() = default;
WebviewAuthHandler* GraduationUiHandler::TestApi::GetWebviewAuthHandler() {
return handler_->auth_handler_.get();
}
GraduationUiHandler::GraduationUiHandler(
mojo::PendingReceiver<graduation_ui::mojom::GraduationUiHandler> receiver,
std::unique_ptr<WebviewAuthHandler> auth_handler,
const user_manager::User& user)
: receiver_(this, std::move(receiver)),
auth_handler_(std::move(auth_handler)),
user_(user) {
CHECK(auth_handler_);
}
GraduationUiHandler::~GraduationUiHandler() = default;
void GraduationUiHandler::AuthenticateWebview(
AuthenticateWebviewCallback callback) {
auth_handler_->AuthenticateWebview(
base::BindOnce(&GraduationUiHandler::OnAuthenticationFinished,
base::Unretained(this), std::move(callback)));
}
void GraduationUiHandler::GetProfileInfo(GetProfileInfoCallback callback) {
std::move(callback).Run(graduation_ui::mojom::ProfileInfo::New(
user_->GetDisplayEmail(),
webui::GetBitmapDataUrl(
user_->GetImage().GetRepresentation(1.0f).GetBitmap())));
}
void GraduationUiHandler::OnScreenSwitched(
graduation_ui::mojom::GraduationScreen screen) {
switch (screen) {
case graduation_ui::mojom::GraduationScreen::kWelcome:
state_tracker_.set_flow_state(
GraduationStateTracker::FlowState::kWelcome);
break;
case graduation_ui::mojom::GraduationScreen::kTakeoutUi:
state_tracker_.set_flow_state(
GraduationStateTracker::FlowState::kTakeoutUi);
break;
case graduation_ui::mojom::GraduationScreen::kError:
state_tracker_.set_flow_state(GraduationStateTracker::FlowState::kError);
break;
}
}
void GraduationUiHandler::OnTransferComplete() {
state_tracker_.set_flow_state(
GraduationStateTracker::FlowState::kTakeoutTransferComplete);
}
void GraduationUiHandler::OnAuthenticationFinished(
AuthenticateWebviewCallback callback,
bool is_success) {
std::move(callback).Run(is_success
? graduation_ui::mojom::AuthResult::kSuccess
: graduation_ui::mojom::AuthResult::kError);
}
} // namespace ash::graduation