File: data_url_blob_reader.h

package info (click to toggle)
qtwebengine-opensource-src 5.15.13%2Bdfsg-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,112,448 kB
  • sloc: cpp: 13,167,885; ansic: 4,228,702; javascript: 1,909,649; python: 554,805; asm: 529,966; xml: 496,619; java: 151,702; objc: 80,776; perl: 73,361; sh: 71,208; cs: 30,383; makefile: 20,779; yacc: 9,120; tcl: 8,394; php: 5,896; sql: 5,473; pascal: 4,510; lex: 2,884; lisp: 2,727; ruby: 559; awk: 200; sed: 40
file content (72 lines) | stat: -rw-r--r-- 2,289 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
// Copyright 2019 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_BROWSER_DOWNLOAD_DATA_URL_BLOB_READER_H_
#define CONTENT_BROWSER_DOWNLOAD_DATA_URL_BLOB_READER_H_

#include <string>

#include "base/callback_forward.h"
#include "base/sequence_checker.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
#include "third_party/blink/public/mojom/blob/blob.mojom.h"
#include "url/gurl.h"

namespace storage {
class BlobDataHandle;
}  // namespace storage

namespace content {

// Helper class to read a data url from a BlobDataHandle.
class CONTENT_EXPORT DataURLBlobReader : public mojo::DataPipeDrainer::Client {
 public:
  using ReadCompletionCallback = base::OnceCallback<void(GURL)>;

  // Read the data URL from |blob_data_handle|, and call
  // |read_completion_callback| once it completes. If the data URL cannot be
  // retrieved, |read_completion_callback| will be called with an empty URL.
  // This method must be called on the UI thread.
  static void ReadDataURLFromBlob(
      mojo::PendingRemote<blink::mojom::Blob> data_url_blob,
      ReadCompletionCallback read_completion_callback);

  ~DataURLBlobReader() override;

 private:
  DataURLBlobReader(mojo::PendingRemote<blink::mojom::Blob> data_url_blob);

  // Starts reading from the |data_url_blob_| and calls |callback| once
  // completes.
  void Start(base::OnceClosure callback);

  // mojo::DataPipeDrainer:
  void OnDataAvailable(const void* data, size_t num_bytes) override;
  void OnDataComplete() override;

  // Called when failed to read from blob.
  void OnFailed();

  std::unique_ptr<mojo::DataPipeDrainer> data_pipe_drainer_;

  mojo::Remote<blink::mojom::Blob> data_url_blob_;

  // Data URL retrieved from the blob.
  std::string url_data_;

  // Callback to run once blob data is read.
  base::OnceClosure callback_;

  SEQUENCE_CHECKER(sequence_checker_);

  DISALLOW_COPY_AND_ASSIGN(DataURLBlobReader);
};

}  // namespace content

#endif  // CONTENT_BROWSER_DOWNLOAD_DATA_URL_BLOB_READER_H_