OLD | NEW |
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 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 bool IsArcPlayStoreEnabledPreferenceManagedForProfile(const Profile* profile) { | 155 bool IsArcPlayStoreEnabledPreferenceManagedForProfile(const Profile* profile) { |
156 if (!IsArcAllowedForProfile(profile)) { | 156 if (!IsArcAllowedForProfile(profile)) { |
157 LOG(DFATAL) << "ARC is not allowed for profile"; | 157 LOG(DFATAL) << "ARC is not allowed for profile"; |
158 return false; | 158 return false; |
159 } | 159 } |
160 return profile->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); | 160 return profile->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); |
161 } | 161 } |
162 | 162 |
163 void SetArcPlayStoreEnabledForProfile(Profile* profile, bool enabled) { | 163 bool SetArcPlayStoreEnabledForProfile(Profile* profile, bool enabled) { |
164 DCHECK(IsArcAllowedForProfile(profile)); | 164 DCHECK(IsArcAllowedForProfile(profile)); |
165 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile)) { | 165 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile)) { |
| 166 if (enabled && !IsArcPlayStoreEnabledForProfile(profile)) { |
| 167 LOG(WARNING) << "Attempt to enable disabled by policy ARC."; |
| 168 return false; |
| 169 } |
166 VLOG(1) << "Google-Play-Store-enabled pref is managed. Request to " | 170 VLOG(1) << "Google-Play-Store-enabled pref is managed. Request to " |
167 << (enabled ? "enable" : "disable") << " Play Store is not stored"; | 171 << (enabled ? "enable" : "disable") << " Play Store is not stored"; |
168 // Need update ARC session manager manually for managed case in order to | 172 // Need update ARC session manager manually for managed case in order to |
169 // keep its state up to date, otherwise it may stuck with enabling | 173 // keep its state up to date, otherwise it may stuck with enabling |
170 // request. | 174 // request. |
171 // TODO (khmel): Consider finding the better way handling this. | 175 // TODO (khmel): Consider finding the better way handling this. |
172 ArcSessionManager* arc_session_manager = ArcSessionManager::Get(); | 176 ArcSessionManager* arc_session_manager = ArcSessionManager::Get(); |
173 // |arc_session_manager| can be nullptr in unit_tests. | 177 // |arc_session_manager| can be nullptr in unit_tests. |
174 if (!arc_session_manager) | 178 if (!arc_session_manager) |
175 return; | 179 return false; |
176 if (enabled) | 180 if (enabled) |
177 arc_session_manager->RequestEnable(); | 181 arc_session_manager->RequestEnable(); |
178 else | 182 else |
179 arc_session_manager->RequestDisable(); | 183 arc_session_manager->RequestDisable(); |
180 return; | 184 return true; |
181 } | 185 } |
182 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); | 186 profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, enabled); |
| 187 return true; |
183 } | 188 } |
184 | 189 |
185 bool AreArcAllOptInPreferencesManagedForProfile(const Profile* profile) { | 190 bool AreArcAllOptInPreferencesManagedForProfile(const Profile* profile) { |
186 return profile->GetPrefs()->IsManagedPreference( | 191 return profile->GetPrefs()->IsManagedPreference( |
187 prefs::kArcBackupRestoreEnabled) && | 192 prefs::kArcBackupRestoreEnabled) && |
188 profile->GetPrefs()->IsManagedPreference( | 193 profile->GetPrefs()->IsManagedPreference( |
189 prefs::kArcLocationServiceEnabled); | 194 prefs::kArcLocationServiceEnabled); |
190 } | 195 } |
191 | 196 |
192 bool IsArcCompatibleFilesystem(const base::FilePath& path) { | 197 bool IsArcCompatibleFilesystem(const base::FilePath& path) { |
193 base::ThreadRestrictions::AssertIOAllowed(); | 198 base::ThreadRestrictions::AssertIOAllowed(); |
194 | 199 |
195 // If it can be verified it is not on ecryptfs, then it is ok. | 200 // If it can be verified it is not on ecryptfs, then it is ok. |
196 struct statfs statfs_buf; | 201 struct statfs statfs_buf; |
197 if (statfs(path.value().c_str(), &statfs_buf) < 0) | 202 if (statfs(path.value().c_str(), &statfs_buf) < 0) |
198 return false; | 203 return false; |
199 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; | 204 return statfs_buf.f_type != ECRYPTFS_SUPER_MAGIC; |
200 } | 205 } |
201 | 206 |
202 } // namespace arc | 207 } // namespace arc |
OLD | NEW |