Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / indexed_db / indexed_db_callbacks.h
blob4b8a2177a8c7c31f7fc729912ee1fe45d1bb684b
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "content/browser/indexed_db/indexed_db_database_error.h"
17 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
18 #include "content/common/indexed_db/indexed_db_key.h"
19 #include "content/common/indexed_db/indexed_db_key_path.h"
20 #include "url/gurl.h"
22 namespace content {
23 class IndexedDBBlobInfo;
24 class IndexedDBConnection;
25 class IndexedDBCursor;
26 class IndexedDBDatabase;
27 class IndexedDBDatabaseCallbacks;
28 struct IndexedDBDatabaseMetadata;
29 struct IndexedDBValue;
31 class CONTENT_EXPORT IndexedDBCallbacks
32 : public base::RefCounted<IndexedDBCallbacks> {
33 public:
34 // Simple payload responses
35 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
36 int32 ipc_thread_id,
37 int32 ipc_callbacks_id);
39 // IndexedDBCursor responses
40 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
41 int32 ipc_thread_id,
42 int32 ipc_callbacks_id,
43 int32 ipc_cursor_id);
45 // IndexedDBDatabase responses
46 IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
47 int32 ipc_thread_id,
48 int32 ipc_callbacks_id,
49 int32 ipc_database_callbacks_id,
50 int64 host_transaction_id,
51 const GURL& origin_url);
53 virtual void OnError(const IndexedDBDatabaseError& error);
55 // IndexedDBFactory::GetDatabaseNames
56 virtual void OnSuccess(const std::vector<base::string16>& string);
58 // IndexedDBFactory::Open / DeleteDatabase
59 virtual void OnBlocked(int64 existing_version);
61 // IndexedDBFactory::Open
62 virtual void OnDataLoss(blink::WebIDBDataLoss data_loss,
63 std::string data_loss_message);
64 virtual void OnUpgradeNeeded(
65 int64 old_version,
66 scoped_ptr<IndexedDBConnection> connection,
67 const content::IndexedDBDatabaseMetadata& metadata);
68 virtual void OnSuccess(scoped_ptr<IndexedDBConnection> connection,
69 const content::IndexedDBDatabaseMetadata& metadata);
71 // IndexedDBDatabase::OpenCursor
72 virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
73 const IndexedDBKey& key,
74 const IndexedDBKey& primary_key,
75 IndexedDBValue* value);
77 // IndexedDBCursor::Continue / Advance
78 virtual void OnSuccess(const IndexedDBKey& key,
79 const IndexedDBKey& primary_key,
80 IndexedDBValue* value);
82 // IndexedDBCursor::PrefetchContinue
83 virtual void OnSuccessWithPrefetch(
84 const std::vector<IndexedDBKey>& keys,
85 const std::vector<IndexedDBKey>& primary_keys,
86 std::vector<IndexedDBValue>* values);
88 // IndexedDBDatabase::Get (with key injection)
89 virtual void OnSuccess(IndexedDBValue* value,
90 const IndexedDBKey& key,
91 const IndexedDBKeyPath& key_path);
93 // IndexedDBDatabase::Get
94 virtual void OnSuccess(IndexedDBValue* value);
96 // IndexedDBDatabase::Put / IndexedDBCursor::Update
97 virtual void OnSuccess(const IndexedDBKey& key);
99 // IndexedDBDatabase::Count
100 // IndexedDBFactory::DeleteDatabase
101 virtual void OnSuccess(int64 value);
103 // IndexedDBDatabase::Delete
104 // IndexedDBCursor::Continue / Advance (when complete)
105 virtual void OnSuccess();
107 blink::WebIDBDataLoss data_loss() const { return data_loss_; }
109 void SetConnectionOpenStartTime(const base::TimeTicks& start_time);
111 protected:
112 virtual ~IndexedDBCallbacks();
114 private:
115 void RegisterBlobsAndSend(const std::vector<IndexedDBBlobInfo>& blob_info,
116 const base::Closure& callback);
118 friend class base::RefCounted<IndexedDBCallbacks>;
120 // Originally from IndexedDBCallbacks:
121 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
122 int32 ipc_callbacks_id_;
123 int32 ipc_thread_id_;
125 // IndexedDBCursor callbacks ------------------------
126 int32 ipc_cursor_id_;
128 // IndexedDBDatabase callbacks ------------------------
129 int64 host_transaction_id_;
130 GURL origin_url_;
131 int32 ipc_database_id_;
132 int32 ipc_database_callbacks_id_;
134 // Stored in OnDataLoss, merged with OnUpgradeNeeded response.
135 blink::WebIDBDataLoss data_loss_;
136 std::string data_loss_message_;
138 // The "blocked" event should be sent at most once per request.
139 bool sent_blocked_;
140 base::TimeTicks connection_open_start_time_;
141 DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacks);
144 } // namespace content
146 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_