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

Unified Diff: mojo/public/cpp/bindings/lib/shared_data.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | mojo/public/cpp/bindings/lib/shared_ptr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/shared_data.h
diff --git a/mojo/public/cpp/bindings/lib/shared_data.h b/mojo/public/cpp/bindings/lib/shared_data.h
deleted file mode 100644
index 8e93300b72534f66ce6401b03d81d577abb3b418..0000000000000000000000000000000000000000
--- a/mojo/public/cpp/bindings/lib/shared_data.h
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_SHARED_DATA_H_
-#define MOJO_PUBLIC_CPP_BINDINGS_LIB_SHARED_DATA_H_
-
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/threading/thread_checker.h"
-
-namespace mojo {
-namespace internal {
-
-// Used to allocate an instance of T that can be shared via reference counting.
-//
-// A default constructed SharedData does not have a Holder until it is set,
-// either by assignment, or by accessing the value. As a result, it is not tied
-// to any thread. The Holder is lazily allocated on first access. The complexity
-// is due to the behaviour around copying. If a default constructed SharedData
-// is copied into another, the two share the same empty state, and changing the
-// value of one will affect the other.
-template <typename T>
-class SharedData {
- public:
- ~SharedData() {
- if (holder_)
- holder_->Release();
- }
-
- SharedData() : holder_(nullptr) {}
-
- explicit SharedData(const T& value) : holder_(new Holder(value)) {}
-
- SharedData(const SharedData<T>& other) {
- other.LazyInit();
- holder_ = other.holder_;
- holder_->Retain();
- }
-
- SharedData<T>& operator=(const SharedData<T>& other) {
- other.LazyInit();
- if (other.holder_ == holder_)
- return *this;
- if (holder_)
- holder_->Release();
- holder_ = other.holder_;
- holder_->Retain();
- return *this;
- }
-
- void reset() {
- if (holder_)
- holder_->Release();
- holder_ = nullptr;
- }
-
- void reset(const T& value) {
- if (holder_)
- holder_->Release();
- holder_ = new Holder(value);
- }
-
- void set_value(const T& value) {
- LazyInit();
- holder_->value = value;
- }
- T* mutable_value() {
- LazyInit();
- return &holder_->value;
- }
- const T& value() const {
- LazyInit();
- return holder_->value;
- }
-
- private:
- class Holder {
- public:
- Holder() : value(), ref_count_(1) {}
- Holder(const T& value) : value(value), ref_count_(1) {}
-
- void Retain() {
- DCHECK(thread_checker_.CalledOnValidThread());
- ++ref_count_;
- }
- void Release() {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (--ref_count_ == 0)
- delete this;
- }
-
- T value;
-
- private:
- int ref_count_;
- base::ThreadChecker thread_checker_;
- DISALLOW_COPY_AND_ASSIGN(Holder);
- };
-
- void LazyInit() const {
- if (!holder_)
- holder_ = new Holder();
- }
-
- mutable Holder* holder_;
-};
-
-} // namespace internal
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SHARED_DATA_H_
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | mojo/public/cpp/bindings/lib/shared_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698