1 // Copyright 2018 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 #include "content/public/common/network_service_util.h" 6 7 #include "base/command_line.h" 8 #include "build/build_config.h" 9 #include "content/public/common/content_features.h" 10 #include "content/public/common/content_switches.h" 11 12 #if defined(OS_ANDROID) 13 #include "base/metrics/field_trial_params.h" 14 #include "base/system/sys_info.h" 15 #endif 16 17 namespace content { 18 namespace { 19 20 #if defined(OS_ANDROID) 21 const base::Feature kNetworkServiceOutOfProcessMemoryThreshold{ 22 "NetworkServiceOutOfProcessMemoryThreshold", 23 base::FEATURE_ENABLED_BY_DEFAULT}; 24 25 // Using 1077 rather than 1024 because 1) it helps ensure that devices with 26 // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one 27 // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2. 28 constexpr base::FeatureParam<int> kNetworkServiceOutOfProcessThresholdMb{ 29 &kNetworkServiceOutOfProcessMemoryThreshold, 30 "network_service_oop_threshold_mb", 1077}; 31 #endif 32 33 // Indicates whether the network service is forced to be running in the browser 34 // process. 35 bool g_force_in_process_network_service = false; 36 37 } // namespace 38 IsOutOfProcessNetworkService()39bool IsOutOfProcessNetworkService() { 40 return !IsInProcessNetworkService(); 41 } 42 IsInProcessNetworkService()43bool IsInProcessNetworkService() { 44 if (g_force_in_process_network_service || 45 base::FeatureList::IsEnabled(features::kNetworkServiceInProcess) || 46 base::CommandLine::ForCurrentProcess()->HasSwitch( 47 switches::kSingleProcess)) { 48 return true; 49 } 50 51 #if defined(OS_ANDROID) 52 return base::SysInfo::AmountOfPhysicalMemoryMB() <= 53 kNetworkServiceOutOfProcessThresholdMb.Get(); 54 #endif 55 return false; 56 } 57 ForceInProcessNetworkService(bool is_forced)58void ForceInProcessNetworkService(bool is_forced) { 59 g_force_in_process_network_service = is_forced; 60 } 61 62 } // namespace content 63