Move Sky's DataPipeDrainer to mojo/common

I want to use DataPipeDrainer in some non-sky code
it seems generally useful (and compiled w/o modification).

R=jimbe@chromium.org, jamesr@chromium.org

Review URL: https://codereview.chromium.org/811873003
This commit is contained in:
Eric Seidel 2014-12-17 12:16:34 -08:00
parent 0b8c9cf3ac
commit a251cf3ecb
6 changed files with 5 additions and 103 deletions

View File

@ -31,7 +31,6 @@
#ifndef SKY_ENGINE_CORE_HTML_IMPORTS_HTMLIMPORTLOADER_H_
#define SKY_ENGINE_CORE_HTML_IMPORTS_HTMLIMPORTLOADER_H_
#include "sky/engine/platform/fetcher/DataPipeDrainer.h"
#include "sky/engine/platform/fetcher/MojoFetcher.h"
#include "sky/engine/platform/heap/Handle.h"
#include "sky/engine/wtf/OwnPtr.h"

View File

@ -76,7 +76,7 @@ BackgroundHTMLParser::~BackgroundHTMLParser()
void BackgroundHTMLParser::start()
{
m_drainer = adoptPtr(new DataPipeDrainer(this, m_source.Pass()));
m_drainer = adoptPtr(new mojo::common::DataPipeDrainer(this, m_source.Pass()));
}
void BackgroundHTMLParser::stop()

View File

@ -27,11 +27,11 @@
#define SKY_ENGINE_CORE_HTML_PARSER_BACKGROUNDHTMLPARSER_H_
#include "base/memory/weak_ptr.h"
#include "mojo/common/data_pipe_drainer.h"
#include "mojo/public/cpp/system/core.h"
#include "sky/engine/core/html/parser/CompactHTMLToken.h"
#include "sky/engine/core/html/parser/HTMLTokenizer.h"
#include "sky/engine/core/html/parser/TextResourceDecoder.h"
#include "sky/engine/platform/fetcher/DataPipeDrainer.h"
#include "sky/engine/platform/text/SegmentedString.h"
#include "sky/engine/wtf/PassOwnPtr.h"
#include "sky/engine/wtf/WeakPtr.h"
@ -41,7 +41,7 @@ namespace blink {
class HTMLDocumentParser;
class SharedBuffer;
class BackgroundHTMLParser : public DataPipeDrainer::Client {
class BackgroundHTMLParser : public mojo::common::DataPipeDrainer::Client {
WTF_MAKE_FAST_ALLOCATED;
public:
struct Configuration {
@ -58,6 +58,7 @@ private:
explicit BackgroundHTMLParser(PassOwnPtr<Configuration>);
~BackgroundHTMLParser();
// DataPipeDrainer::Client:
void OnDataAvailable(const void* data, size_t numberOfBytes) override;
void OnDataComplete() override;
@ -76,7 +77,7 @@ private:
OwnPtr<TextResourceDecoder> m_decoder;
mojo::ScopedDataPipeConsumerHandle m_source;
OwnPtr<DataPipeDrainer> m_drainer;
OwnPtr<mojo::common::DataPipeDrainer> m_drainer;
base::WeakPtrFactory<BackgroundHTMLParser> m_weakFactory;
};

View File

@ -144,8 +144,6 @@ source_set("platform") {
"exported/WebURLResponsePrivate.h",
"exported/WrappedResourceRequest.h",
"exported/WrappedResourceResponse.h",
"fetcher/DataPipeDrainer.cpp",
"fetcher/DataPipeDrainer.h",
"fetcher/MojoFetcher.cpp",
"fetcher/MojoFetcher.h",
"FloatConversion.h",

View File

@ -1,52 +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.
#include "sky/engine/config.h"
#include "sky/engine/platform/fetcher/DataPipeDrainer.h"
#include "base/bind.h"
namespace blink {
DataPipeDrainer::DataPipeDrainer(Client* client,
mojo::ScopedDataPipeConsumerHandle source)
: client_(client),
source_(source.Pass()),
weak_factory_(this) {
DCHECK(client_);
ReadData();
}
DataPipeDrainer::~DataPipeDrainer() {
}
void DataPipeDrainer::ReadData() {
const void* buffer = nullptr;
uint32_t num_bytes = 0;
MojoResult rv = BeginReadDataRaw(source_.get(),
&buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE);
if (rv == MOJO_RESULT_OK) {
client_->OnDataAvailable(buffer, num_bytes);
EndReadDataRaw(source_.get(), num_bytes);
WaitForData();
} else if (rv == MOJO_RESULT_SHOULD_WAIT) {
WaitForData();
} else if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
client_->OnDataComplete();
} else {
DCHECK(false);
}
}
void DataPipeDrainer::WaitForData() {
handle_watcher_.Start(source_.get(),
MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
base::Bind(&DataPipeDrainer::WaitComplete, weak_factory_.GetWeakPtr()));
}
void DataPipeDrainer::WaitComplete(MojoResult result) {
ReadData();
}
} // namespace blink

View File

@ -1,44 +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 SKY_ENGINE_PLATFORM_FETCHER_DATAPIPEDRAINER_H_
#define SKY_ENGINE_PLATFORM_FETCHER_DATAPIPEDRAINER_H_
#include "base/memory/weak_ptr.h"
#include "mojo/common/handle_watcher.h"
#include "mojo/public/cpp/system/core.h"
namespace blink {
class DataPipeDrainer {
public:
class Client {
public:
virtual void OnDataAvailable(const void* data, size_t num_bytes) = 0;
virtual void OnDataComplete() = 0;
protected:
virtual ~Client() { }
};
DataPipeDrainer(Client*, mojo::ScopedDataPipeConsumerHandle source);
~DataPipeDrainer();
private:
void ReadData();
void WaitForData();
void WaitComplete(MojoResult result);
Client* client_;
mojo::ScopedDataPipeConsumerHandle source_;
mojo::common::HandleWatcher handle_watcher_;
base::WeakPtrFactory<DataPipeDrainer> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DataPipeDrainer);
};
} // namespace blink
#endif // SKY_ENGINE_PLATFORM_FETCHER_DATAPIPEDRAINER_H_