Chromium Code Reviews| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 // live until after the ExecutionContext destructs. This is true even if | 61 // live until after the ExecutionContext destructs. This is true even if |
| 62 // we don't succeed in opening any Databases for that context. When we do | 62 // we don't succeed in opening any Databases for that context. When we do |
| 63 // succeed in opening Databases for this ExecutionContext, the Database | 63 // succeed in opening Databases for this ExecutionContext, the Database |
| 64 // will re-use the same DatabaseContext. | 64 // will re-use the same DatabaseContext. |
| 65 // | 65 // |
| 66 // At Shutdown: | 66 // At Shutdown: |
| 67 // =========== | 67 // =========== |
| 68 // During shutdown, the DatabaseContext needs to: | 68 // During shutdown, the DatabaseContext needs to: |
| 69 // 1. "outlive" the ExecutionContext. | 69 // 1. "outlive" the ExecutionContext. |
| 70 // - This is needed because the DatabaseContext needs to remove itself from | 70 // - This is needed because the DatabaseContext needs to remove itself from |
| 71 // the | 71 // the |
|
dcheng
2016/12/12 02:06:27
Nit: can we fix the wrapping while we're changing
| |
| 72 // ExecutionContext's ActiveDOMObject list and ContextLifecycleObserver | 72 // ExecutionContext's SuspendableObject list and ContextLifecycleObserver |
| 73 // list. This removal needs to be executed on the script's thread. Hence, | 73 // list. This removal needs to be executed on the script's thread. Hence, |
| 74 // we | 74 // we |
|
dcheng
2016/12/12 02:06:27
Here as well.
| |
| 75 // rely on the ExecutionContext's shutdown process to call | 75 // rely on the ExecutionContext's shutdown process to call |
| 76 // stop() and contextDestroyed() to give us a chance to clean these up from | 76 // stop() and contextDestroyed() to give us a chance to clean these up from |
| 77 // the script thread. | 77 // the script thread. |
| 78 // | 78 // |
| 79 // 2. "outlive" the Databases. | 79 // 2. "outlive" the Databases. |
| 80 // - This is because they may make use of the DatabaseContext to execute a | 80 // - This is because they may make use of the DatabaseContext to execute a |
| 81 // close task and shutdown in an orderly manner. When the Databases are | 81 // close task and shutdown in an orderly manner. When the Databases are |
| 82 // destructed, they will release the DatabaseContext reference from the | 82 // destructed, they will release the DatabaseContext reference from the |
| 83 // DatabaseThread. | 83 // DatabaseThread. |
| 84 // | 84 // |
| 85 // During shutdown, the ExecutionContext is shutting down on the script thread | 85 // During shutdown, the ExecutionContext is shutting down on the script thread |
| 86 // while the Databases are shutting down on the DatabaseThread. Hence, there can | 86 // while the Databases are shutting down on the DatabaseThread. Hence, there can |
| 87 // be a race condition as to whether the ExecutionContext or the Databases | 87 // be a race condition as to whether the ExecutionContext or the Databases |
| 88 // destruct first. | 88 // destruct first. |
| 89 // | 89 // |
| 90 // The Members in the Databases and DatabaseManager will ensure that the | 90 // The Members in the Databases and DatabaseManager will ensure that the |
| 91 // DatabaseContext will outlive Database and ExecutionContext regardless of | 91 // DatabaseContext will outlive Database and ExecutionContext regardless of |
| 92 // which of the 2 destructs first. | 92 // which of the 2 destructs first. |
| 93 | 93 |
| 94 DatabaseContext* DatabaseContext::create(ExecutionContext* context) { | 94 DatabaseContext* DatabaseContext::create(ExecutionContext* context) { |
| 95 DatabaseContext* self = new DatabaseContext(context); | 95 DatabaseContext* self = new DatabaseContext(context); |
| 96 DatabaseManager::manager().registerDatabaseContext(self); | 96 DatabaseManager::manager().registerDatabaseContext(self); |
| 97 return self; | 97 return self; |
| 98 } | 98 } |
| 99 | 99 |
| 100 DatabaseContext::DatabaseContext(ExecutionContext* context) | 100 DatabaseContext::DatabaseContext(ExecutionContext* context) |
| 101 : ActiveDOMObject(context), | 101 : SuspendableObject(context), |
| 102 m_hasOpenDatabases(false), | 102 m_hasOpenDatabases(false), |
| 103 m_hasRequestedTermination(false) { | 103 m_hasRequestedTermination(false) { |
| 104 DCHECK(isMainThread()); | 104 DCHECK(isMainThread()); |
| 105 | 105 |
| 106 // ActiveDOMObject expects this to be called to set internal flags. | 106 // SuspendableObject expects this to be called to set internal flags. |
| 107 suspendIfNeeded(); | 107 suspendIfNeeded(); |
| 108 | 108 |
| 109 // For debug accounting only. We must do this before we register the | 109 // For debug accounting only. We must do this before we register the |
| 110 // instance. The assertions assume this. | 110 // instance. The assertions assume this. |
| 111 DatabaseManager::manager().didConstructDatabaseContext(); | 111 DatabaseManager::manager().didConstructDatabaseContext(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 DatabaseContext::~DatabaseContext() { | 114 DatabaseContext::~DatabaseContext() { |
| 115 // For debug accounting only. We must call this last. The assertions assume | 115 // For debug accounting only. We must call this last. The assertions assume |
| 116 // this. | 116 // this. |
| 117 DatabaseManager::manager().didDestructDatabaseContext(); | 117 DatabaseManager::manager().didDestructDatabaseContext(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 DEFINE_TRACE(DatabaseContext) { | 120 DEFINE_TRACE(DatabaseContext) { |
| 121 visitor->trace(m_databaseThread); | 121 visitor->trace(m_databaseThread); |
| 122 ActiveDOMObject::trace(visitor); | 122 SuspendableObject::trace(visitor); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // This is called if the associated ExecutionContext is destructing while | 125 // This is called if the associated ExecutionContext is destructing while |
| 126 // we're still associated with it. That's our cue to disassociate and shutdown. | 126 // we're still associated with it. That's our cue to disassociate and shutdown. |
| 127 // To do this, we stop the database and let everything shutdown naturally | 127 // To do this, we stop the database and let everything shutdown naturally |
| 128 // because the database closing process may still make use of this context. | 128 // because the database closing process may still make use of this context. |
| 129 // It is not safe to just delete the context here. | 129 // It is not safe to just delete the context here. |
| 130 void DatabaseContext::contextDestroyed() { | 130 void DatabaseContext::contextDestroyed() { |
| 131 stopDatabases(); | 131 stopDatabases(); |
| 132 DatabaseManager::manager().unregisterDatabaseContext(this); | 132 DatabaseManager::manager().unregisterDatabaseContext(this); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 | 182 |
| 183 SecurityOrigin* DatabaseContext::getSecurityOrigin() const { | 183 SecurityOrigin* DatabaseContext::getSecurityOrigin() const { |
| 184 return getExecutionContext()->getSecurityOrigin(); | 184 return getExecutionContext()->getSecurityOrigin(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool DatabaseContext::isContextThread() const { | 187 bool DatabaseContext::isContextThread() const { |
| 188 return getExecutionContext()->isContextThread(); | 188 return getExecutionContext()->isContextThread(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace blink | 191 } // namespace blink |
| OLD | NEW |