• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_DRAINER_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_DRAINER_H_
7 
8 #include <stddef.h>
9 
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "mojo/public/cpp/system/core.h"
13 #include "mojo/public/cpp/system/simple_watcher.h"
14 #include "mojo/public/cpp/system/system_export.h"
15 
16 namespace mojo {
17 
18 class MOJO_CPP_SYSTEM_EXPORT DataPipeDrainer {
19  public:
20   class Client {
21    public:
22     virtual void OnDataAvailable(const void* data, size_t num_bytes) = 0;
23     virtual void OnDataComplete() = 0;
24 
25    protected:
~Client()26     virtual ~Client() {}
27   };
28 
29   DataPipeDrainer(Client*, mojo::ScopedDataPipeConsumerHandle source);
30   ~DataPipeDrainer();
31 
32  private:
33   void ReadData();
34   void WaitComplete(MojoResult result);
35 
36   Client* client_;
37   mojo::ScopedDataPipeConsumerHandle source_;
38   mojo::SimpleWatcher handle_watcher_;
39 
40   base::WeakPtrFactory<DataPipeDrainer> weak_factory_;
41 
42   DISALLOW_COPY_AND_ASSIGN(DataPipeDrainer);
43 };
44 
45 }  // namespace mojo
46 
47 #endif  // MOJO_PUBLIC_CPP_SYSTEM_DATA_PIPE_DRAINER_H_
48