Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: components/arc/arc_util.cc

Issue 2890843002: Policy implementation for encryptfs to ext4 migration strategy (Closed)
Patch Set: Fixed review comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/arc/arc_util.h" 5 #include "components/arc/arc_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/shared/app_types.h" 9 #include "ash/shared/app_types.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "chrome/common/pref_names.h"
12 #include "chromeos/chromeos_switches.h" 13 #include "chromeos/chromeos_switches.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "chromeos/dbus/session_manager_client.h" 15 #include "chromeos/dbus/session_manager_client.h"
16 #include "components/prefs/pref_service.h"
15 #include "components/user_manager/user_manager.h" 17 #include "components/user_manager/user_manager.h"
16 #include "ui/aura/client/aura_constants.h" 18 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
18 20
19 namespace arc { 21 namespace arc {
20 22
21 namespace { 23 namespace {
22 24
25 // This flag is set only in case the command line flag is set to mark the device
26 // as requiring the migration. The value is set the first time the policy fetch
27 // is done, and remains unchanged after that.
28 // TODO(igorcov): Remove this after migration. crbug.com/725493
29 ArcAvailabilityPolicyStatus g_arc_availability_policy_status = UNKNOWN;
30
31 // The flag to state if the device ownership is taken.
32 bool g_has_device_owner = false;
33
23 // This is for finch. See also crbug.com/633704 for details. 34 // This is for finch. See also crbug.com/633704 for details.
24 // TODO(hidehiko): More comments of the intention how this works, when 35 // TODO(hidehiko): More comments of the intention how this works, when
25 // we unify the commandline flags. 36 // we unify the commandline flags.
26 const base::Feature kEnableArcFeature{"EnableARC", 37 const base::Feature kEnableArcFeature{"EnableARC",
27 base::FEATURE_DISABLED_BY_DEFAULT}; 38 base::FEATURE_DISABLED_BY_DEFAULT};
28 39
29 // Possible values for --arc-availability flag. 40 // Possible values for --arc-availability flag.
30 constexpr char kAvailabilityNone[] = "none"; 41 constexpr char kAvailabilityNone[] = "none";
31 constexpr char kAvailabilityInstalled[] = "installed"; 42 constexpr char kAvailabilityInstalled[] = "installed";
32 constexpr char kAvailabilityOfficiallySupported[] = "officially-supported"; 43 constexpr char kAvailabilityOfficiallySupported[] = "officially-supported";
33 44
45 // The value of
46 // enterprise_management::DeviceEcryptfsMigrationStrategyProto::ALLOW_MIGRATION
47 constexpr int kAllowMigration = 2;
48
34 void SetArcCpuRestrictionCallback( 49 void SetArcCpuRestrictionCallback(
35 login_manager::ContainerCpuRestrictionState state, 50 login_manager::ContainerCpuRestrictionState state,
36 bool success) { 51 bool success) {
37 if (success) 52 if (success)
38 return; 53 return;
39 const char* message = 54 const char* message =
40 (state == login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND) 55 (state == login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND)
41 ? "unprioritize" 56 ? "unprioritize"
42 : "prioritize"; 57 : "prioritize";
43 LOG(ERROR) << "Failed to " << message << " ARC"; 58 LOG(ERROR) << "Failed to " << message << " ARC";
44 } 59 }
45 60
61 // Returns if the migration from ecryptfs to ext4 is allowed. It is true if it
62 // is known that the device is consumer owned, meaning the flag
63 // |g_has_device_owner| is set to true, or if the device policy is loaded and
64 // has the value |kAllowMigration|. If the state is unknown, returns false. The
65 // moment the result becomes known, it is cached and is not updated even if the
66 // policy is updated.
67 bool IsMigrationAllowed() {
68 if (g_arc_availability_policy_status == UNKNOWN) {
69 if (g_has_device_owner) {
70 g_arc_availability_policy_status = AVAILABLE;
71 return true;
72 }
73
74 if (!user_manager::UserManager::IsInitialized())
75 return false;
76
77 PrefService* pref_service =
78 user_manager::UserManager::Get()->GetLocalState();
79 const PrefService::Preference* pref =
80 pref_service->FindPreference(prefs::kDeviceEcryptfsMigrationStrategy);
81
82 if (!pref || !pref->IsManaged()) {
83 // There's no device owner, so it's either the policy loading and the
84 // status will be known later, or the device owner was not set yet.
85 return false;
86 }
87
88 if (pref->GetValue()->GetInt() == kAllowMigration)
89 g_arc_availability_policy_status = AVAILABLE;
90 else
91 g_arc_availability_policy_status = DISABLED;
92 }
93
94 return g_arc_availability_policy_status == AVAILABLE;
95 }
96
46 } // namespace 97 } // namespace
47 98
48 bool IsArcAvailable() { 99 bool IsArcAvailable() {
49 const auto* command_line = base::CommandLine::ForCurrentProcess(); 100 const auto* command_line = base::CommandLine::ForCurrentProcess();
50 101
102 // In the case the initial encryption was ecryptfs, the user data require
103 // migration to ext4 in order to have ARC available. The migration is
104 // forbidden if the device is managed and the policy is set to disable
105 // migration. This makes the ARC unavailable too.
106 // TODO(igorcov): Remove this after migration. crbug.com/725493
107 if (command_line->HasSwitch(chromeos::switches::kInitialEncryptionEcryptfs)) {
108 return IsMigrationAllowed();
hidehiko 2017/06/01 16:07:16 Because, IsArcAvailable() is designed to return a
109 }
110
51 if (command_line->HasSwitch(chromeos::switches::kArcAvailability)) { 111 if (command_line->HasSwitch(chromeos::switches::kArcAvailability)) {
52 std::string value = command_line->GetSwitchValueASCII( 112 std::string value = command_line->GetSwitchValueASCII(
53 chromeos::switches::kArcAvailability); 113 chromeos::switches::kArcAvailability);
54 DCHECK(value == kAvailabilityNone || value == kAvailabilityInstalled || 114 DCHECK(value == kAvailabilityNone || value == kAvailabilityInstalled ||
55 value == kAvailabilityOfficiallySupported) 115 value == kAvailabilityOfficiallySupported)
56 << "Unknown flag value: " << value; 116 << "Unknown flag value: " << value;
57 return value == kAvailabilityOfficiallySupported || 117 return value == kAvailabilityOfficiallySupported ||
58 (value == kAvailabilityInstalled && 118 (value == kAvailabilityInstalled &&
59 base::FeatureList::IsEnabled(kEnableArcFeature)); 119 base::FeatureList::IsEnabled(kEnableArcFeature));
60 } 120 }
61 121
62 // For transition, fallback to old flags. 122 // For transition, fallback to old flags.
63 // TODO(hidehiko): Remove this and clean up whole this function, when 123 // TODO(hidehiko): Remove this and clean up whole this function, when
64 // session_manager supports a new flag. 124 // session_manager supports a new flag.
65 return command_line->HasSwitch(chromeos::switches::kEnableArc) || 125 return command_line->HasSwitch(chromeos::switches::kEnableArc) ||
66 (command_line->HasSwitch(chromeos::switches::kArcAvailable) && 126 (command_line->HasSwitch(chromeos::switches::kArcAvailable) &&
67 base::FeatureList::IsEnabled(kEnableArcFeature)); 127 base::FeatureList::IsEnabled(kEnableArcFeature));
68 } 128 }
69 129
130 void SetHasDeviceOwner() {
131 g_has_device_owner = true;
132 }
133
134 void ResetGlobalDataForTesting() {
135 g_has_device_owner = false;
136 g_arc_availability_policy_status = UNKNOWN;
137 }
138
139 ArcAvailabilityPolicyStatus GetArcAvailabilityPolicyStatus() {
140 return g_arc_availability_policy_status;
141 }
142
70 bool ShouldArcAlwaysStart() { 143 bool ShouldArcAlwaysStart() {
71 return base::CommandLine::ForCurrentProcess()->HasSwitch( 144 return base::CommandLine::ForCurrentProcess()->HasSwitch(
72 chromeos::switches::kArcAlwaysStart); 145 chromeos::switches::kArcAlwaysStart);
73 } 146 }
74 147
75 void SetArcAlwaysStartForTesting() { 148 void SetArcAlwaysStartForTesting() {
76 base::CommandLine::ForCurrentProcess()->AppendSwitch( 149 base::CommandLine::ForCurrentProcess()->AppendSwitch(
77 chromeos::switches::kArcAlwaysStart); 150 chromeos::switches::kArcAlwaysStart);
78 } 151 }
79 152
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return; 230 return;
158 } 231 }
159 const login_manager::ContainerCpuRestrictionState state = 232 const login_manager::ContainerCpuRestrictionState state =
160 do_restrict ? login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND 233 do_restrict ? login_manager::CONTAINER_CPU_RESTRICTION_BACKGROUND
161 : login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND; 234 : login_manager::CONTAINER_CPU_RESTRICTION_FOREGROUND;
162 session_manager_client->SetArcCpuRestriction( 235 session_manager_client->SetArcCpuRestriction(
163 state, base::Bind(SetArcCpuRestrictionCallback, state)); 236 state, base::Bind(SetArcCpuRestrictionCallback, state));
164 } 237 }
165 238
166 } // namespace arc 239 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698