summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/indexeddb/indexed_db_callbacks_impl.h
blob: efbaeb80604874805a2a30763b36e390c80efeb3 (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
// Copyright 2016 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_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CALLBACKS_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CALLBACKS_IMPL_H_

#include <stdint.h>

#include <memory>

#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_key.h"
#include "third_party/blink/public/common/indexeddb/indexeddb_metadata.h"
#include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom-blink.h"

namespace blink {

class WebIDBCallbacks;
class WebIDBCursorImpl;
class WebIDBValue;

// Implements the child-process end of the pipe used to deliver callbacks.
// |callback_runner_| is used to post tasks back to the thread which owns the
// blink::WebIDBCallbacks.
class IndexedDBCallbacksImpl : public mojom::blink::IDBCallbacks {
 public:
  // |kNoTransaction| is used as the default transaction ID when instantiating
  // an IndexedDBCallbacksImpl instance.  See web_idb_factory_impl.cc for those
  // cases.
  enum : int64_t { kNoTransaction = -1 };

  static WebIDBValue ConvertValue(const mojom::blink::IDBValuePtr& value);

  IndexedDBCallbacksImpl(std::unique_ptr<WebIDBCallbacks> callbacks,
                         int64_t transaction_id,
                         const base::WeakPtr<WebIDBCursorImpl>& cursor);
  ~IndexedDBCallbacksImpl() override;

  // mojom::blink::IDBCallbacks implementation:
  void Error(int32_t code, const String& message) override;
  void SuccessNamesAndVersionsList(
      Vector<mojom::blink::IDBNameAndVersionPtr> names_and_versions) override;
  void SuccessStringList(const Vector<String>& value) override;
  void Blocked(int64_t existing_version) override;
  void UpgradeNeeded(mojom::blink::IDBDatabaseAssociatedPtrInfo database_info,
                     int64_t old_version,
                     mojom::IDBDataLoss data_loss,
                     const String& data_loss_message,
                     const WebIDBMetadata& metadata) override;
  void SuccessDatabase(mojom::blink::IDBDatabaseAssociatedPtrInfo database_info,
                       const WebIDBMetadata& metadata) override;
  void SuccessCursor(mojom::blink::IDBCursorAssociatedPtrInfo cursor,
                     WebIDBKey key,
                     WebIDBKey primary_key,
                     mojom::blink::IDBValuePtr value) override;
  void SuccessValue(mojom::blink::IDBReturnValuePtr value) override;
  void SuccessCursorContinue(WebIDBKey key,
                             WebIDBKey primary_key,
                             mojom::blink::IDBValuePtr value) override;
  void SuccessCursorPrefetch(Vector<WebIDBKey> keys,
                             Vector<WebIDBKey> primary_keys,
                             Vector<mojom::blink::IDBValuePtr> values) override;
  void SuccessArray(Vector<mojom::blink::IDBReturnValuePtr> values) override;
  void SuccessKey(WebIDBKey key) override;
  void SuccessInteger(int64_t value) override;
  void Success() override;

 private:
  scoped_refptr<base::SingleThreadTaskRunner> callback_runner_;
  std::unique_ptr<WebIDBCallbacks> callbacks_;
  base::WeakPtr<WebIDBCursorImpl> cursor_;
  int64_t transaction_id_;

  DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacksImpl);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_INDEXEDDB_INDEXED_DB_CALLBACKS_IMPL_H_