summaryrefslogtreecommitdiffstats
path: root/content/child/web_data_consumer_handle_impl.h
blob: 167fe400c14eef0dcdb2944232bd2dd808d0f9fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// 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 CONTENT_CHILD_WEB_DATA_CONSUMER_HANDLE_IMPL_H_
#define CONTENT_CHILD_WEB_DATA_CONSUMER_HANDLE_IMPL_H_

#include "base/memory/scoped_ptr.h"
#include "content/common/content_export.h"
#include "mojo/common/handle_watcher.h"
#include "third_party/WebKit/public/platform/WebDataConsumerHandle.h"
#include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h"

namespace content {

class CONTENT_EXPORT WebDataConsumerHandleImpl final
    : public NON_EXPORTED_BASE(blink::WebDataConsumerHandle) {
  typedef mojo::ScopedDataPipeConsumerHandle Handle;
  class Context;

 public:
  class CONTENT_EXPORT ReaderImpl final : public NON_EXPORTED_BASE(Reader) {
   public:
    ReaderImpl(scoped_refptr<Context> context, Client* client);
    virtual ~ReaderImpl();
    virtual Result read(void* data, size_t size, Flags flags, size_t* readSize);
    virtual Result beginRead(const void** buffer,
                             Flags flags,
                             size_t* available);
    virtual Result endRead(size_t readSize);

   private:
    Result HandleReadResult(MojoResult);
    void StartWatching();
    void OnHandleGotReadable(MojoResult);

    scoped_refptr<Context> context_;
    mojo::common::HandleWatcher handle_watcher_;
    Client* client_;
  };
  scoped_ptr<Reader> ObtainReader(Client* client);

  explicit WebDataConsumerHandleImpl(Handle handle);
  virtual ~WebDataConsumerHandleImpl();

 private:
  virtual ReaderImpl* obtainReaderInternal(Client* client);

  scoped_refptr<Context> context_;
};

}  // namespace content

#endif  // CONTENT_CHILD_WEB_DATA_CONSUMER_HANDLE_IMPL_H_