1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_OBSERVER_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_OBSERVER_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <bitset>
12 #include <set>
13 #include <utility>
14 
15 #include "base/macros.h"
16 #include "base/stl_util.h"
17 #include "content/common/content_export.h"
18 #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
19 
20 namespace content {
21 
22 class CONTENT_EXPORT IndexedDBObserver {
23  public:
24   struct CONTENT_EXPORT Options {
25     explicit Options(bool include_transaction,
26                      bool no_records,
27                      bool values,
28                      std::bitset<blink::kIDBOperationTypeCount> types);
29     Options(const Options&);
30     ~Options();
31 
32     bool include_transaction;
33     bool no_records;
34     bool values;
35     // Operation type bits are set corresponding to mojom::IDBOperationType.
36     std::bitset<blink::kIDBOperationTypeCount> operation_types;
37   };
38   IndexedDBObserver(int32_t observer_id,
39                     std::set<int64_t> object_store_ids,
40                     const Options& options);
41   ~IndexedDBObserver();
42 
id()43   int32_t id() const { return id_; }
object_store_ids()44   const std::set<int64_t>& object_store_ids() const {
45     return object_store_ids_;
46   }
47 
set_object_store_ids(std::set<int64_t> ids)48   void set_object_store_ids(std::set<int64_t> ids) {
49     object_store_ids_ = std::move(ids);
50   }
51 
IsRecordingType(blink::mojom::IDBOperationType type)52   bool IsRecordingType(blink::mojom::IDBOperationType type) const {
53     DCHECK_LT(static_cast<size_t>(type), blink::kIDBOperationTypeCount);
54     return options_.operation_types[static_cast<size_t>(type)];
55   }
IsRecordingObjectStore(int64_t object_store_id)56   bool IsRecordingObjectStore(int64_t object_store_id) const {
57     return base::Contains(object_store_ids_, object_store_id);
58   }
include_transaction()59   bool include_transaction() const { return options_.include_transaction; }
no_records()60   bool no_records() const { return options_.no_records; }
values()61   bool values() const { return options_.values; }
62 
63  private:
64   int32_t id_;
65   std::set<int64_t> object_store_ids_;
66   Options options_;
67 
68   DISALLOW_COPY_AND_ASSIGN(IndexedDBObserver);
69 };
70 
71 }  // namespace content
72 
73 #endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_OBSERVER_H_
74