Flutter Engine
plugin_registrar.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 
6 
7 #include <iostream>
8 #include <map>
9 
10 #include "binary_messenger_impl.h"
13 
14 namespace flutter {
15 
16 // ===== PluginRegistrar =====
17 
19  : registrar_(registrar) {
20  auto core_messenger = FlutterDesktopPluginRegistrarGetMessenger(registrar_);
21  messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
22 }
23 
25  // This must always be the first call.
26  ClearPlugins();
27 
28  // Explicitly cleared to facilitate testing of destruction order.
29  messenger_.reset();
30 }
31 
32 void PluginRegistrar::AddPlugin(std::unique_ptr<Plugin> plugin) {
33  plugins_.insert(std::move(plugin));
34 }
35 
37  plugins_.clear();
38 }
39 
40 // ===== PluginRegistrarManager =====
41 
42 // static
44  static PluginRegistrarManager* instance = new PluginRegistrarManager();
45  return instance;
46 }
47 
48 PluginRegistrarManager::PluginRegistrarManager() = default;
49 
50 // static
51 void PluginRegistrarManager::OnRegistrarDestroyed(
53  GetInstance()->registrars()->erase(registrar);
54 }
55 
56 } // namespace flutter
FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger(FlutterDesktopPluginRegistrarRef registrar)
void AddPlugin(std::unique_ptr< Plugin > plugin)
PluginRegistrar(FlutterDesktopPluginRegistrarRef core_registrar)
static PluginRegistrarManager * GetInstance()
FlutterDesktopPluginRegistrarRef registrar()