summaryrefslogtreecommitdiffstats
path: root/third_party/content_analysis_sdk/browser/include/content_analysis/sdk/analysis_client.h
blob: c7c5da85209a69dc51a5f00602acdc8c849b8fb8 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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.

#ifndef CONTENT_ANALYSIS_BROWSER_INCLUDE_CONTENT_ANALYSIS_SDK_ANALYSIS_CLIENT_H_
#define CONTENT_ANALYSIS_BROWSER_INCLUDE_CONTENT_ANALYSIS_SDK_ANALYSIS_CLIENT_H_

#include <memory>
#include <string>

#include "content_analysis/sdk/analysis.pb.h"

// This is the main include file for code using Content Analysis Connector
// Client SDK.  No other include is needed.
//
// A browser begins by creating an instance of Client using the factory
// function Client::Create().  This instance should live as long as the browser
// intends to send content analysis requests to the content analysis agent.

namespace content_analysis {
namespace sdk {

// Represents information about one instance of a content analysis agent
// process that is connected to the browser.
struct AgentInfo {
  unsigned long pid = 0;  // Process ID of content analysis agent process.
  std::string binary_path;  // The full path to the process's main binary.
};

// Represents a client that can request content analysis for locally running
// agent.  This class holds the client endpoint that the browser connects
// with when content analysis is required.
//
// See the demo directory for an example of how to use this class.
class Client {
 public:
   // Configuration options where creating an agent.  `name` is used to create
   // a channel between the agent and Google Chrome.
   struct Config {
     // Used to create a channel between the agent and Google Chrome.  Both must
     // use the same name to properly rendezvous with each other.  The channel
     // is platform specific.
     std::string name;

     // Set to true if there is a different agent instance per OS user.  Defaults
     // to false.
     bool user_specific = false;
   };

  // Returns a new client instance and calls Start().
  static std::unique_ptr<Client> Create(Config config);

  virtual ~Client() = default;

  // Returns the configuration parameters used to create the client.
  virtual const Config& GetConfig() const = 0;

  // Retrives information about the agent that is connected to the browser.
  virtual const AgentInfo& GetAgentInfo() const = 0;

  // Sends an analysis request to the agent and waits for a response.
  virtual int Send(ContentAnalysisRequest request,
                   ContentAnalysisResponse* response) = 0;

  // Sends an response acknowledgment back to the agent.
  virtual int Acknowledge(const ContentAnalysisAcknowledgement& ack) = 0;

  // Ask the agent to cancel all requests matching the criteria in `cancel`.
  // This is a best effort only, the agent may cancel some, all, or no requests
  // that match.
  virtual int CancelRequests(const ContentAnalysisCancelRequests& cancel) = 0;

 protected:
  Client() = default;
  Client(const Client& rhs) = delete;
  Client(Client&& rhs) = delete;
  Client& operator=(const Client& rhs) = delete;
  Client& operator=(Client&& rhs) = delete;
};

}  // namespace sdk
}  // namespace content_analysis

#endif  // CONTENT_ANALYSIS_BROWSER_INCLUDE_CONTENT_ANALYSIS_SDK_ANALYSIS_CLIENT_H_