droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 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. |
| 4 | |
| 5 | // This file can be empty. Its purpose is to contain the relatively short lived |
| 6 | // definitions required for experimental flags. |
| 7 | |
| 8 | #include "ios/chrome/browser/experimental_flags.h" |
| 9 | |
sdefresne | 60feea1 | 2015-06-04 08:39:51 | [diff] [blame] | 10 | #import <Foundation/Foundation.h> |
| 11 | |
lpromero | 6853727 | 2015-04-29 11:16:01 | [diff] [blame] | 12 | #include <string> |
| 13 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 14 | #include "base/command_line.h" |
lpromero | 6853727 | 2015-04-29 11:16:01 | [diff] [blame] | 15 | #include "base/metrics/field_trial.h" |
| 16 | #include "base/strings/string_number_conversions.h" |
sdefresne | b53a987 | 2015-05-18 20:01:49 | [diff] [blame] | 17 | #include "base/strings/string_util.h" |
lpromero | 6853727 | 2015-04-29 11:16:01 | [diff] [blame] | 18 | #include "components/variations/variations_associated_data.h" |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 19 | #include "ios/chrome/browser/chrome_switches.h" |
sdefresne | 60feea1 | 2015-06-04 08:39:51 | [diff] [blame] | 20 | #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
bzanotti | a5f249ed | 2015-06-24 10:02:59 | [diff] [blame^] | 21 | #include "ios/web/public/web_view_creation_util.h" |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 22 | |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 23 | namespace { |
| 24 | NSString* const kEnableAlertOnBackgroundUpload = |
| 25 | @"EnableAlertsOnBackgroundUpload"; |
sdefresne | 60feea1 | 2015-06-04 08:39:51 | [diff] [blame] | 26 | NSString* const kEnableBookmarkRefreshImageOnEachVisit = |
| 27 | @"EnableBookmarkRefreshImageOnEachVisit"; |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 28 | } // namespace |
| 29 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 30 | namespace experimental_flags { |
| 31 | |
sdefresne | 8b192a7 | 2015-05-13 13:25:19 | [diff] [blame] | 32 | bool IsAlertOnBackgroundUploadEnabled() { |
| 33 | return [[NSUserDefaults standardUserDefaults] |
| 34 | boolForKey:kEnableAlertOnBackgroundUpload]; |
| 35 | } |
| 36 | |
sdefresne | 60feea1 | 2015-06-04 08:39:51 | [diff] [blame] | 37 | bool IsBookmarkCollectionEnabled() { |
| 38 | return ios::GetChromeBrowserProvider()->IsBookmarkCollectionEnabled(); |
| 39 | } |
| 40 | |
| 41 | bool IsBookmarkImageFetchingOnVisitEnabled() { |
| 42 | if (!IsBookmarkCollectionEnabled()) |
| 43 | return false; |
| 44 | |
| 45 | NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults]; |
| 46 | if ([user_defaults boolForKey:kEnableBookmarkRefreshImageOnEachVisit]) |
| 47 | return true; |
| 48 | |
| 49 | const char kFieldTrialName[] = "EnhancedBookmarks"; |
| 50 | std::string enable_fetching = variations::GetVariationParamValue( |
| 51 | kFieldTrialName, "EnableImagesFetchingOnVisit"); |
| 52 | return !enable_fetching.empty(); |
| 53 | } |
| 54 | |
sdefresne | b53a987 | 2015-05-18 20:01:49 | [diff] [blame] | 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()) |
| 60 | return false; |
| 61 | |
| 62 | std::string group_name = |
| 63 | base::FieldTrialList::FindFullName("IOSUseWKWebView"); |
| 64 | |
| 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)) { |
| 68 | return true; |
| 69 | } else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | // Check if the finch experiment is turned on. |
brettw | 44ce0ec5 | 2015-06-12 01:57:57 | [diff] [blame] | 74 | return base::StartsWithASCII(group_name, "Enabled", false); |
sdefresne | b53a987 | 2015-05-18 20:01:49 | [diff] [blame] | 75 | } |
| 76 | |
lpromero | 6853727 | 2015-04-29 11:16:01 | [diff] [blame] | 77 | size_t MemoryWedgeSizeInMB() { |
| 78 | std::string wedge_size_string; |
| 79 | |
| 80 | // Get the size from the Experimental setting. |
| 81 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 82 | wedge_size_string = |
| 83 | command_line->GetSwitchValueASCII(switches::kIOSMemoryWedgeSize); |
| 84 | |
| 85 | // Otherwise, get from a variation param. |
| 86 | if (wedge_size_string.empty()) { |
| 87 | wedge_size_string = |
| 88 | variations::GetVariationParamValue("MemoryWedge", "wedge_size"); |
| 89 | } |
| 90 | |
| 91 | // Parse the value. |
| 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; |
| 95 | return 0; |
| 96 | } |
| 97 | |
droger | f83b9126 | 2015-03-05 19:45:19 | [diff] [blame] | 98 | } // namespace experimental_flags |