summaryrefslogtreecommitdiff
path: root/chromium/content/common/associated_interface_registry_impl.h
blob: ae28f1994edde9a8505c5d2fe792b4473c79f1fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2016 The Chromium 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 CONTENT_COMMON_ASSOCIATED_INTERFACE_REGISTRY_IMPL_H_
#define CONTENT_COMMON_ASSOCIATED_INTERFACE_REGISTRY_IMPL_H_

#include <map>
#include <string>

#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
#include "third_party/WebKit/public/common/associated_interfaces/associated_interface_registry.h"

namespace content {

class AssociatedInterfaceRegistryImpl
    : public blink::AssociatedInterfaceRegistry {
 public:
  AssociatedInterfaceRegistryImpl();
  ~AssociatedInterfaceRegistryImpl() override;

  bool CanBindRequest(const std::string& interface_name) const;
  void BindRequest(const std::string& interface_name,
                   mojo::ScopedInterfaceEndpointHandle handle);

  // AssociatedInterfaceRegistry:
  void AddInterface(const std::string& name, const Binder& binder) override;
  void RemoveInterface(const std::string& name) override;

  base::WeakPtr<AssociatedInterfaceRegistryImpl> GetWeakPtr();

 private:
  std::map<std::string, Binder> interfaces_;
  base::WeakPtrFactory<AssociatedInterfaceRegistryImpl> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(AssociatedInterfaceRegistryImpl);
};

}  // namespace content

#endif  // CONTENT_COMMON_ASSOCIATED_INTERFACE_REGISTRY_IMPL_H_