提交 70c382c0 编写于 作者: E Eric Seidel

Remove wtf/Functional.h

The background parser was the last client.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/684813003
上级 2328807e
......@@ -37,7 +37,6 @@
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "platform/weborigin/KURL.h"
#include "wtf/Functional.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
......
......@@ -26,9 +26,12 @@
#include "config.h"
#include "core/html/parser/BackgroundHTMLParser.h"
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "core/html/parser/HTMLDocumentParser.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html/parser/TextResourceDecoder.h"
#include "public/platform/Platform.h"
#include "wtf/MainThread.h"
#include "wtf/text/TextPosition.h"
......@@ -152,7 +155,8 @@ void BackgroundHTMLParser::sendTokensToMainThread()
OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentParser::ParsedChunk);
chunk->tokens = m_pendingTokens.release();
callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser, m_parser, chunk.release()));
Platform::current()->mainThreadTaskRunner()->PostTask(FROM_HERE,
base::Bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser, m_parser, chunk.release()));
m_pendingTokens = adoptPtr(new CompactHTMLTokenStream);
}
......
......@@ -46,7 +46,7 @@ class BackgroundHTMLParser : public DataPipeDrainer::Client {
public:
struct Configuration {
mojo::ScopedDataPipeConsumerHandle source;
WeakPtr<HTMLDocumentParser> parser;
base::WeakPtr<HTMLDocumentParser> parser;
};
static base::WeakPtr<BackgroundHTMLParser> create(PassOwnPtr<Configuration>);
......@@ -70,7 +70,7 @@ private:
SegmentedString m_input;
OwnPtr<HTMLToken> m_token;
OwnPtr<HTMLTokenizer> m_tokenizer;
WeakPtr<HTMLDocumentParser> m_parser;
base::WeakPtr<HTMLDocumentParser> m_parser;
OwnPtr<CompactHTMLTokenStream> m_pendingTokens;
OwnPtr<TextResourceDecoder> m_decoder;
......
......@@ -41,7 +41,6 @@
#include "core/inspector/InspectorTraceEvents.h"
#include "platform/SharedBuffer.h"
#include "platform/TraceEvent.h"
#include "wtf/Functional.h"
namespace blink {
......@@ -82,7 +81,7 @@ void HTMLDocumentParser::parse(mojo::ScopedDataPipeConsumerHandle source)
OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new BackgroundHTMLParser::Configuration);
config->source = source.Pass();
config->parser = m_weakFactory.createWeakPtr();
config->parser = m_weakFactory.GetWeakPtr();
m_backgroundParser = BackgroundHTMLParser::create(config.release());
HTMLParserThread::taskRunner()->PostTask(FROM_HERE,
......@@ -350,7 +349,7 @@ void HTMLDocumentParser::stopBackgroundParser()
HTMLParserThread::taskRunner()->PostTask(FROM_HERE,
base::Bind(&BackgroundHTMLParser::stop, m_backgroundParser));
m_weakFactory.revokeAll();
m_weakFactory.InvalidateWeakPtrs();
}
void HTMLDocumentParser::end()
......
......@@ -130,7 +130,7 @@ private:
OwnPtr<ParsedChunk> m_lastChunkBeforeScript;
Deque<OwnPtr<ParsedChunk> > m_speculations;
WeakPtrFactory<HTMLDocumentParser> m_weakFactory;
base::WeakPtrFactory<HTMLDocumentParser> m_weakFactory;
base::WeakPtr<BackgroundHTMLParser> m_backgroundParser;
bool m_isFragment;
......
......@@ -31,7 +31,6 @@
#ifndef Handle_h
#define Handle_h
#include "wtf/Functional.h"
#include "wtf/HashFunctions.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RawPtr.h"
......@@ -144,27 +143,4 @@ public:
} // namespace blink
namespace WTF {
// For wtf/Functional.h
template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits;
template<typename T>
struct PointerParamStorageTraits<T*, false> {
typedef T* StorageType;
static StorageType wrap(T* value) { return value; }
static T* unwrap(const StorageType& value) { return value; }
};
template<typename T>
struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, false> {
};
template<typename T>
struct ParamStorageTraits<RawPtr<T> > : public PointerParamStorageTraits<T*, false> {
};
} // namespace WTF
#endif
......@@ -47,6 +47,10 @@
class GrContext;
namespace base {
class SingleThreadTaskRunner;
}
namespace mojo {
class NetworkService;
}
......@@ -256,6 +260,7 @@ public:
// Callable from a background WebKit thread.
virtual void callOnMainThread(void (*func)(void*), void* context) { }
virtual base::SingleThreadTaskRunner* mainThreadTaskRunner() { return 0; }
// Vibration -----------------------------------------------------------
......
......@@ -234,7 +234,6 @@ test("unittests") {
"CheckedArithmeticTest.cpp",
"DequeTest.cpp",
"DoubleBufferedDequeTest.cpp",
"FunctionalTest.cpp",
"HashMapTest.cpp",
"HashSetTest.cpp",
"ListHashSetTest.cpp",
......
此差异已折叠。
/*
* 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.
*/
#include "config.h"
#include "wtf/RefCounted.h"
#include "wtf/Functional.h"
#include <gtest/gtest.h>
namespace {
using namespace WTF;
static int returnFortyTwo()
{
return 42;
}
TEST(FunctionalTest, Basic)
{
Function<int()> emptyFunction;
EXPECT_TRUE(emptyFunction.isNull());
Function<int()> returnFortyTwoFunction = bind(returnFortyTwo);
EXPECT_FALSE(returnFortyTwoFunction.isNull());
EXPECT_EQ(42, returnFortyTwoFunction());
}
static int multiplyByTwo(int n)
{
return n * 2;
}
static double multiplyByOneAndAHalf(double d)
{
return d * 1.5;
}
TEST(FunctionalTest, UnaryBind)
{
Function<int()> multiplyFourByTwoFunction = bind(multiplyByTwo, 4);
EXPECT_EQ(8, multiplyFourByTwoFunction());
Function<double()> multiplyByOneAndAHalfFunction = bind(multiplyByOneAndAHalf, 3);
EXPECT_EQ(4.5, multiplyByOneAndAHalfFunction());
}
TEST(FunctionalTest, UnaryPartBind)
{
Function<int(int)> multiplyByTwoFunction = bind<int>(multiplyByTwo);
EXPECT_EQ(8, multiplyByTwoFunction(4));
Function<double(double)> multiplyByOneAndAHalfFunction = bind<double>(multiplyByOneAndAHalf);
EXPECT_EQ(4.5, multiplyByOneAndAHalfFunction(3));
}
static int multiply(int x, int y)
{
return x * y;
}
static int subtract(int x, int y)
{
return x - y;
}
TEST(FunctionalTest, BinaryBind)
{
Function<int()> multiplyFourByTwoFunction = bind(multiply, 4, 2);
EXPECT_EQ(8, multiplyFourByTwoFunction());
Function<int()> subtractTwoFromFourFunction = bind(subtract, 4, 2);
EXPECT_EQ(2, subtractTwoFromFourFunction());
}
TEST(FunctionalTest, BinaryPartBind)
{
Function<int(int)> multiplyFourFunction = bind<int>(multiply, 4);
EXPECT_EQ(8, multiplyFourFunction(2));
Function<int(int, int)> multiplyFunction = bind<int, int>(multiply);
EXPECT_EQ(8, multiplyFunction(4, 2));
Function<int(int)> subtractFromFourFunction = bind<int>(subtract, 4);
EXPECT_EQ(2, subtractFromFourFunction(2));
Function<int(int, int)> subtractFunction = bind<int, int>(subtract);
EXPECT_EQ(2, subtractFunction(4, 2));
}
static void sixArgFunc(int a, double b, char c, int* d, double* e, char* f)
{
*d = a;
*e = b;
*f = c;
}
static void assertArgs(int actualInt, double actualDouble, char actualChar, int expectedInt, double expectedDouble, char expectedChar)
{
EXPECT_EQ(expectedInt, actualInt);
EXPECT_EQ(expectedDouble, actualDouble);
EXPECT_EQ(expectedChar, actualChar);
}
TEST(FunctionalTest, MultiPartBind)
{
int a = 0;
double b = 0.5;
char c = 'a';
Function<void(int, double, char, int*, double*, char*)> unbound =
bind<int, double, char, int*, double*, char*>(sixArgFunc);
unbound(1, 1.5, 'b', &a, &b, &c);
assertArgs(a, b, c, 1, 1.5, 'b');
Function<void(double, char, int*, double*, char*)> oneBound =
bind<double, char, int*, double*, char*>(sixArgFunc, 2);
oneBound(2.5, 'c', &a, &b, &c);
assertArgs(a, b, c, 2, 2.5, 'c');
Function<void(char, int*, double*, char*)> twoBound =
bind<char, int*, double*, char*>(sixArgFunc, 3, 3.5);
twoBound('d', &a, &b, &c);
assertArgs(a, b, c, 3, 3.5, 'd');
Function<void(int*, double*, char*)> threeBound =
bind<int*, double*, char*>(sixArgFunc, 4, 4.5, 'e');
threeBound(&a, &b, &c);
assertArgs(a, b, c, 4, 4.5, 'e');
Function<void(double*, char*)> fourBound =
bind<double*, char*>(sixArgFunc, 5, 5.5, 'f', &a);
fourBound(&b, &c);
assertArgs(a, b, c, 5, 5.5, 'f');
Function<void(char*)> fiveBound =
bind<char*>(sixArgFunc, 6, 6.5, 'g', &a, &b);
fiveBound(&c);
assertArgs(a, b, c, 6, 6.5, 'g');
Function<void()> sixBound =
bind(sixArgFunc, 7, 7.5, 'h', &a, &b, &c);
sixBound();
assertArgs(a, b, c, 7, 7.5, 'h');
}
class A {
public:
explicit A(int i)
: m_i(i)
{
}
int f() { return m_i; }
int addF(int j) { return m_i + j; }
private:
int m_i;
};
TEST(FunctionalTest, MemberFunctionBind)
{
A a(10);
Function<int()> function1 = bind(&A::f, &a);
EXPECT_EQ(10, function1());
Function<int()> function2 = bind(&A::addF, &a, 15);
EXPECT_EQ(25, function2());
}
TEST(FunctionalTest, MemberFunctionPartBind)
{
A a(10);
Function<int(class A*)> function1 = bind<class A*>(&A::f);
EXPECT_EQ(10, function1(&a));
Function<int(class A*, int)> unboundFunction2 =
bind<class A*, int>(&A::addF);
EXPECT_EQ(25, unboundFunction2(&a, 15));
Function<int(int)> objectBoundFunction2 =
bind<int>(&A::addF, &a);
EXPECT_EQ(25, objectBoundFunction2(15));
}
class Number : public RefCounted<Number> {
public:
static PassRefPtr<Number> create(int value)
{
return adoptRef(new Number(value));
}
~Number()
{
m_value = 0;
}
int value() const { return m_value; }
private:
explicit Number(int value)
: m_value(value)
{
}
int m_value;
};
static int multiplyNumberByTwo(Number* number)
{
return number->value() * 2;
}
TEST(FunctionalTest, RefCountedStorage)
{
RefPtr<Number> five = Number::create(5);
Function<int()> multiplyFiveByTwoFunction = bind(multiplyNumberByTwo, five);
EXPECT_EQ(10, multiplyFiveByTwoFunction());
Function<int()> multiplyFourByTwoFunction = bind(multiplyNumberByTwo, Number::create(4));
EXPECT_EQ(8, multiplyFourByTwoFunction());
RefPtr<Number> six = Number::create(6);
Function<int()> multiplySixByTwoFunction = bind(multiplyNumberByTwo, six.release());
EXPECT_FALSE(six);
EXPECT_EQ(12, multiplySixByTwoFunction());
}
} // namespace
......@@ -32,7 +32,6 @@
#include "wtf/MainThread.h"
#include "wtf/Assertions.h"
#include "wtf/Functional.h"
#include "wtf/Threading.h"
#include "wtf/text/AtomicString.h"
......@@ -59,18 +58,6 @@ void callOnMainThread(MainThreadFunction* function, void* context)
(*callOnMainThreadFunction)(function, context);
}
static void callFunctionObject(void* context)
{
Function<void()>* function = static_cast<Function<void()>*>(context);
(*function)();
delete function;
}
void callOnMainThread(const Function<void()>& function)
{
callOnMainThread(callFunctionObject, new Function<void()>(function));
}
bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
......
......@@ -44,9 +44,6 @@ WTF_EXPORT void initializeMainThread(void (*)(MainThreadFunction, void*));
WTF_EXPORT void callOnMainThread(MainThreadFunction*, void* context);
template<typename> class Function;
WTF_EXPORT void callOnMainThread(const Function<void ()>&);
WTF_EXPORT bool isMainThread();
} // namespace WTF
......
......@@ -41,6 +41,7 @@ class ConvertableToTraceFormatWrapper
PlatformImpl::PlatformImpl(mojo::ApplicationImpl* app)
: main_loop_(base::MessageLoop::current()),
main_thread_task_runner_(base::MessageLoop::current()->task_runner()),
shared_timer_func_(NULL),
shared_timer_fire_time_(0.0),
shared_timer_fire_time_was_set_while_suspended_(false),
......@@ -123,6 +124,11 @@ void PlatformImpl::callOnMainThread(
main_loop_->PostTask(FROM_HERE, base::Bind(func, context));
}
base::SingleThreadTaskRunner* PlatformImpl::mainThreadTaskRunner() {
return main_thread_task_runner_.get();
}
bool PlatformImpl::isThreadedCompositingEnabled() {
return true;
}
......
......@@ -39,6 +39,7 @@ class PlatformImpl : public blink::Platform {
virtual void setSharedTimerFireInterval(double interval_seconds);
virtual void stopSharedTimer();
virtual void callOnMainThread(void (*func)(void*), void* context);
virtual base::SingleThreadTaskRunner* mainThreadTaskRunner();
virtual bool isThreadedCompositingEnabled();
virtual blink::WebCompositorSupport* compositorSupport();
virtual mojo::NetworkService* networkService();
......@@ -88,6 +89,7 @@ class PlatformImpl : public blink::Platform {
mojo::NetworkServicePtr network_service_;
base::MessageLoop* main_loop_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
base::OneShotTimer<PlatformImpl> shared_timer_;
void (*shared_timer_func_)();
double shared_timer_fire_time_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册