summaryrefslogtreecommitdiffstats
path: root/content/browser/indexed_db/indexed_db_callbacks.h
blob: 6ed751c6f83645dc377724eb33edffb6053b665c (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright (c) 2012 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 CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_
#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "content/browser/indexed_db/indexed_db_database_error.h"
#include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
#include "content/common/indexed_db/indexed_db_key.h"
#include "content/common/indexed_db/indexed_db_key_path.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/public/platform/WebIDBCallbacks.h"
#include "third_party/WebKit/public/platform/WebIDBDatabase.h"

namespace content {
class IndexedDBCursor;
class IndexedDBDatabase;
class IndexedDBDatabaseCallbacks;
class WebIDBDatabaseImpl;
struct IndexedDBDatabaseMetadata;

class CONTENT_EXPORT IndexedDBCallbacks
    : public base::RefCounted<IndexedDBCallbacks> {
 public:
  // Simple payload responses
  static scoped_refptr<IndexedDBCallbacks> Create(
      IndexedDBDispatcherHost* dispatcher_host,
      int32 ipc_thread_id,
      int32 ipc_callbacks_id) {
    return make_scoped_refptr(new IndexedDBCallbacks(
        dispatcher_host, ipc_thread_id, ipc_callbacks_id));
  }

  // IndexedDBCursor responses
  static scoped_refptr<IndexedDBCallbacks> Create(
      IndexedDBDispatcherHost* dispatcher_host,
      int32 ipc_thread_id,
      int32 ipc_callbacks_id,
      int32 ipc_cursor_id) {
    return make_scoped_refptr(new IndexedDBCallbacks(
        dispatcher_host, ipc_thread_id, ipc_callbacks_id, ipc_cursor_id));
  }
  // IndexedDBDatabase responses
  static scoped_refptr<IndexedDBCallbacks> Create(
      IndexedDBDispatcherHost* dispatcher_host,
      int32 ipc_thread_id,
      int32 ipc_callbacks_id,
      int32 ipc_database_callbacks_id,
      int64 host_transaction_id,
      const GURL& origin_url) {
    return make_scoped_refptr(new IndexedDBCallbacks(dispatcher_host,
                                                     ipc_thread_id,
                                                     ipc_callbacks_id,
                                                     ipc_database_callbacks_id,
                                                     host_transaction_id,
                                                     origin_url));
  }

  virtual void OnError(const IndexedDBDatabaseError& error);

  // IndexedDBFactory::GetDatabaseNames
  virtual void OnSuccess(const std::vector<string16>& string);

  // IndexedDBFactory::Open / DeleteDatabase
  virtual void OnBlocked(int64 existing_version);

  // IndexedDBFactory::Open
  virtual void OnUpgradeNeeded(
      int64 old_version,
      scoped_refptr<IndexedDBDatabase> db,
      const content::IndexedDBDatabaseMetadata& metadata,
      WebKit::WebIDBCallbacks::DataLoss data_loss);
  virtual void OnSuccess(scoped_refptr<IndexedDBDatabase> db,
                         const content::IndexedDBDatabaseMetadata& metadata);
  void SetDatabaseCallbacks(
      scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks);

  // IndexedDBDatabase::OpenCursor
  virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
                         const IndexedDBKey& key,
                         const IndexedDBKey& primary_key,
                         std::vector<char>* value);

  // IndexedDBCursor::Continue / Advance
  virtual void OnSuccess(const IndexedDBKey& key,
                         const IndexedDBKey& primary_key,
                         std::vector<char>* value);

  // IndexedDBCursor::PrefetchContinue
  virtual void OnSuccessWithPrefetch(
      const std::vector<IndexedDBKey>& keys,
      const std::vector<IndexedDBKey>& primary_keys,
      const std::vector<std::vector<char> >& values);

  // IndexedDBDatabase::Get (with key injection)
  virtual void OnSuccess(std::vector<char>* data,
                         const IndexedDBKey& key,
                         const IndexedDBKeyPath& key_path);

  // IndexedDBDatabase::Get
  virtual void OnSuccess(std::vector<char>* value);

  // IndexedDBDatabase::Put / IndexedDBCursor::Update
  virtual void OnSuccess(const IndexedDBKey& value);

  // IndexedDBDatabase::Count
  virtual void OnSuccess(int64 value);

  // IndexedDBDatabase::Delete
  // IndexedDBCursor::Continue / Advance (when complete)
  virtual void OnSuccess();

 protected:
  virtual ~IndexedDBCallbacks();

  // Simple payload responses
  IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
                     int32 ipc_thread_id,
                     int32 ipc_callbacks_id);

  // IndexedDBCursor responses
  IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
                     int32 ipc_thread_id,
                     int32 ipc_callbacks_id,
                     int32 ipc_cursor_id);

  // IndexedDBDatabase responses
  IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
                     int32 ipc_thread_id,
                     int32 ipc_callbacks_id,
                     int32 ipc_database_callbacks_id,
                     int64 host_transaction_id,
                     const GURL& origin_url);

 private:
  friend class base::RefCounted<IndexedDBCallbacks>;

  scoped_ptr<WebIDBDatabaseImpl> web_database_impl_;
  scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks_;
  bool did_complete_;
  bool did_create_proxy_;

  // Originally from IndexedDBCallbacks:
  scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
  int32 ipc_callbacks_id_;
  int32 ipc_thread_id_;

  // IndexedDBCursor callbacks ------------------------
  int32 ipc_cursor_id_;

  // IndexedDBDatabase callbacks ------------------------
  int64 host_transaction_id_;
  GURL origin_url_;
  int32 ipc_database_id_;
  int32 ipc_database_callbacks_id_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_