Skip to content

Commit

Permalink
Made it so you can whitelist what events you want to listen to (flutt…
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored Mar 16, 2020
1 parent 733933a commit fddb0c2
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 99 deletions.
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ FILE: ../../../flutter/flow/view_holder.cc
FILE: ../../../flutter/flow/view_holder.h
FILE: ../../../flutter/flutter_frontend_server/bin/starter.dart
FILE: ../../../flutter/flutter_frontend_server/lib/server.dart
FILE: ../../../flutter/fml/ascii_trie.cc
FILE: ../../../flutter/fml/ascii_trie.h
FILE: ../../../flutter/fml/ascii_trie_unittests.cc
FILE: ../../../flutter/fml/backtrace.cc
FILE: ../../../flutter/fml/backtrace.h
FILE: ../../../flutter/fml/backtrace_stub.cc
Expand Down
1 change: 1 addition & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct Settings {
bool enable_checked_mode = false;
bool start_paused = false;
bool trace_skia = false;
std::string trace_whitelist;
bool trace_startup = false;
bool trace_systrace = false;
bool dump_skp_on_shader_compilation = false;
Expand Down
3 changes: 3 additions & 0 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import("//flutter/testing/testing.gni")

source_set("fml") {
sources = [
"ascii_trie.cc",
"ascii_trie.h",
"backtrace.h",
"base32.cc",
"base32.h",
Expand Down Expand Up @@ -236,6 +238,7 @@ executable("fml_unittests") {
testonly = true

sources = [
"ascii_trie_unittests.cc",
"backtrace_unittests.cc",
"base32_unittest.cc",
"command_line_unittest.cc",
Expand Down
48 changes: 48 additions & 0 deletions fml/ascii_trie.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/ascii_trie.h"
#include "flutter/fml/logging.h"

namespace fml {
typedef AsciiTrie::TrieNode TrieNode;
typedef AsciiTrie::TrieNodePtr TrieNodePtr;

namespace {
void Add(TrieNodePtr* trie, const char* entry) {
int ch = entry[0];
FML_DCHECK(ch < AsciiTrie::kMaxAsciiValue);
if (ch != 0) {
if (!*trie) {
*trie = std::make_unique<TrieNode>();
}
Add(&(*trie)->children[ch], entry + 1);
}
}

TrieNodePtr MakeTrie(const std::vector<std::string>& entries) {
TrieNodePtr result;
for (const std::string& entry : entries) {
Add(&result, entry.c_str());
}
return result;
}
} // namespace

void AsciiTrie::Fill(const std::vector<std::string>& entries) {
node_ = MakeTrie(entries);
}

bool AsciiTrie::Query(TrieNode* trie, const char* query) {
FML_DCHECK(trie);
const char* char_position = query;
TrieNode* trie_position = trie;
TrieNode* child;
int ch;
while ((ch = *char_position) && (child = trie_position->children[ch].get())) {
char_position++;
trie_position = child;
}
return !child && trie_position != trie;
}
} // namespace fml
39 changes: 39 additions & 0 deletions fml/ascii_trie.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_FML_ASCIITRIE_H_
#define FLUTTER_FML_ASCIITRIE_H_

#include <string>
#include <vector>

namespace fml {

/// A trie for looking for ASCII prefixes.
class AsciiTrie {
public:
struct TrieNode;
typedef std::unique_ptr<TrieNode> TrieNodePtr;
/// The max Ascii value.
static const int kMaxAsciiValue = 128;

/// Clear and insert all the entries into the trie.
void Fill(const std::vector<std::string>& entries);

/// Returns true if \p argument is prefixed by the contents of the trie.
inline bool Query(const char* argument) {
return !node_ || Query(node_.get(), argument);
}

struct TrieNode {
TrieNodePtr children[kMaxAsciiValue];
};

private:
static bool Query(TrieNode* trie, const char* query);
TrieNodePtr node_;
};
} // namespace fml

#endif
36 changes: 36 additions & 0 deletions fml/ascii_trie_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/fml/ascii_trie.h"
#include "gtest/gtest.h"

using fml::AsciiTrie;

TEST(AsciiTableTest, Simple) {
AsciiTrie trie;
auto entries = std::vector<std::string>{"foo"};
trie.Fill(entries);
ASSERT_TRUE(trie.Query("foobar"));
ASSERT_FALSE(trie.Query("google"));
}

TEST(AsciiTableTest, ExactMatch) {
AsciiTrie trie;
auto entries = std::vector<std::string>{"foo"};
trie.Fill(entries);
ASSERT_TRUE(trie.Query("foo"));
}

TEST(AsciiTableTest, Empty) {
AsciiTrie trie;
ASSERT_TRUE(trie.Query("foo"));
}

TEST(AsciiTableTest, MultipleEntries) {
AsciiTrie trie;
auto entries = std::vector<std::string>{"foo", "bar"};
trie.Fill(entries);
ASSERT_TRUE(trie.Query("foozzz"));
ASSERT_TRUE(trie.Query("barzzz"));
}
Loading

0 comments on commit fddb0c2

Please sign in to comment.