OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
19 #include "content/browser/indexed_db/indexed_db_database_error.h" | 19 #include "content/browser/indexed_db/indexed_db_database_error.h" |
20 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 20 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
21 #include "content/common/indexed_db/indexed_db.mojom.h" | 21 #include "content/common/indexed_db/indexed_db.mojom.h" |
22 #include "content/common/indexed_db/indexed_db_key.h" | 22 #include "content/common/indexed_db/indexed_db_key.h" |
23 #include "content/common/indexed_db/indexed_db_key_path.h" | 23 #include "content/common/indexed_db/indexed_db_key_path.h" |
24 #include "url/origin.h" | 24 #include "url/origin.h" |
25 | 25 |
| 26 namespace base { |
| 27 class SequencedTaskRunner; |
| 28 } |
| 29 |
26 namespace content { | 30 namespace content { |
27 class IndexedDBConnection; | 31 class IndexedDBConnection; |
28 class IndexedDBCursor; | 32 class IndexedDBCursor; |
29 class IndexedDBDatabase; | 33 class IndexedDBDatabase; |
30 struct IndexedDBDataLossInfo; | 34 struct IndexedDBDataLossInfo; |
31 struct IndexedDBDatabaseMetadata; | 35 struct IndexedDBDatabaseMetadata; |
32 struct IndexedDBReturnValue; | 36 struct IndexedDBReturnValue; |
33 struct IndexedDBValue; | 37 struct IndexedDBValue; |
34 | 38 |
| 39 // Expected to be constructed on IO thread and called/deleted from IDB thread. |
35 class CONTENT_EXPORT IndexedDBCallbacks | 40 class CONTENT_EXPORT IndexedDBCallbacks |
36 : public base::RefCounted<IndexedDBCallbacks> { | 41 : public base::RefCounted<IndexedDBCallbacks> { |
37 public: | 42 public: |
38 // Destructively converts an IndexedDBValue to a Mojo Value. | 43 // Destructively converts an IndexedDBValue to a Mojo Value. |
39 static ::indexed_db::mojom::ValuePtr ConvertAndEraseValue( | 44 static ::indexed_db::mojom::ValuePtr ConvertAndEraseValue( |
40 IndexedDBValue* value); | 45 IndexedDBValue* value); |
41 | 46 |
42 IndexedDBCallbacks( | 47 IndexedDBCallbacks( |
43 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 48 base::WeakPtr<IndexedDBDispatcherHost> dispatcher_host, |
44 const url::Origin& origin, | 49 const url::Origin& origin, |
45 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info); | 50 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 51 scoped_refptr<base::SequencedTaskRunner> idb_runner); |
46 | 52 |
47 virtual void OnError(const IndexedDBDatabaseError& error); | 53 virtual void OnError(const IndexedDBDatabaseError& error); |
48 | 54 |
49 // IndexedDBFactory::GetDatabaseNames | 55 // IndexedDBFactory::GetDatabaseNames |
50 virtual void OnSuccess(const std::vector<base::string16>& string); | 56 virtual void OnSuccess(const std::vector<base::string16>& string); |
51 | 57 |
52 // IndexedDBFactory::Open / DeleteDatabase | 58 // IndexedDBFactory::Open / DeleteDatabase |
53 virtual void OnBlocked(int64_t existing_version); | 59 virtual void OnBlocked(int64_t existing_version); |
54 | 60 |
55 // IndexedDBFactory::Open | 61 // IndexedDBFactory::Open |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void SetConnectionOpenStartTime(const base::TimeTicks& start_time); | 105 void SetConnectionOpenStartTime(const base::TimeTicks& start_time); |
100 | 106 |
101 protected: | 107 protected: |
102 virtual ~IndexedDBCallbacks(); | 108 virtual ~IndexedDBCallbacks(); |
103 | 109 |
104 private: | 110 private: |
105 friend class base::RefCounted<IndexedDBCallbacks>; | 111 friend class base::RefCounted<IndexedDBCallbacks>; |
106 | 112 |
107 class IOThreadHelper; | 113 class IOThreadHelper; |
108 | 114 |
109 // Originally from IndexedDBCallbacks: | 115 // Stores if this callbacks object is complete and should not be called again. |
110 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 116 bool complete_ = false; |
111 | 117 |
112 // IndexedDBDatabase callbacks ------------------------ | 118 // Depending on whether the database needs upgrading, we create connections in |
113 url::Origin origin_; | 119 // different spots. This stores if we've already created the connection so |
114 bool database_sent_ = false; | 120 // OnSuccess(Connection) doesn't create an extra one. |
| 121 bool connection_created_ = false; |
115 | 122 |
116 // Used to assert that OnSuccess is only called if there was no data loss. | 123 // Used to assert that OnSuccess is only called if there was no data loss. |
117 blink::WebIDBDataLoss data_loss_; | 124 blink::WebIDBDataLoss data_loss_; |
118 | 125 |
119 // The "blocked" event should be sent at most once per request. | 126 // The "blocked" event should be sent at most once per request. |
120 bool sent_blocked_; | 127 bool sent_blocked_ = false; |
121 base::TimeTicks connection_open_start_time_; | 128 base::TimeTicks connection_open_start_time_; |
122 | 129 |
123 std::unique_ptr<IOThreadHelper, BrowserThread::DeleteOnIOThread> io_helper_; | 130 std::unique_ptr<IOThreadHelper, BrowserThread::DeleteOnIOThread> io_helper_; |
124 base::ThreadChecker thread_checker_; | 131 base::ThreadChecker thread_checker_; |
125 | 132 |
126 DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacks); | 133 DISALLOW_COPY_AND_ASSIGN(IndexedDBCallbacks); |
127 }; | 134 }; |
128 | 135 |
129 } // namespace content | 136 } // namespace content |
130 | 137 |
131 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ | 138 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CALLBACKS_H_ |
OLD | NEW |