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

content / public / browser / k_anonymity_service_delegate.h [blame]

// 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_PUBLIC_BROWSER_K_ANONYMITY_SERVICE_DELEGATE_H_
#define CONTENT_PUBLIC_BROWSER_K_ANONYMITY_SERVICE_DELEGATE_H_

#include <string>
#include <vector>

#include "base/functional/bind.h"
#include "base/time/time.h"
#include "content/common/content_export.h"

namespace content {

// The KAnonymityServiceDelegate interface provides functions to determine if
// the provided ID is k-anonymous in the sense that QuerySet only returns true
// for an ID if at least k other users have called JoinSet for that ID within
// an implementation defined time window. The value k is defined the by the
// implementer of this interface.
class CONTENT_EXPORT KAnonymityServiceDelegate {
 public:
  virtual ~KAnonymityServiceDelegate() = default;

  // JoinSets marks the provided ID as being used by this client. The
  // caller of this function should avoid calling this function repeatedly for
  // the same IDs, as there is no guarantee the implementer deduplicates calls.
  // The callback is called asynchronously when the join has completed or
  // failed. A value of 'true' passed to the callback indicates the join
  // completed successfully. The ID is already hashed via SHA256.
  virtual void JoinSet(std::string id,
                       base::OnceCallback<void(bool)> callback) = 0;

  // QuerySet requests the k-anonymity status of the provided IDs. The callback
  // will be called asynchronously. If the request is successful, the callback
  // will be passed a vector where `true` means the ID in the same index of the
  // request is k-anonymous and `false` means that the ID isn't k-anonymous. In
  // the event of an error, an empty vector will be passed to the callback.
  // There is no requirement that a user has joined an ID or has not joined and
  // ID to perform a query on that ID. The IDs are already hashed via SHA256.
  virtual void QuerySets(
      std::vector<std::string> ids,
      base::OnceCallback<void(std::vector<bool>)> callback) = 0;

  // The minimum period of time that a user of this interface should wait
  // between JoinSet calls with the same `id`.
  virtual base::TimeDelta GetJoinInterval() = 0;

  // The minimum period of time that a user of this interface should wait
  // between QuerySets calls including the same `id`.
  virtual base::TimeDelta GetQueryInterval() = 0;
};

}  // namespace content
#endif  // CONTENT_PUBLIC_BROWSER_K_ANONYMITY_SERVICE_DELEGATE_H_