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

Side by Side Diff: chrome/browser/chromeos/arc/arc_util.cc

Issue 2928113003: arc: Temporary workaround for enabling ARC Kiosk on N. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/chromeos/arc/arc_util.h" 5 #include "chrome/browser/chromeos/arc/arc_util.h"
6 6
7 #include <linux/magic.h> 7 #include <linux/magic.h>
8 #include <sys/statfs.h> 8 #include <sys/statfs.h>
9 #include <set>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/lazy_instance.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "base/sys_info.h" 15 #include "base/sys_info.h"
14 #include "base/task_scheduler/post_task.h" 16 #include "base/task_scheduler/post_task.h"
15 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
16 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 18 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
17 #include "chrome/browser/chromeos/login/user_flow.h" 19 #include "chrome/browser/chromeos/login/user_flow.h"
18 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 20 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
19 #include "chrome/browser/chromeos/profiles/profile_helper.h" 21 #include "chrome/browser/chromeos/profiles/profile_helper.h"
20 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
(...skipping 10 matching lines...) Expand all
32 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION"; 34 constexpr char kLsbReleaseArcVersionKey[] = "CHROMEOS_ARC_ANDROID_SDK_VERSION";
33 constexpr char kAndroidMSdkVersion[] = "23"; 35 constexpr char kAndroidMSdkVersion[] = "23";
34 36
35 // Let IsAllowedForProfile() return "false" for any profile. 37 // Let IsAllowedForProfile() return "false" for any profile.
36 bool g_disallow_for_testing = false; 38 bool g_disallow_for_testing = false;
37 39
38 // Let IsArcBlockedDueToIncompatibleFileSystem() return the specified value 40 // Let IsArcBlockedDueToIncompatibleFileSystem() return the specified value
39 // during test runs. 41 // during test runs.
40 bool g_arc_blocked_due_to_incomaptible_filesystem_for_testing = false; 42 bool g_arc_blocked_due_to_incomaptible_filesystem_for_testing = false;
41 43
44 // TODO(kinaba): Temporary workaround for crbug.com/729034.
45 //
46 // Some type of accounts don't have user prefs. As a short-term workaround,
47 // store the compatibility info from them on memory, ignoring the defect that
48 // it cannot survive browser crash and restart.
49 //
50 // This will be removed once the forced migration for ARC Kiosk user is
51 // implemented. After it's done such types of accounts cannot even sign-in
52 // with incompatible filesystem. Hence it'll be safe to always regard compatible
53 // for them then.
54 base::LazyInstance<std::set<AccountId>>::DestructorAtExit
55 g_known_compatible_users = LAZY_INSTANCE_INITIALIZER;
56
42 // Returns whether ARC can run on the filesystem mounted at |path|. 57 // Returns whether ARC can run on the filesystem mounted at |path|.
43 // This function should run only on threads where IO operations are allowed. 58 // This function should run only on threads where IO operations are allowed.
44 bool IsArcCompatibleFilesystem(const base::FilePath& path) { 59 bool IsArcCompatibleFilesystem(const base::FilePath& path) {
45 base::ThreadRestrictions::AssertIOAllowed(); 60 base::ThreadRestrictions::AssertIOAllowed();
46 61
47 // If it can be verified it is not on ecryptfs, then it is ok. 62 // If it can be verified it is not on ecryptfs, then it is ok.
48 struct statfs statfs_buf; 63 struct statfs statfs_buf;
49 if (statfs(path.value().c_str(), &statfs_buf) < 0) 64 if (statfs(path.value().c_str(), &statfs_buf) < 0)
50 return false; 65 return false;
51 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; 66 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC;
52 } 67 }
53 68
69 FileSystemCompatibilityState GetFileSystemCompatibilityPref(
70 const AccountId& account_id) {
71 int pref_value = kFileSystemIncompatible;
72 user_manager::known_user::GetIntegerPref(
73 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value);
74 return static_cast<FileSystemCompatibilityState>(pref_value);
75 }
76
54 // Stores the result of IsArcCompatibleFilesystem posted back from the blocking 77 // Stores the result of IsArcCompatibleFilesystem posted back from the blocking
55 // task runner. 78 // task runner.
56 void StoreCompatibilityCheckResult(const AccountId& account_id, 79 void StoreCompatibilityCheckResult(const AccountId& account_id,
57 const base::Closure& callback, 80 const base::Closure& callback,
58 bool is_compatible) { 81 bool is_compatible) {
59 if (is_compatible) { 82 if (is_compatible) {
60 user_manager::known_user::SetIntegerPref( 83 user_manager::known_user::SetIntegerPref(
61 account_id, prefs::kArcCompatibleFilesystemChosen, 84 account_id, prefs::kArcCompatibleFilesystemChosen,
62 arc::kFileSystemCompatible); 85 arc::kFileSystemCompatible);
86
87 // TODO(kinaba): Remove this code for accounts without user prefs.
88 // See the comment for |g_known_compatible_users| for the detail.
89 if (GetFileSystemCompatibilityPref(account_id) !=
90 arc::kFileSystemCompatible) {
91 g_known_compatible_users.Get().insert(account_id);
92 }
63 } 93 }
64 callback.Run(); 94 callback.Run();
65 } 95 }
66 96
67 FileSystemCompatibilityState GetFileSystemCompatibilityPref(
68 const AccountId& account_id) {
69 int pref_value = kFileSystemIncompatible;
70 user_manager::known_user::GetIntegerPref(
71 account_id, prefs::kArcCompatibleFilesystemChosen, &pref_value);
72 return static_cast<FileSystemCompatibilityState>(pref_value);
73 }
74
75 } // namespace 97 } // namespace
76 98
77 bool IsArcAllowedForProfile(const Profile* profile) { 99 bool IsArcAllowedForProfile(const Profile* profile) {
78 if (g_disallow_for_testing) { 100 if (g_disallow_for_testing) {
79 VLOG(1) << "ARC is disallowed for testing."; 101 VLOG(1) << "ARC is disallowed for testing.";
80 return false; 102 return false;
81 } 103 }
82 104
83 // ARC Kiosk can be enabled even if ARC is not yet supported on the device. 105 // ARC Kiosk can be enabled even if ARC is not yet supported on the device.
84 // In that case IsArcKioskMode() should return true as profile is already 106 // In that case IsArcKioskMode() should return true as profile is already
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 175
154 // Returns false for profiles not associated with users (like sign-in profile) 176 // Returns false for profiles not associated with users (like sign-in profile)
155 if (!user) 177 if (!user)
156 return false; 178 return false;
157 179
158 // chromeos::UserSessionManager does the actual file system check and stores 180 // chromeos::UserSessionManager does the actual file system check and stores
159 // the result to prefs, so that it survives crash-restart. 181 // the result to prefs, so that it survives crash-restart.
160 FileSystemCompatibilityState filesystem_compatibility = 182 FileSystemCompatibilityState filesystem_compatibility =
161 GetFileSystemCompatibilityPref(user->GetAccountId()); 183 GetFileSystemCompatibilityPref(user->GetAccountId());
162 const bool is_filesystem_compatible = 184 const bool is_filesystem_compatible =
163 filesystem_compatibility != kFileSystemIncompatible; 185 filesystem_compatibility != kFileSystemIncompatible ||
186 g_known_compatible_users.Get().count(user->GetAccountId()) != 0;
164 std::string arc_sdk_version; 187 std::string arc_sdk_version;
165 const bool is_M = base::SysInfo::GetLsbReleaseValue(kLsbReleaseArcVersionKey, 188 const bool is_M = base::SysInfo::GetLsbReleaseValue(kLsbReleaseArcVersionKey,
166 &arc_sdk_version) && 189 &arc_sdk_version) &&
167 arc_sdk_version == kAndroidMSdkVersion; 190 arc_sdk_version == kAndroidMSdkVersion;
168 191
169 // To run ARC we want to make sure either 192 // To run ARC we want to make sure either
170 // - Underlying file system is compatible with ARC, or 193 // - Underlying file system is compatible with ARC, or
171 // - SDK version is M. 194 // - SDK version is M.
172 if (!is_filesystem_compatible && !is_M) { 195 if (!is_filesystem_compatible && !is_M) {
173 VLOG(1) 196 VLOG(1)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Otherwise, check the underlying filesystem. 278 // Otherwise, check the underlying filesystem.
256 base::PostTaskWithTraitsAndReplyWithResult( 279 base::PostTaskWithTraitsAndReplyWithResult(
257 FROM_HERE, 280 FROM_HERE,
258 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, 281 {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
259 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, 282 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
260 base::Bind(&IsArcCompatibleFilesystem, profile_path), 283 base::Bind(&IsArcCompatibleFilesystem, profile_path),
261 base::Bind(&StoreCompatibilityCheckResult, account_id, callback)); 284 base::Bind(&StoreCompatibilityCheckResult, account_id, callback));
262 } 285 }
263 286
264 } // namespace arc 287 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698