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/cpp/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  const char* switch_count_key = "FLUTTER_ENGINE_SWITCHES";
20  const int kMaxSwitchCount = 50;
21  const char* switch_count_string = std::getenv(switch_count_key);
22  int switch_count = std::min(
23  kMaxSwitchCount, switch_count_string ? atoi(switch_count_string) : 0);
24  for (int i = 1; i <= switch_count; ++i) {
25  std::ostringstream switch_key;
26  switch_key << "FLUTTER_ENGINE_SWITCH_" << i;
27  const char* switch_value = std::getenv(switch_key.str().c_str());
28  if (switch_value) {
29  std::ostringstream switch_value_as_flag;
30  switch_value_as_flag << "--" << switch_value;
31  switches.push_back(switch_value_as_flag.str());
32  } else {
33  std::cerr << switch_count << " keys expected from " << switch_count_key
34  << ", but " << switch_key.str() << " is missing." << std::endl;
35  }
36  }
37 #endif // !FLUTTER_RELEASE
38  return switches;
39 }
40 
41 } // namespace flutter
std::vector< std::string > GetSwitchesFromEnvironment()