Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / content / browser / indexed_db / indexed_db_callbacks.h
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.
4
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_
7
8 #include <string>
9 #include <vector>
10
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"
21
22 namespace content {
23 class IndexedDBConnection;
24 class IndexedDBCursor;
25 class IndexedDBDatabase;
26 class IndexedDBDatabaseCallbacks;
27 struct IndexedDBDatabaseMetadata;
28 struct IndexedDBValue;
29
30 class CONTENT_EXPORT IndexedDBCallbacks
31     : public base::RefCounted<IndexedDBCallbacks> {
32  public:
33   // Simple payload responses
34   IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
35                      int32 ipc_thread_id,
36                      int32 ipc_callbacks_id);
37
38   // IndexedDBCursor responses
39   IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
40                      int32 ipc_thread_id,
41                      int32 ipc_callbacks_id,
42                      int32 ipc_cursor_id);
43
44   // IndexedDBDatabase responses
45   IndexedDBCallbacks(IndexedDBDispatcherHost* dispatcher_host,
46                      int32 ipc_thread_id,
47                      int32 ipc_callbacks_id,
48                      int32 ipc_database_callbacks_id,
49                      int64 host_transaction_id,
50                      const GURL& origin_url);
51
52   virtual void OnError(const IndexedDBDatabaseError& error);
53
54   // IndexedDBFactory::GetDatabaseNames
55   virtual void OnSuccess(const std::vector<base::string16>& string);
56
57   // IndexedDBFactory::Open / DeleteDatabase
58   virtual void OnBlocked(int64 existing_version);
59
60   // IndexedDBFactory::Open
61   virtual void OnDataLoss(blink::WebIDBDataLoss data_loss,
62                           std::string data_loss_message);
63   virtual void OnUpgradeNeeded(
64       int64 old_version,
65       scoped_ptr<IndexedDBConnection> connection,
66       const content::IndexedDBDatabaseMetadata& metadata);
67   virtual void OnSuccess(scoped_ptr<IndexedDBConnection> connection,
68                          const content::IndexedDBDatabaseMetadata& metadata);
69
70   // IndexedDBDatabase::OpenCursor
71   virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
72                          const IndexedDBKey& key,
73                          const IndexedDBKey& primary_key,
74                          IndexedDBValue* value);
75
76   // IndexedDBCursor::Continue / Advance
77   virtual void OnSuccess(const IndexedDBKey& key,
78                          const IndexedDBKey& primary_key,
79                          IndexedDBValue* value);
80
81   // IndexedDBCursor::PrefetchContinue
82   virtual void OnSuccessWithPrefetch(
83       const std::vector<IndexedDBKey>& keys,
84       const std::vector<IndexedDBKey>& primary_keys,
85       const std::vector<IndexedDBValue>& values);
86
87   // IndexedDBDatabase::Get (with key injection)
88   virtual void OnSuccess(IndexedDBValue* value,
89                          const IndexedDBKey& key,
90                          const IndexedDBKeyPath& key_path);
91
92   // IndexedDBDatabase::Get
93   virtual void OnSuccess(IndexedDBValue* value);
94
95   // IndexedDBDatabase::Put / IndexedDBCursor::Update
96   virtual void OnSuccess(const IndexedDBKey& key);
97
98   // IndexedDBDatabase::Count
99   virtual void OnSuccess(int64 value);
100
101   // IndexedDBDatabase::Delete
102   // IndexedDBCursor::Continue / Advance (when complete)
103   virtual void OnSuccess();
104
105   blink::WebIDBDataLoss data_loss() const { return data_loss_; }
106
107  protected:
108   virtual ~IndexedDBCallbacks();
109
110  private:
111   friend class base::RefCounted<IndexedDBCallbacks>;
112
113   // Originally from IndexedDBCallbacks:
114   scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
115   int32 ipc_callbacks_id_;
116   int32 ipc_thread_id_;
117
118   // IndexedDBCursor callbacks ------------------------
119   int32 ipc_cursor_id_;
120
121   // IndexedDBDatabase callbacks ------------------------
122   int64 host_transaction_id_;
123   GURL origin_url_;
124   int32 ipc_database_id_;
125   int32 ipc_database_callbacks_id_;
126
127   // Stored in OnDataLoss, merged with OnUpgradeNeeded response.
128   blink::WebIDBDataLoss data_loss_;
129   std::string data_loss_message_;
130 };
131
132 }  // namespace content
133
134 #endif  // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_