• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium 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 #ifndef MOJO_CORE_PORTS_PORT_REF_H_
6 #define MOJO_CORE_PORTS_PORT_REF_H_
7 
8 #include "base/component_export.h"
9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "mojo/core/ports/name.h"
12 
13 namespace mojo {
14 namespace core {
15 namespace ports {
16 
17 class Port;
18 class PortLocker;
19 
COMPONENT_EXPORT(MOJO_CORE_PORTS)20 class COMPONENT_EXPORT(MOJO_CORE_PORTS) PortRef {
21  public:
22   ~PortRef();
23   PortRef();
24   PortRef(const PortName& name, scoped_refptr<Port> port);
25 
26   PortRef(const PortRef& other);
27   PortRef(PortRef&& other);
28 
29   PortRef& operator=(const PortRef& other);
30   PortRef& operator=(PortRef&& other);
31 
32   const PortName& name() const { return name_; }
33 
34   bool is_valid() const { return !!port_; }
35 
36  private:
37   friend class PortLocker;
38 
39   Port* port() const { return port_.get(); }
40 
41   PortName name_;
42   scoped_refptr<Port> port_;
43 };
44 
45 }  // namespace ports
46 }  // namespace core
47 }  // namespace mojo
48 
49 #endif  // MOJO_CORE_PORTS_PORT_REF_H_
50