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

content / browser / shared_storage / shared_storage_event_params.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_BROWSER_SHARED_STORAGE_SHARED_STORAGE_EVENT_PARAMS_H_
#define CONTENT_BROWSER_SHARED_STORAGE_SHARED_STORAGE_EVENT_PARAMS_H_

#include <map>
#include <optional>

#include "content/common/content_export.h"
#include "third_party/blink/public/common/messaging/cloneable_message.h"
#include "url/gurl.h"

namespace content {

// Bundles the varying possible parameters for DevTools shared storage access
// events.
class CONTENT_EXPORT SharedStorageEventParams {
 public:
  // Bundles a URL's spec along with a map of any accompanying reporting
  // metadata for DevTools integration.
  struct CONTENT_EXPORT SharedStorageUrlSpecWithMetadata {
    std::string url;
    std::map<std::string, std::string> reporting_metadata;
    SharedStorageUrlSpecWithMetadata();
    SharedStorageUrlSpecWithMetadata(
        const GURL& url,
        std::map<std::string, std::string> reporting_metadata);
    SharedStorageUrlSpecWithMetadata(const SharedStorageUrlSpecWithMetadata&);
    ~SharedStorageUrlSpecWithMetadata();
    SharedStorageUrlSpecWithMetadata& operator=(
        const SharedStorageUrlSpecWithMetadata&);
    bool operator==(const SharedStorageUrlSpecWithMetadata&) const;
  };

  static SharedStorageEventParams CreateForAddModule(
      const GURL& script_source_url);

  static SharedStorageEventParams CreateForRun(
      const std::string& operation_name,
      const blink::CloneableMessage& serialized_data);
  static SharedStorageEventParams CreateForSelectURL(
      const std::string& operation_name,
      const blink::CloneableMessage& serialized_data,
      std::vector<SharedStorageUrlSpecWithMetadata> urls_with_metadata);
  static SharedStorageEventParams CreateForSet(const std::string& key,
                                               const std::string& value,
                                               bool ignore_if_present);
  static SharedStorageEventParams CreateForAppend(const std::string& key,
                                                  const std::string& value);
  static SharedStorageEventParams CreateForGetOrDelete(const std::string& key);
  static SharedStorageEventParams CreateDefault();

  SharedStorageEventParams(const SharedStorageEventParams&);
  ~SharedStorageEventParams();
  SharedStorageEventParams& operator=(const SharedStorageEventParams&);

  std::optional<std::string> script_source_url;
  std::optional<std::string> operation_name;
  std::optional<std::string> serialized_data;
  std::optional<std::vector<SharedStorageUrlSpecWithMetadata>>
      urls_with_metadata;
  std::optional<std::string> key;
  std::optional<std::string> value;
  std::optional<bool> ignore_if_present;

 private:
  SharedStorageEventParams();
  SharedStorageEventParams(
      std::optional<std::string> script_source_url,
      std::optional<std::string> operation_name,
      std::optional<std::string> serialized_data,
      std::optional<std::vector<SharedStorageUrlSpecWithMetadata>>
          urls_with_metadata,
      std::optional<std::string> key,
      std::optional<std::string> value,
      std::optional<bool> ignore_if_present);
};

}  // namespace content

#endif  // CONTENT_BROWSER_SHARED_STORAGE_SHARED_STORAGE_EVENT_PARAMS_H_