OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "content/child/indexed_db/webidbfactory_impl.h" | 5 #include "content/child/indexed_db/webidbfactory_impl.h" |
6 | 6 |
7 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 7 #include "content/child/child_thread_impl.h" |
8 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" | |
9 #include "content/child/indexed_db/indexed_db_database_callbacks_impl.h" | |
8 #include "content/child/storage_util.h" | 10 #include "content/child/storage_util.h" |
9 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
12 #include "content/public/child/worker_thread.h" | |
13 #include "ipc/ipc_sync_channel.h" | |
10 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 14 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
11 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
12 | 16 |
13 using blink::WebIDBCallbacks; | 17 using blink::WebIDBCallbacks; |
14 using blink::WebIDBDatabase; | 18 using blink::WebIDBDatabase; |
15 using blink::WebIDBDatabaseCallbacks; | 19 using blink::WebIDBDatabaseCallbacks; |
16 using blink::WebSecurityOrigin; | 20 using blink::WebSecurityOrigin; |
17 using blink::WebString; | 21 using blink::WebString; |
18 | 22 |
19 namespace content { | 23 namespace content { |
20 | 24 |
21 WebIDBFactoryImpl::WebIDBFactoryImpl(ThreadSafeSender* thread_safe_sender) | 25 class WebIDBFactoryImpl::IOThreadHelper { |
22 : thread_safe_sender_(thread_safe_sender) {} | 26 public: |
27 IOThreadHelper(scoped_refptr<IPC::SyncMessageFilter> sync_message_filter); | |
28 ~IOThreadHelper(); | |
23 | 29 |
24 WebIDBFactoryImpl::~WebIDBFactoryImpl() {} | 30 void EnsureServiceConnection(); |
31 void GetDatabaseNames(std::unique_ptr<IndexedDBCallbacksImpl> callbacks, | |
32 const url::Origin& origin); | |
33 void Open(int32_t worker_thread, | |
34 const base::string16& name, | |
35 int64_t version, | |
36 int64_t transaction_id, | |
37 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, | |
38 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks, | |
39 const url::Origin& origin); | |
40 void DeleteDatabase(const base::string16& name, | |
41 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, | |
42 const url::Origin& origin); | |
43 | |
44 private: | |
45 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_; | |
46 indexed_db::mojom::FactoryAssociatedPtr service_; | |
47 }; | |
48 | |
49 WebIDBFactoryImpl::WebIDBFactoryImpl( | |
50 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, | |
51 scoped_refptr<ThreadSafeSender> thread_safe_sender, | |
52 scoped_refptr<base::SingleThreadTaskRunner> io_runner) | |
53 : thread_safe_sender_(std::move(thread_safe_sender)), | |
54 io_runner_(std::move(io_runner)) { | |
55 helper_ = new IOThreadHelper(std::move(sync_message_filter)); | |
56 } | |
57 | |
58 WebIDBFactoryImpl::~WebIDBFactoryImpl() { | |
59 io_runner_->DeleteSoon(FROM_HERE, helper_); | |
60 } | |
25 | 61 |
26 void WebIDBFactoryImpl::getDatabaseNames(WebIDBCallbacks* callbacks, | 62 void WebIDBFactoryImpl::getDatabaseNames(WebIDBCallbacks* callbacks, |
27 const WebSecurityOrigin& origin) { | 63 const WebSecurityOrigin& origin) { |
28 IndexedDBDispatcher* dispatcher = | 64 auto callbacks_impl = |
29 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 65 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_); |
30 dispatcher->RequestIDBFactoryGetDatabaseNames(callbacks, origin); | 66 io_runner_->PostTask( |
67 FROM_HERE, | |
68 base::Bind(&IOThreadHelper::GetDatabaseNames, base::Unretained(helper_), | |
69 base::Passed(&callbacks_impl), url::Origin(origin))); | |
31 } | 70 } |
32 | 71 |
33 void WebIDBFactoryImpl::open(const WebString& name, | 72 void WebIDBFactoryImpl::open(const WebString& name, |
34 long long version, | 73 long long version, |
35 long long transaction_id, | 74 long long transaction_id, |
36 WebIDBCallbacks* callbacks, | 75 WebIDBCallbacks* callbacks, |
37 WebIDBDatabaseCallbacks* database_callbacks, | 76 WebIDBDatabaseCallbacks* database_callbacks, |
38 const WebSecurityOrigin& origin) { | 77 const WebSecurityOrigin& origin) { |
39 IndexedDBDispatcher* dispatcher = | 78 auto callbacks_impl = |
40 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 79 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_); |
41 | 80 auto database_callbacks_impl = |
42 dispatcher->RequestIDBFactoryOpen(name, version, transaction_id, callbacks, | 81 base::MakeUnique<IndexedDBDatabaseCallbacksImpl>(database_callbacks); |
43 database_callbacks, origin); | 82 io_runner_->PostTask( |
83 FROM_HERE, | |
84 base::Bind(&IOThreadHelper::Open, base::Unretained(helper_), | |
85 WorkerThread::GetCurrentId(), base::string16(name), version, | |
86 transaction_id, base::Passed(&callbacks_impl), | |
87 base::Passed(&database_callbacks_impl), url::Origin(origin))); | |
44 } | 88 } |
45 | 89 |
46 void WebIDBFactoryImpl::deleteDatabase(const WebString& name, | 90 void WebIDBFactoryImpl::deleteDatabase(const WebString& name, |
47 WebIDBCallbacks* callbacks, | 91 WebIDBCallbacks* callbacks, |
48 const WebSecurityOrigin& origin) { | 92 const WebSecurityOrigin& origin) { |
49 IndexedDBDispatcher* dispatcher = | 93 auto callbacks_impl = |
50 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); | 94 base::MakeUnique<IndexedDBCallbacksImpl>(callbacks, thread_safe_sender_); |
51 dispatcher->RequestIDBFactoryDeleteDatabase(name, callbacks, origin); | 95 io_runner_->PostTask( |
96 FROM_HERE, | |
97 base::Bind(&IOThreadHelper::DeleteDatabase, base::Unretained(helper_), | |
98 base::string16(name), base::Passed(&callbacks_impl), | |
99 url::Origin(origin))); | |
100 } | |
101 | |
102 WebIDBFactoryImpl::IOThreadHelper::IOThreadHelper( | |
103 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter) | |
104 : sync_message_filter_(std::move(sync_message_filter)) {} | |
105 | |
106 WebIDBFactoryImpl::IOThreadHelper::~IOThreadHelper() {} | |
107 | |
108 void WebIDBFactoryImpl::IOThreadHelper::EnsureServiceConnection() { | |
Ken Rockot(use gerrit already)
2016/09/28 20:06:44
nit: I think it'd just be cleaner to have an acces
Reilly Grant (use Gerrit)
2016/09/29 06:44:50
I considered that but since I usually need both se
Ken Rockot(use gerrit already)
2016/09/29 22:37:50
Fair enough. You could of course have the lazy get
Reilly Grant (use Gerrit)
2016/09/30 07:24:20
Oh look! Now there's a StrongAssociatedBinding.
| |
109 if (!service_) | |
110 sync_message_filter_->GetRemoteAssociatedInterface(&service_); | |
111 } | |
112 | |
113 void WebIDBFactoryImpl::IOThreadHelper::GetDatabaseNames( | |
114 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, | |
115 const url::Origin& origin) { | |
116 EnsureServiceConnection(); | |
117 | |
118 indexed_db::mojom::CallbacksAssociatedPtrInfo mojo_callbacks; | |
119 callbacks.release()->Bind(&mojo_callbacks, service_.associated_group()); | |
120 | |
121 service_->GetDatabaseNames(std::move(mojo_callbacks), origin); | |
122 } | |
123 | |
124 void WebIDBFactoryImpl::IOThreadHelper::Open( | |
125 int32_t worker_thread, | |
126 const base::string16& name, | |
127 int64_t version, | |
128 int64_t transaction_id, | |
129 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, | |
130 std::unique_ptr<IndexedDBDatabaseCallbacksImpl> database_callbacks, | |
131 const url::Origin& origin) { | |
132 EnsureServiceConnection(); | |
133 | |
134 indexed_db::mojom::CallbacksAssociatedPtrInfo mojo_callbacks; | |
135 callbacks.release()->Bind(&mojo_callbacks, service_.associated_group()); | |
136 indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo mojo_database_callbacks; | |
137 database_callbacks.release()->Bind(&mojo_database_callbacks, | |
138 service_.associated_group()); | |
139 | |
140 service_->Open(worker_thread, std::move(mojo_callbacks), | |
141 std::move(mojo_database_callbacks), origin, name, version, | |
142 transaction_id); | |
143 } | |
144 | |
145 void WebIDBFactoryImpl::IOThreadHelper::DeleteDatabase( | |
146 const base::string16& name, | |
147 std::unique_ptr<IndexedDBCallbacksImpl> callbacks, | |
148 const url::Origin& origin) { | |
149 EnsureServiceConnection(); | |
150 | |
151 indexed_db::mojom::CallbacksAssociatedPtrInfo mojo_callbacks; | |
152 callbacks.release()->Bind(&mojo_callbacks, service_.associated_group()); | |
153 | |
154 service_->DeleteDatabase(std::move(mojo_callbacks), origin, name); | |
52 } | 155 } |
53 | 156 |
54 } // namespace content | 157 } // namespace content |
OLD | NEW |