Flutter Engine
engine_switches.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "flutter/shell/platform/common/engine_switches.h"
6 
7 #include <algorithm>
8 #include <cstdlib>
9 #include <iostream>
10 #include <sstream>
11 
12 namespace flutter {
13 
14 std::vector<std::string> GetSwitchesFromEnvironment() {
15  std::vector<std::string> switches;
16  // Read engine switches from the environment in debug/profile. If release mode
17  // support is needed in the future, it should likely use a whitelist.
18 #ifndef FLUTTER_RELEASE
19 #ifndef WINUWP
20  const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES";
21  const int kMaxSwitchCount = 50;
22  const char* switch_count_string = std::getenv(switch_count_key);
23  if (!switch_count_string) {
24  return switches;
25  }
26  int switch_count = std::min(kMaxSwitchCount, atoi(switch_count_string));
27  for (int i = 1; i <= switch_count; ++i) {
28  std::ostringstream switch_key;
29  switch_key << "FLUTTER_ENGINE_SWITCH_" << i;
30  const char* switch_value = std::getenv(switch_key.str().c_str());
31  if (switch_value) {
32  std::ostringstream switch_value_as_flag;
33  switch_value_as_flag << "--" << switch_value;
34  switches.push_back(switch_value_as_flag.str());
35  } else {
36  std::cerr << switch_count << " keys expected from " << switch_count_key
37  << ", but " << switch_key.str() << " is missing." << std::endl;
38  }
39  }
40 #endif // !WINUWP
41 #endif // !FLUTTER_RELEASE
42  return switches;
43 }
44 
45 } // namespace flutter
std::vector< std::string > GetSwitchesFromEnvironment()