| 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 #include "content/common/indexed_db/indexed_db_dispatcher.h" | 5 #include "content/common/indexed_db/indexed_db_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
| 9 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
| 10 #include "content/common/indexed_db/indexed_db_messages.h" | 10 #include "content/common/indexed_db/indexed_db_messages.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using WebKit::WebIDBDatabaseError; | 31 using WebKit::WebIDBDatabaseError; |
| 32 using WebKit::WebIDBTransaction; | 32 using WebKit::WebIDBTransaction; |
| 33 using WebKit::WebIDBTransactionCallbacks; | 33 using WebKit::WebIDBTransactionCallbacks; |
| 34 using webkit_glue::WorkerTaskRunner; | 34 using webkit_glue::WorkerTaskRunner; |
| 35 | 35 |
| 36 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky | 36 static base::LazyInstance<ThreadLocalPointer<IndexedDBDispatcher> >::Leaky |
| 37 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 37 g_idb_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 IndexedDBDispatcher* const HAS_BEEN_DELETED = |
| 42 reinterpret_cast<IndexedDBDispatcher*>(0x1); |
| 43 |
| 41 int32 CurrentWorkerId() { | 44 int32 CurrentWorkerId() { |
| 42 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 45 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 43 } | 46 } |
| 44 | 47 |
| 45 } // unnamed namespace | 48 } // unnamed namespace |
| 46 | 49 |
| 47 const size_t kMaxIDBValueSizeInBytes = 64 * 1024 * 1024; | 50 const size_t kMaxIDBValueSizeInBytes = 64 * 1024 * 1024; |
| 48 | 51 |
| 49 IndexedDBDispatcher::IndexedDBDispatcher() { | 52 IndexedDBDispatcher::IndexedDBDispatcher() { |
| 50 g_idb_dispatcher_tls.Pointer()->Set(this); | 53 g_idb_dispatcher_tls.Pointer()->Set(this); |
| 51 } | 54 } |
| 52 | 55 |
| 53 IndexedDBDispatcher::~IndexedDBDispatcher() { | 56 IndexedDBDispatcher::~IndexedDBDispatcher() { |
| 54 g_idb_dispatcher_tls.Pointer()->Set(NULL); | 57 g_idb_dispatcher_tls.Pointer()->Set(HAS_BEEN_DELETED); |
| 55 } | 58 } |
| 56 | 59 |
| 57 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() { | 60 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() { |
| 61 if (g_idb_dispatcher_tls.Pointer()->Get() == HAS_BEEN_DELETED) { |
| 62 NOTREACHED() << "Re-instantiating TLS IndexedDBDispatcher."; |
| 63 g_idb_dispatcher_tls.Pointer()->Set(NULL); |
| 64 } |
| 58 if (g_idb_dispatcher_tls.Pointer()->Get()) | 65 if (g_idb_dispatcher_tls.Pointer()->Get()) |
| 59 return g_idb_dispatcher_tls.Pointer()->Get(); | 66 return g_idb_dispatcher_tls.Pointer()->Get(); |
| 60 | 67 |
| 61 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher; | 68 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher; |
| 62 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) | 69 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) |
| 63 webkit_glue::WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); | 70 webkit_glue::WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); |
| 64 return dispatcher; | 71 return dispatcher; |
| 65 } | 72 } |
| 66 | 73 |
| 67 void IndexedDBDispatcher::OnWorkerRunLoopStopped() { | 74 void IndexedDBDispatcher::OnWorkerRunLoopStopped() { |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 } | 713 } |
| 707 | 714 |
| 708 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { | 715 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { |
| 709 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; | 716 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; |
| 710 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 717 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
| 711 if (i->first == exception_cursor_id) | 718 if (i->first == exception_cursor_id) |
| 712 continue; | 719 continue; |
| 713 i->second->ResetPrefetchCache(); | 720 i->second->ResetPrefetchCache(); |
| 714 } | 721 } |
| 715 } | 722 } |
| OLD | NEW |