blob: c8186a41121f362ff4fceaadbb7b6bee6fd1f05a (
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
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright 2022 The Chromium Authors.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "event_base.h"
namespace content_analysis {
namespace sdk {
ContentAnalysisEventBase::ContentAnalysisEventBase(
const BrowserInfo& browser_info)
: browser_info_(browser_info) {}
ResultCode ContentAnalysisEventBase::Close() {
return ResultCode::OK;
}
ResultCode UpdateResponse(ContentAnalysisResponse& response,
const std::string& tag,
ContentAnalysisResponse::Result::Status status) {
auto result = response.results_size() > 0
? response.mutable_results(0)
: response.add_results();
if (!tag.empty()) {
result->set_tag(tag);
}
if (status != ContentAnalysisResponse::Result::STATUS_UNKNOWN) {
result->set_status(status);
}
return ResultCode::OK;
}
ResultCode SetEventVerdictTo(
ContentAnalysisEvent* event,
ContentAnalysisResponse::Result::TriggeredRule::Action action) {
// This function expects that the event's result has already been
// initialized by a call to UpdateResponse().
if (event->GetResponse().results_size() == 0) {
return ResultCode::ERR_MISSING_RESULT;
}
auto result = event->GetResponse().mutable_results(0);
// Content analysis responses generated with this SDK contain at most one
// triggered rule.
auto rule = result->triggered_rules_size() > 0
? result->mutable_triggered_rules(0)
: result->add_triggered_rules();
rule->set_action(action);
return ResultCode::OK;
}
ResultCode SetEventVerdictToBlock(ContentAnalysisEvent* event) {
return SetEventVerdictTo(event,
ContentAnalysisResponse::Result::TriggeredRule::BLOCK);
}
} // namespace sdk
} // namespace content_analysis
|