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

Unified Diff: third_party/WebKit/Source/wtf/Functional.h

Issue 2764833002: Move files in wtf/ to platform/wtf/ (Part 7). (Closed)
Patch Set: Rebase. Created 3 years, 9 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
Index: third_party/WebKit/Source/wtf/Functional.h
diff --git a/third_party/WebKit/Source/wtf/Functional.h b/third_party/WebKit/Source/wtf/Functional.h
index 93e827dabbfedc124c5b057d695c13bad86650ce..c550eef41b8107f0ec55a933e43c27cd38f6091d 100644
--- a/third_party/WebKit/Source/wtf/Functional.h
+++ b/third_party/WebKit/Source/wtf/Functional.h
@@ -1,300 +1,9 @@
-/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
+// Copyright 2017 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 WTF_Functional_h
-#define WTF_Functional_h
+#include "platform/wtf/Functional.h"
-#include "base/bind.h"
-#include "base/threading/thread_checker.h"
-#include "wtf/Allocator.h"
-#include "wtf/Assertions.h"
-#include "wtf/PassRefPtr.h"
-#include "wtf/PtrUtil.h"
-#include "wtf/RefPtr.h"
-#include "wtf/ThreadSafeRefCounted.h"
-#include "wtf/TypeTraits.h"
-#include <utility>
-
-namespace blink {
-template <typename T>
-class Member;
-template <typename T>
-class WeakMember;
-}
-
-namespace WTF {
-
-// Functional.h provides a very simple way to bind a function pointer and
-// arguments together into a function object that can be stored, copied and
-// invoked, similar to boost::bind and std::bind in C++11.
-
-// Thread Safety:
-//
-// WTF::bind() and WTF::Closure should be used for same-thread closures
-// only, i.e. the closures must be created, executed and destructed on
-// the same thread.
-// Use crossThreadBind() and CrossThreadClosure if the function/task is called
-// or destructed on a (potentially) different thread from the current thread.
-
-// WTF::bind() and move semantics
-// ==============================
-//
-// For unbound parameters (arguments supplied later on the bound functor
-// directly), there are two ways to pass movable arguments:
-//
-// 1) Pass by rvalue reference.
-//
-// void yourFunction(Argument&& argument) { ... }
-// std::unique_ptr<Function<void(Argument&&)>> functor =
-// bind<Argument&&>(yourFunction);
-//
-// 2) Pass by value.
-//
-// void yourFunction(Argument argument) { ... }
-// std::unique_ptr<Function<void(Argument)>> functor =
-// bind<Argument>(yourFunction);
-//
-// Note that with the latter there will be *two* move constructions happening,
-// because there needs to be at least one intermediary function call taking an
-// argument of type "Argument" (i.e. passed by value). The former case does not
-// require any move constructions inbetween.
-//
-// For bound parameters (arguments supplied on the creation of a functor), you
-// can move your argument into the internal storage of the functor by supplying
-// an rvalue to that argument (this is done in wrap() of ParamStorageTraits).
-// However, to make the functor be able to get called multiple times, the
-// stored object does not get moved out automatically when the underlying
-// function is actually invoked. If you want to make an argument "auto-passed",
-// you can do so by wrapping your bound argument with WTF::passed() function, as
-// shown below:
-//
-// void yourFunction(Argument argument)
-// {
-// // |argument| is passed from the internal storage of functor.
-// ...
-// }
-//
-// ...
-// std::unique_ptr<Function<void()>> functor = bind(yourFunction,
-// WTF::passed(Argument()));
-// ...
-// (*functor)();
-//
-// The underlying function must receive the argument wrapped by WTF::passed() by
-// rvalue reference or by value.
-//
-// Obviously, if you create a functor this way, you shouldn't call the functor
-// twice or more; after the second call, the passed argument may be invalid.
-
-enum FunctionThreadAffinity { CrossThreadAffinity, SameThreadAffinity };
-
-template <typename T>
-class PassedWrapper final {
- public:
- explicit PassedWrapper(T&& scoper) : m_scoper(std::move(scoper)) {}
- PassedWrapper(PassedWrapper&& other) : m_scoper(std::move(other.m_scoper)) {}
- T moveOut() const { return std::move(m_scoper); }
-
- private:
- mutable T m_scoper;
-};
-
-template <typename T>
-PassedWrapper<T> passed(T&& value) {
- static_assert(
- !std::is_reference<T>::value,
- "You must pass an rvalue to WTF::passed() so it can be moved. Add "
- "std::move() if necessary.");
- static_assert(!std::is_const<T>::value,
- "|value| must not be const so it can be moved.");
- return PassedWrapper<T>(std::move(value));
-}
-
-template <typename T, FunctionThreadAffinity threadAffinity>
-class UnretainedWrapper final {
- public:
- explicit UnretainedWrapper(T* ptr) : m_ptr(ptr) {}
- T* value() const { return m_ptr; }
-
- private:
- T* m_ptr;
-};
-
-template <typename T>
-UnretainedWrapper<T, SameThreadAffinity> unretained(T* value) {
- static_assert(!WTF::IsGarbageCollectedType<T>::value,
- "WTF::unretained() + GCed type is forbidden");
- return UnretainedWrapper<T, SameThreadAffinity>(value);
-}
-
-template <typename T>
-UnretainedWrapper<T, CrossThreadAffinity> crossThreadUnretained(T* value) {
- static_assert(!WTF::IsGarbageCollectedType<T>::value,
- "crossThreadUnretained() + GCed type is forbidden");
- return UnretainedWrapper<T, CrossThreadAffinity>(value);
-}
-
-template <typename T>
-struct ParamStorageTraits {
- typedef T StorageType;
-
- static_assert(!std::is_pointer<T>::value,
- "Raw pointers are not allowed to bind into WTF::Function. Wrap "
- "it with either wrapPersistent, wrapWeakPersistent, "
- "wrapCrossThreadPersistent, wrapCrossThreadWeakPersistent, "
- "RefPtr or unretained.");
- static_assert(!IsSubclassOfTemplate<T, blink::Member>::value &&
- !IsSubclassOfTemplate<T, blink::WeakMember>::value,
- "Member and WeakMember are not allowed to bind into "
- "WTF::Function. Wrap it with either wrapPersistent, "
- "wrapWeakPersistent, wrapCrossThreadPersistent or "
- "wrapCrossThreadWeakPersistent.");
-};
-
-template <typename T>
-struct ParamStorageTraits<PassRefPtr<T>> {
- typedef RefPtr<T> StorageType;
-};
-
-template <typename T>
-struct ParamStorageTraits<RefPtr<T>> {
- typedef RefPtr<T> StorageType;
-};
-
-template <typename>
-class RetainPtr;
-
-template <typename T>
-struct ParamStorageTraits<RetainPtr<T>> {
- typedef RetainPtr<T> StorageType;
-};
-
-template <typename T>
-struct ParamStorageTraits<PassedWrapper<T>> {
- typedef PassedWrapper<T> StorageType;
-};
-
-template <typename T, FunctionThreadAffinity threadAffinity>
-struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> {
- typedef UnretainedWrapper<T, threadAffinity> StorageType;
-};
-
-template <typename Signature,
- FunctionThreadAffinity threadAffinity = SameThreadAffinity>
-class Function;
-
-template <typename R, typename... Args, FunctionThreadAffinity threadAffinity>
-class Function<R(Args...), threadAffinity> {
- USING_FAST_MALLOC(Function);
- WTF_MAKE_NONCOPYABLE(Function);
-
- public:
- Function(base::Callback<R(Args...)> callback)
- : m_callback(std::move(callback)) {}
-
- ~Function() { DCHECK(m_threadChecker.CalledOnValidThread()); }
-
- R operator()(Args... args) {
- DCHECK(m_threadChecker.CalledOnValidThread());
- return m_callback.Run(std::forward<Args>(args)...);
- }
-
- bool isCancelled() const { return m_callback.IsCancelled(); }
-
- friend base::Callback<R(Args...)> convertToBaseCallback(
- std::unique_ptr<Function> function) {
- if (function)
- return std::move(function->m_callback);
- return base::Callback<R(Args...)>();
- }
-
- private:
- using MaybeThreadChecker =
- typename std::conditional<threadAffinity == SameThreadAffinity,
- base::ThreadChecker,
- base::ThreadCheckerDoNothing>::type;
- MaybeThreadChecker m_threadChecker;
- base::Callback<R(Args...)> m_callback;
-};
-
-template <FunctionThreadAffinity threadAffinity,
- typename FunctionType,
- typename... BoundParameters>
-std::unique_ptr<
- Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>,
- threadAffinity>>
-bindInternal(FunctionType function, BoundParameters&&... boundParameters) {
- using UnboundRunType =
- base::MakeUnboundRunType<FunctionType, BoundParameters...>;
- return WTF::wrapUnique(new Function<UnboundRunType,
- threadAffinity>(base::Bind(
- function,
- typename ParamStorageTraits<typename std::decay<BoundParameters>::type>::
- StorageType(std::forward<BoundParameters>(boundParameters))...)));
-}
-
-template <typename FunctionType, typename... BoundParameters>
-std::unique_ptr<
- Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>,
- SameThreadAffinity>>
-bind(FunctionType function, BoundParameters&&... boundParameters) {
- return bindInternal<SameThreadAffinity>(
- function, std::forward<BoundParameters>(boundParameters)...);
-}
-
-typedef Function<void(), SameThreadAffinity> Closure;
-typedef Function<void(), CrossThreadAffinity> CrossThreadClosure;
-
-} // namespace WTF
-
-namespace base {
-
-template <typename T>
-struct BindUnwrapTraits<WTF::RefPtr<T>> {
- static T* Unwrap(const WTF::RefPtr<T>& wrapped) { return wrapped.get(); }
-};
-
-template <typename T>
-struct BindUnwrapTraits<WTF::PassedWrapper<T>> {
- static T Unwrap(const WTF::PassedWrapper<T>& wrapped) {
- return wrapped.moveOut();
- }
-};
-
-template <typename T, WTF::FunctionThreadAffinity threadAffinity>
-struct BindUnwrapTraits<WTF::UnretainedWrapper<T, threadAffinity>> {
- static T* Unwrap(const WTF::UnretainedWrapper<T, threadAffinity>& wrapped) {
- return wrapped.value();
- }
-};
-
-} // namespace base
-
-using WTF::crossThreadUnretained;
-
-using WTF::Function;
-using WTF::CrossThreadClosure;
-
-#endif // WTF_Functional_h
+// The contents of this header was moved to platform/wtf as part of
+// WTF migration project. See the following post for details:
+// https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gYCAAJ
« no previous file with comments | « third_party/WebKit/Source/wtf/BitwiseOperations.h ('k') | third_party/WebKit/Source/wtf/HashTableDeletedValueType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698