Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: mojo/public/cpp/bindings/lib/shared_ptr.h

Issue 2062333002: mojo::Callback -> base::Callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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_PUBLIC_CPP_BINDINGS_LIB_SHARED_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SHARED_PTR_H_
7
8 #include "base/macros.h"
9 #include "mojo/public/cpp/bindings/lib/shared_data.h"
10
11 namespace mojo {
12 namespace internal {
13
14 // Used to manage a heap-allocated instance of P that can be shared via
15 // reference counting. When the last reference is dropped, the instance is
16 // deleted.
17 template <typename P>
18 class SharedPtr {
19 public:
20 SharedPtr() {}
21
22 explicit SharedPtr(P* ptr) { impl_.mutable_value()->ptr = ptr; }
23
24 // Default copy-constructor and assignment operator are OK.
25
26 P* get() { return impl_.value().ptr; }
27 const P* get() const { return impl_.value().ptr; }
28
29 void reset() { impl_.reset(); }
30
31 P* operator->() { return get(); }
32 const P* operator->() const { return get(); }
33
34 private:
35 class Impl {
36 public:
37 ~Impl() {
38 if (ptr)
39 delete ptr;
40 }
41
42 Impl() : ptr(nullptr) {}
43
44 Impl(P* ptr) : ptr(ptr) {}
45
46 P* ptr;
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(Impl);
50 };
51
52 SharedData<Impl> impl_;
53 };
54
55 } // namespace mojo
56 } // namespace internal
57
58 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SHARED_PTR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698