OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2011 Google, Inc. All Rights Reserved. | 3 * Copyright (C) 2011 Google, Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // they will deref the DatabaseContext from the DatabaseThread. | 80 // they will deref the DatabaseContext from the DatabaseThread. |
81 // | 81 // |
82 // During shutdown, the ExecutionContext is shutting down on the script thread | 82 // During shutdown, the ExecutionContext is shutting down on the script thread |
83 // while the Databases are shutting down on the DatabaseThread. Hence, there can
be | 83 // while the Databases are shutting down on the DatabaseThread. Hence, there can
be |
84 // a race condition as to whether the ExecutionContext or the Databases | 84 // a race condition as to whether the ExecutionContext or the Databases |
85 // destruct first. | 85 // destruct first. |
86 // | 86 // |
87 // The RefPtrs in the Databases and ExecutionContext will ensure that the | 87 // The RefPtrs in the Databases and ExecutionContext will ensure that the |
88 // DatabaseContext will outlive both regardless of which of the 2 destructs firs
t. | 88 // DatabaseContext will outlive both regardless of which of the 2 destructs firs
t. |
89 | 89 |
90 PassRefPtr<DatabaseContext> DatabaseContext::create(ExecutionContext* context) | 90 PassRefPtrWillBeRawPtr<DatabaseContext> DatabaseContext::create(ExecutionContext
* context) |
91 { | 91 { |
92 RefPtr<DatabaseContext> self = adoptRef(new DatabaseContext(context)); | 92 RefPtrWillBeRawPtr<DatabaseContext> self = adoptRefWillBeNoop(new DatabaseCo
ntext(context)); |
93 DatabaseManager::manager().registerDatabaseContext(self.get()); | 93 DatabaseManager::manager().registerDatabaseContext(self.get()); |
94 return self.release(); | 94 return self.release(); |
95 } | 95 } |
96 | 96 |
97 DatabaseContext::DatabaseContext(ExecutionContext* context) | 97 DatabaseContext::DatabaseContext(ExecutionContext* context) |
98 : ActiveDOMObject(context) | 98 : ActiveDOMObject(context) |
99 , m_hasOpenDatabases(false) | 99 , m_hasOpenDatabases(false) |
100 , m_hasRequestedTermination(false) | 100 , m_hasRequestedTermination(false) |
101 { | 101 { |
102 // ActiveDOMObject expects this to be called to set internal flags. | 102 // ActiveDOMObject expects this to be called to set internal flags. |
103 suspendIfNeeded(); | 103 suspendIfNeeded(); |
104 | 104 |
105 // For debug accounting only. We must do this before we register the | 105 // For debug accounting only. We must do this before we register the |
106 // instance. The assertions assume this. | 106 // instance. The assertions assume this. |
107 DatabaseManager::manager().didConstructDatabaseContext(); | 107 DatabaseManager::manager().didConstructDatabaseContext(); |
108 } | 108 } |
109 | 109 |
110 DatabaseContext::~DatabaseContext() | 110 DatabaseContext::~DatabaseContext() |
111 { | 111 { |
112 ASSERT(!m_databaseThread || m_databaseThread->terminationRequested()); | |
113 | |
114 // For debug accounting only. We must call this last. The assertions assume | 112 // For debug accounting only. We must call this last. The assertions assume |
115 // this. | 113 // this. |
116 DatabaseManager::manager().didDestructDatabaseContext(); | 114 DatabaseManager::manager().didDestructDatabaseContext(); |
117 } | 115 } |
118 | 116 |
| 117 void DatabaseContext::trace(Visitor* visitor) |
| 118 { |
| 119 visitor->trace(m_databaseThread); |
| 120 visitor->trace(m_openSyncDatabases); |
| 121 } |
| 122 |
119 // This is called if the associated ExecutionContext is destructing while | 123 // This is called if the associated ExecutionContext is destructing while |
120 // we're still associated with it. That's our cue to disassociate and shutdown. | 124 // we're still associated with it. That's our cue to disassociate and shutdown. |
121 // To do this, we stop the database and let everything shutdown naturally | 125 // To do this, we stop the database and let everything shutdown naturally |
122 // because the database closing process may still make use of this context. | 126 // because the database closing process may still make use of this context. |
123 // It is not safe to just delete the context here. | 127 // It is not safe to just delete the context here. |
124 void DatabaseContext::contextDestroyed() | 128 void DatabaseContext::contextDestroyed() |
125 { | 129 { |
126 RefPtr<DatabaseContext> protector(this); | 130 RefPtrWillBeRawPtr<DatabaseContext> protector(this); |
127 stopDatabases(); | 131 stopDatabases(); |
128 DatabaseManager::manager().unregisterDatabaseContext(this); | 132 DatabaseManager::manager().unregisterDatabaseContext(this); |
129 ActiveDOMObject::contextDestroyed(); | 133 ActiveDOMObject::contextDestroyed(); |
130 } | 134 } |
131 | 135 |
132 void DatabaseContext::willStop() | 136 void DatabaseContext::willStop() |
133 { | 137 { |
134 DatabaseManager::manager().interruptAllDatabasesForContext(this); | 138 DatabaseManager::manager().interruptAllDatabasesForContext(this); |
135 } | 139 } |
136 | 140 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 { | 259 { |
256 return executionContext()->securityOrigin(); | 260 return executionContext()->securityOrigin(); |
257 } | 261 } |
258 | 262 |
259 bool DatabaseContext::isContextThread() const | 263 bool DatabaseContext::isContextThread() const |
260 { | 264 { |
261 return executionContext()->isContextThread(); | 265 return executionContext()->isContextThread(); |
262 } | 266 } |
263 | 267 |
264 } // namespace WebCore | 268 } // namespace WebCore |
OLD | NEW |