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>
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/variations/variations_associated_data.h"
19 #include "ios/chrome/browser/chrome_switches.h"
20 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
21 #include "ios/web/public/web_view_util.h"
24 NSString* const kEnableAlertOnBackgroundUpload =
25 @"EnableAlertsOnBackgroundUpload";
26 NSString* const kEnableBookmarkRefreshImageOnEachVisit =
27 @"EnableBookmarkRefreshImageOnEachVisit";
30 namespace experimental_flags {
32 bool IsAlertOnBackgroundUploadEnabled() {
33 return [[NSUserDefaults standardUserDefaults]
34 boolForKey:kEnableAlertOnBackgroundUpload];
37 bool IsBookmarkCollectionEnabled() {
38 return ios::GetChromeBrowserProvider()->IsBookmarkCollectionEnabled();
41 bool IsBookmarkImageFetchingOnVisitEnabled() {
42 if (!IsBookmarkCollectionEnabled())
45 NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults];
46 if ([user_defaults boolForKey:kEnableBookmarkRefreshImageOnEachVisit])
49 const char kFieldTrialName[] = "EnhancedBookmarks";
50 std::string enable_fetching = variations::GetVariationParamValue(
51 kFieldTrialName, "EnableImagesFetchingOnVisit");
52 return !enable_fetching.empty();
55 bool IsWKWebViewEnabled() {
56 // If WKWebView isn't supported, don't activate the experiment at all. This
57 // avoids someone being slotted into the WKWebView bucket (and thus reporting
58 // as WKWebView), but actually running UIWebView.
59 if (!web::IsWKWebViewSupported())
62 std::string group_name =
63 base::FieldTrialList::FindFullName("IOSUseWKWebView");
65 // First check if the experimental flag is turned on.
66 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
67 if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) {
69 } else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) {
73 // Check if the finch experiment is turned on.
74 return base::StartsWithASCII(group_name, "Enabled", false);
77 size_t MemoryWedgeSizeInMB() {
78 std::string wedge_size_string;
80 // Get the size from the Experimental setting.
81 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
83 command_line->GetSwitchValueASCII(switches::kIOSMemoryWedgeSize);
85 // Otherwise, get from a variation param.
86 if (wedge_size_string.empty()) {
88 variations::GetVariationParamValue("MemoryWedge", "wedge_size");
92 size_t wedge_size_in_mb = 0;
93 if (base::StringToSizeT(wedge_size_string, &wedge_size_in_mb))
94 return wedge_size_in_mb;
98 } // namespace experimental_flags