0

lobster: setup page handler

BUG=b:348281154

Change-Id: I07c2eaad1516f19ac066f40ee337814a4288553d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5660517
Commit-Queue: Curtis McMullan <curtismcmullan@chromium.org>
Reviewed-by: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1327313}
This commit is contained in:
Curtis McMullan
2024-07-15 02:31:38 +00:00
committed by Chromium LUCI CQ
parent c92af59dbf
commit 2df780e484
20 changed files with 228 additions and 60 deletions

@ -829,8 +829,8 @@ component("ash") {
"keyboard/virtual_keyboard_controller.h",
"lobster/lobster_controller.cc",
"lobster/lobster_controller.h",
"lobster/lobster_session.cc",
"lobster/lobster_session.h",
"lobster/lobster_session_impl.cc",
"lobster/lobster_session_impl.h",
"lock_screen_action/lock_screen_action_background_controller.cc",
"lock_screen_action/lock_screen_action_background_controller.h",
"lock_screen_action/lock_screen_action_background_controller_impl.cc",

@ -9,7 +9,7 @@
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_switches.h"
#include "ash/lobster/lobster_session.h"
#include "ash/lobster/lobster_session_impl.h"
#include "ash/public/cpp/lobster/lobster_client.h"
#include "ash/public/cpp/lobster/lobster_client_factory.h"
#include "ash/public/cpp/lobster/lobster_enums.h"
@ -80,7 +80,7 @@ std::unique_ptr<LobsterController::Trigger> LobsterController::CreateTrigger() {
void LobsterController::StartSession(std::unique_ptr<LobsterClient> client,
std::optional<std::string> query) {
active_session_ = std::make_unique<LobsterSession>(std::move(client));
active_session_ = std::make_unique<LobsterSessionImpl>(std::move(client));
}
} // namespace ash

@ -16,7 +16,7 @@ namespace ash {
class LobsterClient;
class LobsterClientFactory;
class LobsterSession;
class LobsterSessionImpl;
class ASH_EXPORT LobsterController {
public:
@ -63,7 +63,7 @@ class ASH_EXPORT LobsterController {
// Only one session can exist at a time. If a trigger fires while a session
// is active, the current session is ended and a new one is started.
std::unique_ptr<LobsterSession> active_session_;
std::unique_ptr<LobsterSessionImpl> active_session_;
};
} // namespace ash

@ -1,22 +0,0 @@
// 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/lobster/lobster_session.h"
#include <memory>
#include "ash/public/cpp/lobster/lobster_client.h"
namespace ash {
LobsterSession::LobsterSession(std::unique_ptr<LobsterClient> client)
: client_(std::move(client)), system_state_(client_->GetSystemState()) {}
LobsterSession::~LobsterSession() = default;
LobsterStatus LobsterSession::GetStatus() {
return system_state_.status;
}
} // namespace ash

@ -1,32 +0,0 @@
// 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.
#ifndef ASH_LOBSTER_LOBSTER_SESSION_H_
#define ASH_LOBSTER_LOBSTER_SESSION_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/public/cpp/lobster/lobster_enums.h"
#include "ash/public/cpp/lobster/lobster_system_state.h"
namespace ash {
class LobsterClient;
class ASH_EXPORT LobsterSession {
public:
explicit LobsterSession(std::unique_ptr<LobsterClient> client);
~LobsterSession();
LobsterStatus GetStatus();
private:
std::unique_ptr<LobsterClient> client_;
LobsterSystemState system_state_;
};
} // namespace ash
#endif // ASH_LOBSTER_LOBSTER_SESSION_H_

@ -0,0 +1,27 @@
// 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/lobster/lobster_session_impl.h"
#include <memory>
#include "ash/public/cpp/lobster/lobster_client.h"
namespace ash {
LobsterSessionImpl::LobsterSessionImpl(std::unique_ptr<LobsterClient> client)
: client_(std::move(client)) {
client_->SetActiveSession(this);
}
LobsterSessionImpl::~LobsterSessionImpl() {
client_->SetActiveSession(nullptr);
}
void LobsterSessionImpl::DownloadCandidate(int candidate_id,
StatusCallback callback) {
std::move(callback).Run(false);
}
} // namespace ash

@ -0,0 +1,33 @@
// 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.
#ifndef ASH_LOBSTER_LOBSTER_SESSION_IMPL_H_
#define ASH_LOBSTER_LOBSTER_SESSION_IMPL_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/public/cpp/lobster/lobster_enums.h"
#include "ash/public/cpp/lobster/lobster_session.h"
#include "ash/public/cpp/lobster/lobster_system_state.h"
namespace ash {
class LobsterClient;
class ASH_EXPORT LobsterSessionImpl : public LobsterSession {
public:
explicit LobsterSessionImpl(std::unique_ptr<LobsterClient> client);
~LobsterSessionImpl() override;
// LobsterSession overrides
void DownloadCandidate(int candidate_id, StatusCallback callback) override;
private:
std::unique_ptr<LobsterClient> client_;
};
} // namespace ash
#endif // ASH_LOBSTER_LOBSTER_SESSION_IMPL_H_

@ -199,6 +199,7 @@ component("cpp") {
"lobster/lobster_client.h",
"lobster/lobster_client_factory.h",
"lobster/lobster_enums.h",
"lobster/lobster_session.h",
"lobster/lobster_system_state.cc",
"lobster/lobster_system_state.h",
"locale_update_controller.cc",

@ -6,6 +6,7 @@
#define ASH_PUBLIC_CPP_LOBSTER_LOBSTER_CLIENT_H_
#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/lobster/lobster_session.h"
#include "ash/public/cpp/lobster/lobster_system_state.h"
namespace ash {
@ -14,6 +15,7 @@ class ASH_PUBLIC_EXPORT LobsterClient {
public:
virtual ~LobsterClient() = default;
virtual void SetActiveSession(LobsterSession* session) = 0;
virtual LobsterSystemState GetSystemState() = 0;
};

@ -0,0 +1,24 @@
// 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.
#ifndef ASH_PUBLIC_CPP_LOBSTER_LOBSTER_SESSION_H_
#define ASH_PUBLIC_CPP_LOBSTER_LOBSTER_SESSION_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/functional/callback.h"
namespace ash {
class ASH_PUBLIC_EXPORT LobsterSession {
public:
using StatusCallback = base::OnceCallback<void(bool)>;
virtual ~LobsterSession() = default;
virtual void DownloadCandidate(int candidate_id, StatusCallback) = 0;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_LOBSTER_LOBSTER_SESSION_H_

@ -3176,6 +3176,10 @@ static_library("ui") {
"webui/ash/launcher_internals/launcher_internals_handler.h",
"webui/ash/launcher_internals/launcher_internals_ui.cc",
"webui/ash/launcher_internals/launcher_internals_ui.h",
"webui/ash/lobster/lobster_page_handler.cc",
"webui/ash/lobster/lobster_page_handler.h",
"webui/ash/lobster/lobster_ui.cc",
"webui/ash/lobster/lobster_ui.h",
"webui/ash/lock_screen_reauth/base_lock_dialog.cc",
"webui/ash/lock_screen_reauth/base_lock_dialog.h",
"webui/ash/lock_screen_reauth/lock_screen_captive_portal_dialog.cc",

@ -14,6 +14,10 @@ LobsterClientImpl::LobsterClientImpl(LobsterService* service)
LobsterClientImpl::~LobsterClientImpl() = default;
void LobsterClientImpl::SetActiveSession(ash::LobsterSession* session) {
service_->SetActiveSession(session);
}
ash::LobsterSystemState LobsterClientImpl::GetSystemState() {
return service_->system_state_provider()->GetSystemState();
}

@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_ASH_LOBSTER_LOBSTER_CLIENT_IMPL_H_
#include "ash/public/cpp/lobster/lobster_client.h"
#include "ash/public/cpp/lobster/lobster_session.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/ash/lobster/lobster_service.h"
#include "chrome/browser/ui/ash/lobster/lobster_system_state_provider.h"
@ -20,6 +21,7 @@ class LobsterClientImpl : public ash::LobsterClient {
~LobsterClientImpl() override;
// LobsterClient overrides
void SetActiveSession(ash::LobsterSession* session) override;
ash::LobsterSystemState GetSystemState() override;
private:

@ -4,10 +4,20 @@
#include "chrome/browser/ui/ash/lobster/lobster_service.h"
#include "ash/public/cpp/lobster/lobster_session.h"
LobsterService::LobsterService() = default;
LobsterService::~LobsterService() = default;
void LobsterService::SetActiveSession(ash::LobsterSession* session) {
active_session_ = session;
}
ash::LobsterSession* LobsterService::active_session() {
return active_session_;
}
LobsterSystemStateProvider* LobsterService::system_state_provider() {
return &system_state_provider_;
}

@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_UI_ASH_LOBSTER_LOBSTER_SERVICE_H_
#define CHROME_BROWSER_UI_ASH_LOBSTER_LOBSTER_SERVICE_H_
#include "ash/public/cpp/lobster/lobster_session.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/ash/lobster/lobster_system_state_provider.h"
#include "components/keyed_service/core/keyed_service.h"
@ -13,9 +15,15 @@ class LobsterService : public KeyedService {
LobsterService();
~LobsterService() override;
void SetActiveSession(ash::LobsterSession* session);
ash::LobsterSession* active_session();
LobsterSystemStateProvider* system_state_provider();
private:
// Not owned by this class
raw_ptr<ash::LobsterSession> active_session_;
LobsterSystemStateProvider system_state_provider_;
};

@ -0,0 +1,3 @@
greywang@google.com
hdchuong@chromium.org
curtismcmullan@chromium.org

@ -0,0 +1,21 @@
// 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 "chrome/browser/ui/webui/ash/lobster/lobster_page_handler.h"
#include "ash/public/cpp/lobster/lobster_session.h"
namespace ash {
LobsterPageHandler::LobsterPageHandler(LobsterSession* active_session)
: session_(active_session) {}
LobsterPageHandler::~LobsterPageHandler() = default;
void LobsterPageHandler::DownloadCandidate(int candidate_id,
DownloadCandidateCallback callback) {
session_->DownloadCandidate(candidate_id, std::move(callback));
}
} // namespace ash

@ -0,0 +1,32 @@
// 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.
#ifndef CHROME_BROWSER_UI_WEBUI_ASH_LOBSTER_LOBSTER_PAGE_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_ASH_LOBSTER_LOBSTER_PAGE_HANDLER_H_
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
namespace ash {
class LobsterSession;
class LobsterPageHandler {
public:
using DownloadCandidateCallback = base::OnceCallback<void(bool)>;
explicit LobsterPageHandler(LobsterSession* active_session);
~LobsterPageHandler();
void DownloadCandidate(int candidate_id, DownloadCandidateCallback);
private:
// Not owned by this class
raw_ptr<LobsterSession> session_;
};
} // namespace ash
#endif // CHROME_BROWSER_UI_WEBUI_ASH_LOBSTER_LOBSTER_PAGE_HANDLER_H_

@ -0,0 +1,23 @@
// 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 "chrome/browser/ui/webui/ash/lobster/lobster_ui.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/lobster/lobster_service_provider.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
namespace ash {
LobsterUI::LobsterUI(content::WebUI* web_ui)
: UntrustedTopChromeWebUIController(web_ui),
page_handler_(std::make_unique<LobsterPageHandler>(
LobsterServiceProvider::GetForProfile(Profile::FromWebUI(web_ui))
->active_session())) {
// TODO(b/348281154): Initialize WebUI container and show to the user.
}
LobsterUI::~LobsterUI() = default;
} // namespace ash

@ -0,0 +1,28 @@
// 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.
#ifndef CHROME_BROWSER_UI_WEBUI_ASH_LOBSTER_LOBSTER_UI_H_
#define CHROME_BROWSER_UI_WEBUI_ASH_LOBSTER_LOBSTER_UI_H_
#include "chrome/browser/ui/webui/ash/lobster/lobster_page_handler.h"
#include "chrome/browser/ui/webui/top_chrome/untrusted_top_chrome_web_ui_controller.h"
namespace ash {
class LobsterUI : public UntrustedTopChromeWebUIController {
public:
explicit LobsterUI(content::WebUI* web_ui);
~LobsterUI() override;
static constexpr std::string GetWebUIName() { return "Lobster"; }
private:
WEB_UI_CONTROLLER_TYPE_DECL();
std::unique_ptr<LobsterPageHandler> page_handler_;
};
} // namespace ash
#endif // CHROME_BROWSER_UI_WEBUI_ASH_LOBSTER_LOBSTER_UI_H_