[email protected] | 4771091 | 2012-01-06 18:54:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_ |
| 6 | #define CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_ |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 7 | |
robliao | 4e3ceb42 | 2015-03-06 19:49:24 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 9 | #include "base/macros.h" |
| 10 | #include "build/build_config.h" |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 11 | |
| 12 | class PrefService; |
[email protected] | a2c1e551 | 2013-06-04 10:49:48 | [diff] [blame] | 13 | class Profile; |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 14 | |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 15 | namespace base { |
| 16 | class CommandLine; |
| 17 | } |
| 18 | |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 19 | namespace user_prefs { |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 20 | class PrefRegistrySyncable; |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 21 | } |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 22 | |
| 23 | // Specifies Incognito mode availability preferences. |
| 24 | class IncognitoModePrefs { |
| 25 | public: |
| 26 | // Possible values for Incognito mode availability. Please, do not change |
| 27 | // the order of entries since numeric values are exposed to users. |
| 28 | enum Availability { |
| 29 | // Incognito mode enabled. Users may open pages in both Incognito mode and |
Michael Thiessen | 0f4e785 | 2019-03-11 16:00:45 | [diff] [blame] | 30 | // normal mode (usually the default behaviour). |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 31 | ENABLED = 0, |
| 32 | // Incognito mode disabled. Users may not open pages in Incognito mode. |
| 33 | // Only normal mode is available for browsing. |
| 34 | DISABLED, |
| 35 | // Incognito mode forced. Users may open pages *ONLY* in Incognito mode. |
| 36 | // Normal mode is not available for browsing. |
| 37 | FORCED, |
| 38 | |
| 39 | AVAILABILITY_NUM_TYPES |
| 40 | }; |
| 41 | |
Michael Thiessen | db4bfdbd | 2019-10-07 23:22:32 | [diff] [blame] | 42 | static constexpr Availability kDefaultAvailability = ENABLED; |
Ian Vollick | 381389a6 | 2019-06-26 16:49:40 | [diff] [blame] | 43 | |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 44 | // Register incognito related preferences. |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 45 | static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 46 | |
| 47 | // Returns kIncognitoModeAvailability preference value stored |
| 48 | // in the given pref service. |
| 49 | static Availability GetAvailability(const PrefService* prefs); |
| 50 | |
| 51 | // Sets kIncognitoModeAvailability preference to the specified availability |
| 52 | // value. |
| 53 | static void SetAvailability(PrefService* prefs, |
| 54 | const Availability availability); |
| 55 | |
| 56 | // Converts in_value into the corresponding Availability value. Returns true |
| 57 | // if conversion is successful (in_value is valid). Otherwise, returns false |
| 58 | // and *out_value is set to ENABLED. |
| 59 | static bool IntToAvailability(int in_value, Availability* out_value); |
| 60 | |
[email protected] | 4771091 | 2012-01-06 18:54:13 | [diff] [blame] | 61 | // Returns true if the browser should start in incognito mode. |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 62 | static bool ShouldLaunchIncognito(const base::CommandLine& command_line, |
[email protected] | 4771091 | 2012-01-06 18:54:13 | [diff] [blame] | 63 | const PrefService* prefs); |
| 64 | |
[email protected] | a2c1e551 | 2013-06-04 10:49:48 | [diff] [blame] | 65 | // Returns true if |profile| can open a new Browser. This checks the incognito |
| 66 | // availability policies and verifies if the |profile| type is allowed to |
| 67 | // open new windows. |
| 68 | static bool CanOpenBrowser(Profile* profile); |
| 69 | |
robliao | 99ed826 | 2015-05-27 21:36:21 | [diff] [blame] | 70 | #if defined(OS_WIN) |
| 71 | // Calculates and caches the platform parental controls enable value on a |
| 72 | // worker thread. |
| 73 | static void InitializePlatformParentalControls(); |
| 74 | #endif |
| 75 | |
[email protected] | e3fd0bd | 2014-06-20 22:46:35 | [diff] [blame] | 76 | // Returns whether parental controls have been enabled on the platform. This |
robliao | 4e3ceb42 | 2015-03-06 19:49:24 | [diff] [blame] | 77 | // method evaluates and caches if the platform controls have been enabled on |
| 78 | // the first call, which must be on the UI thread when IO and blocking are |
| 79 | // allowed. Subsequent calls may be from any thread. |
| 80 | static bool ArePlatformParentalControlsEnabled() WARN_UNUSED_RESULT; |
[email protected] | e3fd0bd | 2014-06-20 22:46:35 | [diff] [blame] | 81 | |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 82 | private: |
asvitkine | b62d7d9 | 2016-10-03 21:15:03 | [diff] [blame] | 83 | // Specifies whether parental controls should be checked. See comment below. |
| 84 | enum GetAvailabilityMode { |
| 85 | CHECK_PARENTAL_CONTROLS, |
| 86 | DONT_CHECK_PARENTAL_CONTROLS, |
| 87 | }; |
| 88 | |
| 89 | // Internal version of GetAvailability() that specifies whether parental |
| 90 | // controls should be checked (which is expensive and not always necessary |
| 91 | // to do - such as when checking for FORCED state). |
| 92 | static Availability GetAvailabilityInternal(const PrefService* pref_service, |
| 93 | GetAvailabilityMode mode); |
| 94 | |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 95 | DISALLOW_IMPLICIT_CONSTRUCTORS(IncognitoModePrefs); |
| 96 | }; |
| 97 | |
| 98 | #endif // CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_ |