blob: 79718ebdc5c3c9ea897acf607251a0307b944c6f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// Copyright 2015 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.
// This file can be empty. Its purpose is to contain the relatively short lived
// definitions required for experimental flags.
#include "ios/chrome/browser/experimental_flags.h"
#import <Foundation/Foundation.h>
#include <string>
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "components/variations/variations_associated_data.h"
#include "ios/chrome/browser/chrome_switches.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#include "ios/web/public/web_view_creation_util.h"
namespace {
NSString* const kEnableAlertOnBackgroundUpload =
@"EnableAlertsOnBackgroundUpload";
NSString* const kEnableBookmarkRefreshImageOnEachVisit =
@"EnableBookmarkRefreshImageOnEachVisit";
} // namespace
namespace experimental_flags {
bool IsAlertOnBackgroundUploadEnabled() {
return [[NSUserDefaults standardUserDefaults]
boolForKey:kEnableAlertOnBackgroundUpload];
}
bool IsBookmarkCollectionEnabled() {
return ios::GetChromeBrowserProvider()->IsBookmarkCollectionEnabled();
}
bool IsBookmarkImageFetchingOnVisitEnabled() {
if (!IsBookmarkCollectionEnabled())
return false;
NSUserDefaults* user_defaults = [NSUserDefaults standardUserDefaults];
if ([user_defaults boolForKey:kEnableBookmarkRefreshImageOnEachVisit])
return true;
const char kFieldTrialName[] = "EnhancedBookmarks";
std::string enable_fetching = variations::GetVariationParamValue(
kFieldTrialName, "EnableImagesFetchingOnVisit");
return !enable_fetching.empty();
}
bool IsWKWebViewEnabled() {
// If WKWebView isn't supported, don't activate the experiment at all. This
// avoids someone being slotted into the WKWebView bucket (and thus reporting
// as WKWebView), but actually running UIWebView.
if (!web::IsWKWebViewSupported())
return false;
std::string group_name =
base::FieldTrialList::FindFullName("IOSUseWKWebView");
// First check if the experimental flag is turned on.
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableIOSWKWebView)) {
return true;
} else if (command_line->HasSwitch(switches::kDisableIOSWKWebView)) {
return false;
}
// Check if the finch experiment is turned on.
return base::StartsWithASCII(group_name, "Enabled", false);
}
size_t MemoryWedgeSizeInMB() {
std::string wedge_size_string;
// Get the size from the Experimental setting.
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
wedge_size_string =
command_line->GetSwitchValueASCII(switches::kIOSMemoryWedgeSize);
// Otherwise, get from a variation param.
if (wedge_size_string.empty()) {
wedge_size_string =
variations::GetVariationParamValue("MemoryWedge", "wedge_size");
}
// Parse the value.
size_t wedge_size_in_mb = 0;
if (base::StringToSizeT(wedge_size_string, &wedge_size_in_mb))
return wedge_size_in_mb;
return 0;
}
} // namespace experimental_flags
|