File: fake_crostini_features.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (113 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download | duplicates (6)
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
// Copyright 2019 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/ash/crostini/fake_crostini_features.h"

namespace crostini {

FakeCrostiniFeatures::FakeCrostiniFeatures() {
  original_features_ = CrostiniFeatures::Get();
  CrostiniFeatures::SetForTesting(this);
}

FakeCrostiniFeatures::~FakeCrostiniFeatures() {
  CrostiniFeatures::SetForTesting(original_features_);
}

void FakeCrostiniFeatures::SetAll(bool flag) {
  could_be_allowed_ = flag;
  allowed_now_ = flag;
  enabled_ = flag;
  export_import_ui_allowed_ = flag;
  root_access_allowed_ = flag;
  container_upgrade_ui_allowed_ = flag;
  can_change_adb_sideloading_ = flag;
  port_forwarding_allowed_ = flag;
  multi_container_allowed_ = flag;
}

void FakeCrostiniFeatures::ClearAll() {
  could_be_allowed_ = std::nullopt;
  allowed_now_ = std::nullopt;
  enabled_ = std::nullopt;
  export_import_ui_allowed_ = std::nullopt;
  root_access_allowed_ = std::nullopt;
  container_upgrade_ui_allowed_ = std::nullopt;
  can_change_adb_sideloading_ = std::nullopt;
  port_forwarding_allowed_ = std::nullopt;
  multi_container_allowed_ = std::nullopt;
}

bool FakeCrostiniFeatures::CouldBeAllowed(Profile* profile,
                                          std::string* reason) {
  if (could_be_allowed_.has_value()) {
    *reason = "some reason";
    return *could_be_allowed_;
  }
  return original_features_->CouldBeAllowed(profile, reason);
}

bool FakeCrostiniFeatures::IsAllowedNow(Profile* profile, std::string* reason) {
  if (could_be_allowed_.has_value() && !could_be_allowed_) {
    *reason = "some reason";
    return false;
  }
  if (allowed_now_.has_value()) {
    *reason = "some reason";
    return *allowed_now_;
  }
  return original_features_->IsAllowedNow(profile, reason);
}

bool FakeCrostiniFeatures::IsEnabled(Profile* profile) {
  if (enabled_.has_value()) {
    return *enabled_;
  }
  return original_features_->IsEnabled(profile);
}

bool FakeCrostiniFeatures::IsExportImportUIAllowed(Profile* profile) {
  if (export_import_ui_allowed_.has_value()) {
    return *export_import_ui_allowed_;
  }
  return original_features_->IsExportImportUIAllowed(profile);
}

bool FakeCrostiniFeatures::IsRootAccessAllowed(Profile* profile) {
  if (root_access_allowed_.has_value()) {
    return *root_access_allowed_;
  }
  return original_features_->IsRootAccessAllowed(profile);
}

bool FakeCrostiniFeatures::IsContainerUpgradeUIAllowed(Profile* profile) {
  if (container_upgrade_ui_allowed_.has_value()) {
    return *container_upgrade_ui_allowed_;
  }
  return original_features_->IsContainerUpgradeUIAllowed(profile);
}

void FakeCrostiniFeatures::CanChangeAdbSideloading(
    Profile* profile,
    CanChangeAdbSideloadingCallback callback) {
  if (can_change_adb_sideloading_.has_value()) {
    std::move(callback).Run(*can_change_adb_sideloading_);
    return;
  }
  original_features_->CanChangeAdbSideloading(profile, std::move(callback));
}

bool FakeCrostiniFeatures::IsPortForwardingAllowed(Profile* profile) {
  if (port_forwarding_allowed_.has_value()) {
    return *port_forwarding_allowed_;
  }
  return original_features_->IsPortForwardingAllowed(profile);
}

bool FakeCrostiniFeatures::IsMultiContainerAllowed(Profile* profile) {
  return multi_container_allowed_.value_or(
      original_features_->IsMultiContainerAllowed(profile));
}

}  // namespace crostini