| Flutter macOS Embedder |

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