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 | |
44 int32 CurrentWorkerId() { | 41 int32 CurrentWorkerId() { |
45 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 42 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
46 } | 43 } |
47 | 44 |
48 } // unnamed namespace | 45 } // unnamed namespace |
49 | 46 |
50 const size_t kMaxIDBValueSizeInBytes = 64 * 1024 * 1024; | 47 const size_t kMaxIDBValueSizeInBytes = 64 * 1024 * 1024; |
51 | 48 |
52 IndexedDBDispatcher::IndexedDBDispatcher() { | 49 IndexedDBDispatcher::IndexedDBDispatcher() { |
53 g_idb_dispatcher_tls.Pointer()->Set(this); | 50 g_idb_dispatcher_tls.Pointer()->Set(this); |
54 } | 51 } |
55 | 52 |
56 IndexedDBDispatcher::~IndexedDBDispatcher() { | 53 IndexedDBDispatcher::~IndexedDBDispatcher() { |
57 g_idb_dispatcher_tls.Pointer()->Set(HAS_BEEN_DELETED); | 54 g_idb_dispatcher_tls.Pointer()->Set(NULL); |
58 } | 55 } |
59 | 56 |
60 IndexedDBDispatcher* IndexedDBDispatcher::ThreadSpecificInstance() { | 57 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 } | |
65 if (g_idb_dispatcher_tls.Pointer()->Get()) | 58 if (g_idb_dispatcher_tls.Pointer()->Get()) |
66 return g_idb_dispatcher_tls.Pointer()->Get(); | 59 return g_idb_dispatcher_tls.Pointer()->Get(); |
67 | 60 |
68 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher; | 61 IndexedDBDispatcher* dispatcher = new IndexedDBDispatcher; |
69 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) | 62 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) |
70 webkit_glue::WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); | 63 webkit_glue::WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); |
71 return dispatcher; | 64 return dispatcher; |
72 } | 65 } |
73 | 66 |
74 void IndexedDBDispatcher::OnWorkerRunLoopStopped() { | 67 void IndexedDBDispatcher::OnWorkerRunLoopStopped() { |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 } | 706 } |
714 | 707 |
715 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { | 708 void IndexedDBDispatcher::ResetCursorPrefetchCaches(int32 exception_cursor_id) { |
716 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; | 709 typedef std::map<int32, RendererWebIDBCursorImpl*>::iterator Iterator; |
717 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { | 710 for (Iterator i = cursors_.begin(); i != cursors_.end(); ++i) { |
718 if (i->first == exception_cursor_id) | 711 if (i->first == exception_cursor_id) |
719 continue; | 712 continue; |
720 i->second->ResetPrefetchCache(); | 713 i->second->ResetPrefetchCache(); |
721 } | 714 } |
722 } | 715 } |
OLD | NEW |