Commit 82138d8f authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Introduce commander::Commander

This is the boundary between Commander internals and the rest of the
system.

Also includes the enable check and current logic (command line flag),
though nothing will happen until Initialize is hooked up (and nothing
*interesting* will happen until the WebUI CL lands).

Bug: 1014639
Change-Id: I9063766657fb4bceb8bbf11faab8655b515315a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500245
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821359}
parent a4a218f7
......@@ -908,6 +908,8 @@ static_library("ui") {
"commander/apps_command_source.h",
"commander/command_source.cc",
"commander/command_source.h",
"commander/commander.cc",
"commander/commander.h",
"commander/commander_backend.h",
"commander/commander_controller.cc",
"commander/commander_controller.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/commander/commander.h"
#include "base/command_line.h"
#include "chrome/browser/ui/commander/commander_controller.h"
#include "chrome/browser/ui/commander/commander_frontend.h"
#include "content/public/browser/browser_thread.h"
namespace commander {
namespace {
constexpr char kEnableCommander[] = "enable-commander";
} // namespace
bool IsEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(kEnableCommander);
}
// static
Commander* Commander::Get() {
static base::NoDestructor<Commander> instance;
return instance.get();
}
Commander::Commander() = default;
Commander::~Commander() = default;
void Commander::Initialize() {
DCHECK(IsEnabled());
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!backend_ && !frontend_);
backend_ = std::make_unique<CommanderController>();
frontend_ = CommanderFrontend::Create(backend_.get());
}
void Commander::ToggleForBrowser(Browser* browser) {
DCHECK(IsEnabled());
DCHECK(frontend_);
frontend_->ToggleForBrowser(browser);
}
} // namespace commander
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COMMANDER_COMMANDER_H_
#define CHROME_BROWSER_UI_COMMANDER_COMMANDER_H_
#include <memory>
#include "base/no_destructor.h"
class Browser;
namespace commander {
class CommanderBackend;
class CommanderFrontend;
// Returns true if the commander UI should be made available.
bool IsEnabled();
// A singleton which initializes and owns the components of the commander
// system. This is the boundary between commander internals and the rest of the
// browser.
class Commander {
public:
static Commander* Get();
// Initialize internal components. Must be called before any calls to
// ToggleForBrowser().
void Initialize();
// Toggles the UI. There are three possible cases:
// If the UI is not showing, it will be shown attached to `browser`'s window.
// If the UI is showing on `browser`, it will be hidden.
// If the UI is showing on a different browser, it will be hidden, and then
// shown attached to `browser`'s window.
void ToggleForBrowser(Browser* browser);
Commander(const Commander& other) = delete;
Commander& operator=(const Commander& other) = delete;
private:
friend base::NoDestructor<Commander>;
Commander();
~Commander();
std::unique_ptr<CommanderFrontend> frontend_;
std::unique_ptr<CommanderBackend> backend_;
};
} // namespace commander
#endif // CHROME_BROWSER_UI_COMMANDER_COMMANDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment