| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "modules/indexeddb/IndexedDBClient.h" | 5 #include "modules/indexeddb/IndexedDBClient.h" |
| 6 #include "wtf/Atomics.h" | 6 |
| 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/ExecutionContext.h" |
| 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/workers/WorkerClients.h" |
| 11 #include "core/workers/WorkerGlobalScope.h" |
| 7 | 12 |
| 8 namespace blink { | 13 namespace blink { |
| 9 | 14 |
| 10 static void* idbClientCreateFunction = nullptr; | 15 IndexedDBClient::IndexedDBClient() |
| 11 | |
| 12 void setIndexedDBClientCreateFunction(CreateIndexedDBClient createFunction) | |
| 13 { | 16 { |
| 14 // See web/IndexedDBClientImpl.h comment for some context. As the initializa
tion | |
| 15 // of this IndexedDB client constructor now happens as context is set up for | |
| 16 // threads, it is possible that setIndexedDBClientCreateFunction() will be | |
| 17 // called more than once. Hence update atomicity is needed. | |
| 18 #if ENABLE(ASSERT) | |
| 19 CreateIndexedDBClient* currentFunction = reinterpret_cast<CreateIndexedDBCli
ent*>(acquireLoad(&idbClientCreateFunction)); | |
| 20 ASSERT(!currentFunction || currentFunction == createFunction); | |
| 21 #endif | |
| 22 releaseStore(&idbClientCreateFunction, reinterpret_cast<void*>(createFunctio
n)); | |
| 23 } | 17 } |
| 24 | 18 |
| 25 IndexedDBClient* IndexedDBClient::create() | 19 IndexedDBClient* IndexedDBClient::from(ExecutionContext* context) |
| 26 { | 20 { |
| 27 CreateIndexedDBClient* createFunction = reinterpret_cast<CreateIndexedDBClie
nt*>(acquireLoad(&idbClientCreateFunction)); | 21 if (context->isDocument()) |
| 28 ASSERT(createFunction); | 22 return static_cast<IndexedDBClient*>(Supplement<LocalFrame>::from(toDocu
ment(*context).frame(), supplementName())); |
| 29 // There's no reason why we need to allocate a new proxy each time, but | 23 |
| 30 // there's also no strong reason not to. | 24 WorkerClients* clients = toWorkerGlobalScope(*context).clients(); |
| 31 return createFunction(); | 25 ASSERT(clients); |
| 26 return static_cast<IndexedDBClient*>(Supplement<WorkerClients>::from(clients
, supplementName())); |
| 27 } |
| 28 |
| 29 const char* IndexedDBClient::supplementName() |
| 30 { |
| 31 return "IndexedDBClient"; |
| 32 } |
| 33 |
| 34 void provideIndexedDBClientTo(LocalFrame& frame, IndexedDBClient* client) |
| 35 { |
| 36 frame.provideSupplement(IndexedDBClient::supplementName(), client); |
| 37 } |
| 38 |
| 39 void provideIndexedDBClientToWorker(WorkerClients* clients, IndexedDBClient* cli
ent) |
| 40 { |
| 41 clients->provideSupplement(IndexedDBClient::supplementName(), client); |
| 32 } | 42 } |
| 33 | 43 |
| 34 } // namespace blink | 44 } // namespace blink |
| OLD | NEW |