Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / ios / chrome / browser / experimental_flags.mm
blob7f6d4fafa25cb6137b37eb66fb518010e6e6b9a2
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file can be empty. Its purpose is to contain the relatively short lived
6 // definitions required for experimental flags.
8 #include "ios/chrome/browser/experimental_flags.h"
10 #import <Foundation/Foundation.h>
12 #include <string>
14 #include "base/command_line.h"
15 #include "base/metrics/field_trial.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h"
18 #include "components/enhanced_bookmarks/enhanced_bookmark_features.h"
19 #include "components/variations/variations_associated_data.h"
20 #include "ios/chrome/browser/chrome_switches.h"
21 #include "ios/web/public/web_view_creation_util.h"
23 namespace {
24 NSString* const kEnableAlertOnBackgroundUpload =
25     @"EnableAlertsOnBackgroundUpload";
26 NSString* const kEnableBookmarkRefreshImageOnEachVisit =
27     @"EnableBookmarkRefreshImageOnEachVisit";
28 }  // namespace
30 namespace experimental_flags {
32 bool IsAlertOnBackgroundUploadEnabled() {
33   return [[NSUserDefaults standardUserDefaults]
34       boolForKey:kEnableAlertOnBackgroundUpload];
37 bool IsExternalURLBlockingEnabled() {
38   std::string group_name =
39       base::FieldTrialList::FindFullName("IOSBlockUnpromptedExternalURLs");
41   // Check if the experimental flag is turned on.
42   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
43   if (command_line->HasSwitch(
44           switches::kEnableIOSBlockUnpromptedExternalURLs)) {
45     return true;
46   } else if (command_line->HasSwitch(
47                  switches::kDisableIOSBlockUnpromptedExternalURLs)) {
48     return false;
49   }
51   // Check if the finch experiment is turned on.
52   return !base::StartsWith(group_name, "Disabled",
53                            base::CompareCase::INSENSITIVE_ASCII);
56 bool IsBookmarkCollectionEnabled() {
57   return enhanced_bookmarks::IsEnhancedBookmarksEnabled();
60 bool IsBookmarkImageFetchingOnVisitEnabled() {
61   if (!IsBookmarkCollectionEnabled())
62     return false;
64   NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults];
65   if ([user_defaults boolForKey:kEnableBookmarkRefreshImageOnEachVisit])
66     return true;
68   const char kFieldTrialName[] = "EnhancedBookmarks";
69   std::string enable_fetching = variations::GetVariationParamValue(
70       kFieldTrialName, "EnableImagesFetchingOnVisit");
71   return !enable_fetching.empty();
74 bool IsWKWebViewEnabled() {
75   // If WKWebView isn't supported, don't activate the experiment at all. This
76   // avoids someone being slotted into the WKWebView bucket (and thus reporting
77   // as WKWebView), but actually running UIWebView.
78   if (!web::IsWKWebViewSupported())
79     return false;
81   std::string group_name =
82       base::FieldTrialList::FindFullName("IOSUseWKWebView");
84   // First check if the experimental flag is turned on.
85   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
86   if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) {
87     return true;
88   } else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) {
89     return false;
90   }
92   // Check if the finch experiment is turned on.
93   return base::StartsWith(group_name, "Enabled",
94                           base::CompareCase::INSENSITIVE_ASCII);
97 size_t MemoryWedgeSizeInMB() {
98   std::string wedge_size_string;
100   // Get the size from the Experimental setting.
101   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
102   wedge_size_string =
103       command_line->GetSwitchValueASCII(switches::kIOSMemoryWedgeSize);
105   // Otherwise, get from a variation param.
106   if (wedge_size_string.empty()) {
107     wedge_size_string =
108         variations::GetVariationParamValue("MemoryWedge", "wedge_size");
109   }
111   // Parse the value.
112   size_t wedge_size_in_mb = 0;
113   if (base::StringToSizeT(wedge_size_string, &wedge_size_in_mb))
114     return wedge_size_in_mb;
115   return 0;
118 }  // namespace experimental_flags