summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/public/platform/media/learning_experiment_helper.h
blob: 890380a831f2f13535163991aac3570342af61c4 (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
// 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 THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MEDIA_LEARNING_EXPERIMENT_HELPER_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MEDIA_LEARNING_EXPERIMENT_HELPER_H_

#include <memory>

#include "media/learning/common/feature_dictionary.h"
#include "media/learning/common/labelled_example.h"
#include "media/learning/common/learning_task.h"
#include "media/learning/common/learning_task_controller.h"
#include "third_party/blink/public/platform/web_common.h"

namespace blink {

// Helper for adding a learning experiment to existing code.
class BLINK_PLATFORM_EXPORT LearningExperimentHelper {
 public:
  // If |controller| is null, then everything else no-ops.
  LearningExperimentHelper(
      std::unique_ptr<media::learning::LearningTaskController> controller);

  LearningExperimentHelper(const LearningExperimentHelper&) = delete;
  LearningExperimentHelper& operator=(const LearningExperimentHelper&) = delete;

  // Cancels any existing observation.
  ~LearningExperimentHelper();

  // Start a new observation.  Any existing observation is cancelled.  Does
  // nothing if there's no controller.
  void BeginObservation(const media::learning::FeatureDictionary& dictionary);

  // Complete any pending observation.  Does nothing if none is in progress.
  void CompleteObservationIfNeeded(const media::learning::TargetValue& target);

  // Cancel any pending observation.
  void CancelObservationIfNeeded();

 private:
  // May be null.
  std::unique_ptr<media::learning::LearningTaskController> controller_;

  // May be null if no observation is in flight.  Must be null if |controller_|
  // is null.
  base::UnguessableToken observation_id_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MEDIA_LEARNING_EXPERIMENT_HELPER_H_