File: fake_random_access_stream.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 3,079 bytes parent folder | download | duplicates (7)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_WEBSHARE_WIN_FAKE_RANDOM_ACCESS_STREAM_H_
#define CHROME_BROWSER_WEBSHARE_WIN_FAKE_RANDOM_ACCESS_STREAM_H_

#include <windows.foundation.h>
#include <windows.storage.streams.h>
#include <wrl/implements.h>

#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"

namespace webshare {

class StreamData;

// Provides an implementation of IRandomAccessStream for use in GTests.
class __declspec(uuid("66DAD26A-BEDE-4A54-8316-088838CC65A0"))
    FakeRandomAccessStream final
    : public Microsoft::WRL::RuntimeClass<
          Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>,
          ABI::Windows::Storage::Streams::IRandomAccessStream,
          ABI::Windows::Foundation::IClosable,
          ABI::Windows::Storage::Streams::IInputStream,
          ABI::Windows::Storage::Streams::IOutputStream> {
 public:
  FakeRandomAccessStream();
  FakeRandomAccessStream(const FakeRandomAccessStream& other) = delete;
  FakeRandomAccessStream& operator=(const FakeRandomAccessStream&) = delete;
  ~FakeRandomAccessStream() final;

  // ABI::Windows::Storage::Streams::IRandomAccessStream:
  IFACEMETHODIMP get_Size(UINT64* value) final;
  IFACEMETHODIMP put_Size(UINT64 value) final;
  IFACEMETHODIMP
  GetInputStreamAt(UINT64 position,
                   ABI::Windows::Storage::Streams::IInputStream** stream) final;
  IFACEMETHODIMP
  GetOutputStreamAt(
      UINT64 position,
      ABI::Windows::Storage::Streams::IOutputStream** stream) final;
  IFACEMETHODIMP get_Position(UINT64* value) final;
  IFACEMETHODIMP Seek(UINT64 position) final;
  IFACEMETHODIMP
  CloneStream(IRandomAccessStream** stream) final;
  IFACEMETHODIMP get_CanRead(boolean* value) final;
  IFACEMETHODIMP get_CanWrite(boolean* value) final;

  // ABI::Windows::Foundation::IClosable:
  IFACEMETHODIMP Close() final;

  // ABI::Windows::Storage::Streams::IInputStream:
  IFACEMETHODIMP ReadAsync(
      ABI::Windows::Storage::Streams::IBuffer* buffer,
      UINT32 count,
      ABI::Windows::Storage::Streams::InputStreamOptions options,
      ABI::Windows::Foundation::IAsyncOperationWithProgress<
          ABI::Windows::Storage::Streams::IBuffer*,
          UINT32>** operation) final;

  // ABI::Windows::Storage::Streams::IOutputStream:
  IFACEMETHODIMP
  WriteAsync(
      ABI::Windows::Storage::Streams::IBuffer* buffer,
      ABI::Windows::Foundation::IAsyncOperationWithProgress<UINT32, UINT32>**
          operation) final;
  IFACEMETHODIMP
  FlushAsync(ABI::Windows::Foundation::IAsyncOperation<bool>** operation) final;

  // Sets a callback to be invoked when |Close| is called.
  void OnClose(base::OnceClosure on_close);

 private:
  scoped_refptr<StreamData> shared_data_;
  scoped_refptr<base::RefCountedData<UINT64>> position_;
  bool is_closed_ = false;
  base::OnceClosure on_close_;
};

}  // namespace webshare

#endif  // CHROME_BROWSER_WEBSHARE_WIN_FAKE_RANDOM_ACCESS_STREAM_H_