OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "modules/webdatabase/SQLTransactionCoordinator.h" | 34 #include "modules/webdatabase/SQLTransactionCoordinator.h" |
35 #include "platform/Logging.h" | 35 #include "platform/Logging.h" |
36 #include "platform/ThreadSafeFunctional.h" | 36 #include "platform/ThreadSafeFunctional.h" |
37 #include "platform/WebThreadSupportingGC.h" | 37 #include "platform/WebThreadSupportingGC.h" |
38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 DatabaseThread::DatabaseThread() | 42 DatabaseThread::DatabaseThread() |
43 : m_transactionClient(adoptPtr(new SQLTransactionClient())) | 43 : m_transactionClient(adoptPtr(new SQLTransactionClient())) |
44 , m_transactionCoordinator(new SQLTransactionCoordinator()) | |
45 , m_cleanupSync(nullptr) | 44 , m_cleanupSync(nullptr) |
46 , m_terminationRequested(false) | 45 , m_terminationRequested(false) |
47 { | 46 { |
| 47 DCHECK(isMainThread()); |
48 } | 48 } |
49 | 49 |
50 DatabaseThread::~DatabaseThread() | 50 DatabaseThread::~DatabaseThread() |
51 { | 51 { |
52 ASSERT(m_openDatabaseSet.isEmpty()); | 52 ASSERT(m_openDatabaseSet.isEmpty()); |
53 ASSERT(!m_thread); | 53 ASSERT(!m_thread); |
54 } | 54 } |
55 | 55 |
56 DEFINE_TRACE(DatabaseThread) | 56 DEFINE_TRACE(DatabaseThread) |
57 { | 57 { |
58 visitor->trace(m_openDatabaseSet); | |
59 visitor->trace(m_transactionCoordinator); | |
60 } | 58 } |
61 | 59 |
62 void DatabaseThread::start() | 60 void DatabaseThread::start() |
63 { | 61 { |
64 ASSERT(isMainThread()); | 62 ASSERT(isMainThread()); |
65 if (m_thread) | 63 if (m_thread) |
66 return; | 64 return; |
67 m_thread = WebThreadSupportingGC::create("WebCore: Database"); | 65 m_thread = WebThreadSupportingGC::create("WebCore: Database", true); |
68 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::setupDat
abaseThread, wrapCrossThreadPersistent(this))); | 66 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::setupDat
abaseThread, wrapCrossThreadPersistent(this))); |
69 } | 67 } |
70 | 68 |
71 void DatabaseThread::setupDatabaseThread() | 69 void DatabaseThread::setupDatabaseThread() |
72 { | 70 { |
73 m_thread->initialize(); | 71 m_thread->initialize(); |
| 72 m_transactionCoordinator = new SQLTransactionCoordinator(); |
74 } | 73 } |
75 | 74 |
76 void DatabaseThread::terminate() | 75 void DatabaseThread::terminate() |
77 { | 76 { |
78 ASSERT(isMainThread()); | 77 ASSERT(isMainThread()); |
79 TaskSynchronizer sync; | 78 TaskSynchronizer sync; |
80 { | 79 { |
81 MutexLocker lock(m_terminationRequestedMutex); | 80 MutexLocker lock(m_terminationRequestedMutex); |
82 ASSERT(!m_terminationRequested); | 81 ASSERT(!m_terminationRequested); |
83 m_terminationRequested = true; | 82 m_terminationRequested = true; |
84 m_cleanupSync = &sync; | 83 m_cleanupSync = &sync; |
85 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); | 84 WTF_LOG(StorageAPI, "DatabaseThread %p was asked to terminate\n", this); |
86 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::clea
nupDatabaseThread, wrapCrossThreadPersistent(this))); | 85 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseThread::clea
nupDatabaseThread, wrapCrossThreadPersistent(this))); |
87 } | 86 } |
88 sync.waitForTaskCompletion(); | 87 sync.waitForTaskCompletion(); |
89 // The WebThread destructor blocks until all the tasks of the database | 88 // The WebThread destructor blocks until all the tasks of the database |
90 // thread are processed. However, it shouldn't block at all because | 89 // thread are processed. However, it shouldn't block at all because |
91 // the database thread has already finished processing the cleanup task. | 90 // the database thread has already finished processing the cleanup task. |
92 m_thread.reset(); | 91 m_thread.reset(); |
93 } | 92 } |
94 | 93 |
95 void DatabaseThread::cleanupDatabaseThread() | 94 void DatabaseThread::cleanupDatabaseThread() |
96 { | 95 { |
| 96 DCHECK(isDatabaseThread()); |
| 97 |
97 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); | 98 WTF_LOG(StorageAPI, "Cleaning up DatabaseThread %p", this); |
98 | 99 |
99 // Clean up the list of all pending transactions on this database thread | 100 // Clean up the list of all pending transactions on this database thread |
100 m_transactionCoordinator->shutdown(); | 101 m_transactionCoordinator->shutdown(); |
101 | 102 |
102 // Close the databases that we ran transactions on. This ensures that if any
transactions are still open, they are rolled back and we don't leave the databa
se in an | 103 // Close the databases that we ran transactions on. This ensures that if any
transactions are still open, they are rolled back and we don't leave the databa
se in an |
103 // inconsistent or locked state. | 104 // inconsistent or locked state. |
104 if (m_openDatabaseSet.size() > 0) { | 105 if (m_openDatabaseSet.size() > 0) { |
105 // As the call to close will modify the original set, we must take a cop
y to iterate over. | 106 // As the call to close will modify the original set, we must take a cop
y to iterate over. |
106 HeapHashSet<Member<Database>> openSetCopy; | 107 HashSet<CrossThreadPersistent<Database>> openSetCopy; |
107 openSetCopy.swap(m_openDatabaseSet); | 108 openSetCopy.swap(m_openDatabaseSet); |
108 HeapHashSet<Member<Database>>::iterator end = openSetCopy.end(); | 109 HashSet<CrossThreadPersistent<Database>>::iterator end = openSetCopy.end
(); |
109 for (HeapHashSet<Member<Database>>::iterator it = openSetCopy.begin(); i
t != end; ++it) | 110 for (HashSet<CrossThreadPersistent<Database>>::iterator it = openSetCopy
.begin(); it != end; ++it) |
110 (*it)->close(); | 111 (*it)->close(); |
111 } | 112 } |
112 m_openDatabaseSet.clear(); | 113 m_openDatabaseSet.clear(); |
113 | 114 |
114 m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDataba
seThreadCompleted, this)); | 115 m_thread->postTask(BLINK_FROM_HERE, WTF::bind(&DatabaseThread::cleanupDataba
seThreadCompleted, this)); |
115 } | 116 } |
116 | 117 |
117 void DatabaseThread::cleanupDatabaseThreadCompleted() | 118 void DatabaseThread::cleanupDatabaseThreadCompleted() |
118 { | 119 { |
119 m_thread->shutdown(); | 120 m_thread->shutdown(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 { | 167 { |
167 MutexLocker lock(m_terminationRequestedMutex); | 168 MutexLocker lock(m_terminationRequestedMutex); |
168 ASSERT(!m_terminationRequested); | 169 ASSERT(!m_terminationRequested); |
169 } | 170 } |
170 #endif | 171 #endif |
171 // WebThread takes ownership of the task. | 172 // WebThread takes ownership of the task. |
172 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseTask::run, std::
move(task))); | 173 m_thread->postTask(BLINK_FROM_HERE, threadSafeBind(&DatabaseTask::run, std::
move(task))); |
173 } | 174 } |
174 | 175 |
175 } // namespace blink | 176 } // namespace blink |
OLD | NEW |