Commit 6a790229 authored by Tina Wang's avatar Tina Wang Committed by Chromium LUCI CQ

[ios] Use enum for IncognitoModeAvailability pref

Use enum to avoid meaningless decision like "kprefValue == 0" and
improve the readability.

Add an util class to help check the value of the incognito pref.

Change-Id: I005891908e261c8d292e2a861c7b5950a4f526d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586104Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836644}
parent a2de88da
......@@ -29,6 +29,8 @@ source_set("browser_prefs") {
sources = [
"browser_prefs.h",
"browser_prefs.mm",
"prefs_util.h",
"prefs_util.mm",
]
deps = [
"//components/autofill/core/browser",
......@@ -78,6 +80,7 @@ source_set("browser_prefs") {
"//ios/chrome/browser/memory",
"//ios/chrome/browser/metrics",
"//ios/chrome/browser/net",
"//ios/chrome/browser/policy:feature_flags",
"//ios/chrome/browser/prerender:prerender_pref",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui/authentication",
......
......@@ -12,6 +12,18 @@ namespace user_prefs {
class PrefRegistrySyncable;
}
enum class IncognitoModePrefs {
// Incognito mode enabled. Users may open pages in both Incognito mode and
// normal mode (usually the default behaviour).
kEnabled = 0,
// Incognito mode disabled. Users may not open pages in Incognito mode.
// Only normal mode is available for browsing.
kDisabled,
// Incognito mode forced. Users may open pages *ONLY* in Incognito mode.
// Normal mode is not available for browsing.
kForced,
};
// Registers all prefs that will be used via the local state PrefService.
void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
......
......@@ -233,8 +233,8 @@ void RegisterBrowserStatePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterIntegerPref(kGCMChannelPollIntervalSeconds, 0);
registry->RegisterInt64Pref(kGCMChannelLastCheckTime, 0);
// Register kIncognitoModeAvailability to available.
registry->RegisterIntegerPref(prefs::kIncognitoModeAvailability, 0);
registry->RegisterIntegerPref(prefs::kIncognitoModeAvailability,
static_cast<int>(IncognitoModePrefs::kEnabled));
registry->RegisterListPref(kInvalidatorSavedInvalidations);
registry->RegisterStringPref(kInvalidatorInvalidationState, std::string());
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_PREFS_PREFS_UTIL_H_
#define IOS_CHROME_BROWSER_PREFS_PREFS_UTIL_H_
class PrefService;
// Returns true if incognito mode is disabled by enterprise policy.
bool IsIncognitoModeDisabled(PrefService* pref_service);
// Returns true if incognito mode is forced by enterprise policy.
bool IsIncognitoModeForced(PrefService* pref_service);
#endif // IOS_CHROME_BROWSER_PREFS_PREFS_UTIL_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/prefs/prefs_util.h"
#include "components/prefs/pref_service.h"
#include "ios/chrome/browser/policy/policy_features.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/prefs/browser_prefs.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
bool IsIncognitoModeDisabled(PrefService* pref_service) {
return IsEnterprisePolicyEnabled() &&
pref_service->IsManagedPreference(prefs::kIncognitoModeAvailability) &&
pref_service->GetInteger(prefs::kIncognitoModeAvailability) ==
static_cast<int>(IncognitoModePrefs::kDisabled);
}
bool IsIncognitoModeForced(PrefService* pref_service) {
return IsEnterprisePolicyEnabled() &&
pref_service->IsManagedPreference(prefs::kIncognitoModeAvailability) &&
pref_service->GetInteger(prefs::kIncognitoModeAvailability) ==
static_cast<int>(IncognitoModePrefs::kForced);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment