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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
// Copyright 2018 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_ASH_CROSTINI_CROSTINI_UTIL_H_
#define CHROME_BROWSER_ASH_CROSTINI_CROSTINI_UTIL_H_
#include <string>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/functional/callback_helpers.h"
#include "chrome/browser/ash/crostini/crostini_simple_types.h"
#include "chrome/browser/ash/guest_os/guest_id.h"
#include "chrome/browser/ash/guest_os/guest_os_launcher.h"
#include "chrome/browser/ash/guest_os/public/types.h"
#include "chromeos/ash/components/dbus/cicerone/cicerone_service.pb.h"
#include "components/services/app_service/public/cpp/intent.h"
#include "third_party/skia/include/core/SkColor.h"
namespace aura {
class Window;
} // namespace aura
namespace base {
class FilePath;
class TimeTicks;
} // namespace base
class Profile;
namespace crostini {
inline constexpr char kCrostiniImageAliasPattern[] = "debian/%s";
inline constexpr char kCrostiniContainerDefaultVersion[] = "bookworm";
inline constexpr char kCrostiniContainerFlag[] =
"crostini-container-install-version";
inline constexpr guest_os::VmType kCrostiniDefaultVmType =
guest_os::VmType::TERMINA;
inline constexpr guest_os::VmType kBaguetteDefaultVmType =
guest_os::VmType::BAGUETTE;
inline constexpr char kCrostiniDefaultVmName[] = "termina";
inline constexpr char kCrostiniDefaultContainerName[] = "penguin";
inline constexpr char kCrostiniDefaultUsername[] = "emperor";
inline constexpr char kCrostiniDefaultImageServerUrl[] =
"https://storage.googleapis.com/cros-containers/%d";
inline constexpr char kCrostiniDlcName[] = "termina-dlc";
inline constexpr char kToolsDlcName[] = "termina-tools-dlc";
inline constexpr base::FilePath::CharType kHomeDirectory[] =
FILE_PATH_LITERAL("/home/chronos/user");
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class CrostiniAppLaunchAppType {
// An app which isn't in the CrostiniAppRegistry. This shouldn't happen.
kUnknownApp = 0,
// The main terminal app.
kTerminal = 1,
// An app for which there is something in the CrostiniAppRegistry.
kRegisteredApp = 2,
kMaxValue = kRegisteredApp,
};
// Checks if user profile is able to a crostini app with a given app_id.
bool IsUninstallable(Profile* profile, const std::string& app_id);
// Returns whether the default Crostini VM is running for the user.
bool IsCrostiniRunning(Profile* profile);
// Whether the user is able to perform a container upgrade.
bool ShouldAllowContainerUpgrade(Profile* profile);
// Returns whether default Crostini container should be configured according to
// the configuration specified by CrostiniAnsiblePlaybook user policy.
bool ShouldConfigureDefaultContainer(Profile* profile);
// Launch a Crostini App with a given set of files, given as absolute paths in
// the container. For apps which can only be launched with a single file,
// launch multiple instances.
void LaunchCrostiniApp(
Profile* profile,
const std::string& app_id,
int64_t display_id,
const std::vector<guest_os::LaunchArg>& args = {},
guest_os::launcher::SuccessCallback callback = base::DoNothing());
void LaunchCrostiniAppWithIntent(
Profile* profile,
const std::string& app_id,
int64_t display_id,
apps::IntentPtr intent,
const std::vector<guest_os::LaunchArg>& args = {},
guest_os::launcher::SuccessCallback callback = base::DoNothing());
// Determine features to enable in the container on app/terminal launches.
std::vector<vm_tools::cicerone::ContainerFeature> GetContainerFeatures();
// Retrieves cryptohome_id from profile.
std::string CryptohomeIdForProfile(Profile* profile);
// Retrieves username from profile.
std::string DefaultContainerUserNameForProfile(Profile* profile);
// Returns the mount directory within the container where paths from the Chrome
// OS host such as within Downloads are shared with the container.
base::FilePath ContainerChromeOSBaseDirectory();
// Returns a list of ports currently being forwarded in Crostini as a JSON
// object.
std::string GetActivePortListAsJSON(Profile* profile);
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class CrostiniUISurface { kSettings = 0, kAppList = 1, kCount };
// Add a newly created LXD container to the kCrostiniContainers pref
void AddNewLxdContainerToPrefs(Profile* profile,
const guest_os::GuestId& container_id);
// Remove a newly deleted LXD container from the kCrostiniContainers pref, and
// deregister its apps and mime types.
void RemoveLxdContainerFromPrefs(Profile* profile,
const guest_os::GuestId& container_id);
// Returns a string to be displayed in a notification with the estimated time
// left for an operation to run which started and time |start| and is current
// at |percent| way through.
std::u16string GetTimeRemainingMessage(base::TimeTicks start, int percent);
SkColor GetContainerBadgeColor(Profile* profile,
const guest_os::GuestId& container_id);
void SetContainerBadgeColor(Profile* profile,
const guest_os::GuestId& container_id,
SkColor badge_color);
bool IsContainerVersionExpired(Profile* profile,
const guest_os::GuestId& container_id);
const guest_os::GuestId& DefaultContainerId();
const guest_os::GuestId& DefaultBaguetteContainerId();
bool IsCrostiniWindow(const aura::Window* window);
void RecordAppLaunchHistogram(CrostiniAppLaunchAppType app_type);
void RecordAppLaunchResultHistogram(CrostiniAppLaunchAppType type,
crostini::CrostiniResult reason);
// Tests whether or not the specified Container is the last one running on it's
// VM. Returns true if the VM should be stopped.
bool ShouldStopVm(Profile* profile, const guest_os::GuestId& container_id);
// Formats a container id the way most UI surfaces identify Crostini containers.
std::string FormatForUi(guest_os::GuestId container_id);
} // namespace crostini
#endif // CHROME_BROWSER_ASH_CROSTINI_CROSTINI_UTIL_H_
|