forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_decoder_service.h
104 lines (86 loc) · 3.85 KB
/
data_decoder_service.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2016 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 SERVICES_DATA_DECODER_DATA_DECODER_SERVICE_H_
#define SERVICES_DATA_DECODER_DATA_DECODER_SERVICE_H_
#include <memory>
#include "base/macros.h"
#include "components/web_package/mojom/web_bundle_parser.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "services/data_decoder/public/mojom/data_decoder_service.mojom.h"
#include "services/data_decoder/public/mojom/gzipper.mojom.h"
#include "services/data_decoder/public/mojom/image_decoder.mojom.h"
#include "services/data_decoder/public/mojom/json_parser.mojom.h"
#include "services/data_decoder/public/mojom/web_bundler.mojom.h"
#include "services/data_decoder/public/mojom/xml_parser.mojom.h"
#ifdef OS_CHROMEOS
#include "services/data_decoder/public/mojom/ble_scan_parser.mojom.h"
#endif // OS_CHROMEOS
namespace data_decoder {
class DataDecoderService : public mojom::DataDecoderService {
public:
DataDecoderService();
explicit DataDecoderService(
mojo::PendingReceiver<mojom::DataDecoderService> receiver);
~DataDecoderService() override;
// May be used to establish a latent DataDecoderService binding for this
// instance. May only be called once, and only if this instance was default-
// constructed.
void BindReceiver(mojo::PendingReceiver<mojom::DataDecoderService> receiver);
// Configures the service to drop ImageDecoder receivers instead of binding
// them. Useful for tests simulating service failures.
void SimulateImageDecoderCrashForTesting(bool drop) {
drop_image_decoders_ = drop;
}
// Same as above but for JsonParser receivers.
void SimulateJsonParserCrashForTesting(bool drop) {
drop_json_parsers_ = drop;
}
// Configures the service to use |binder| to bind
// WebBundleParserFactory in subsequent
// BindWebBundleParserFactory() calls.
void SetWebBundleParserFactoryBinderForTesting(
base::RepeatingCallback<void(
mojo::PendingReceiver<web_package::mojom::WebBundleParserFactory>)>
binder) {
web_bundle_parser_factory_binder_ = binder;
}
// Configures the service to use |binder| to bind WebBundler in subsequent
// BindWebBundler() calls.
void SetWebBundlerBinderForTesting(
base::RepeatingCallback<void(mojo::PendingReceiver<mojom::WebBundler>)>
binder) {
web_bundler_binder_ = binder;
}
private:
// mojom::DataDecoderService implementation:
void BindImageDecoder(
mojo::PendingReceiver<mojom::ImageDecoder> receiver) override;
void BindJsonParser(
mojo::PendingReceiver<mojom::JsonParser> receiver) override;
void BindXmlParser(mojo::PendingReceiver<mojom::XmlParser> receiver) override;
void BindWebBundleParserFactory(
mojo::PendingReceiver<web_package::mojom::WebBundleParserFactory>
receiver) override;
void BindWebBundler(
mojo::PendingReceiver<mojom::WebBundler> receiver) override;
void BindGzipper(mojo::PendingReceiver<mojom::Gzipper> receiver) override;
#ifdef OS_CHROMEOS
void BindBleScanParser(
mojo::PendingReceiver<mojom::BleScanParser> receiver) override;
#endif // OS_CHROMEOS
// In-process instances (e.g. on iOS or in tests) may have multiple concurrent
// remote DataDecoderService clients.
mojo::ReceiverSet<mojom::DataDecoderService> receivers_;
bool drop_image_decoders_ = false;
bool drop_json_parsers_ = false;
base::RepeatingCallback<void(
mojo::PendingReceiver<web_package::mojom::WebBundleParserFactory>)>
web_bundle_parser_factory_binder_;
base::RepeatingCallback<void(mojo::PendingReceiver<mojom::WebBundler>)>
web_bundler_binder_;
DISALLOW_COPY_AND_ASSIGN(DataDecoderService);
};
} // namespace data_decoder
#endif // SERVICES_DATA_DECODER_DATA_DECODER_SERVICE_H_