Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: Source/modules/webdatabase/DatabaseManager.h

Issue 567453002: Web SQL: Make sure DatabaseManager is used only in the main thread. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef DatabaseManager_h 26 #ifndef DatabaseManager_h
27 #define DatabaseManager_h 27 #define DatabaseManager_h
28 28
29 #include "modules/webdatabase/DatabaseBasicTypes.h"
30 #include "modules/webdatabase/DatabaseContext.h" 29 #include "modules/webdatabase/DatabaseContext.h"
31 #include "modules/webdatabase/DatabaseError.h" 30 #include "modules/webdatabase/DatabaseError.h"
32 #include "platform/heap/Handle.h" 31 #include "platform/heap/Handle.h"
33 #include "wtf/Assertions.h" 32 #include "wtf/Assertions.h"
33 #include "wtf/Forward.h"
34 #include "wtf/HashMap.h" 34 #include "wtf/HashMap.h"
35 #include "wtf/PassRefPtr.h" 35 #include "wtf/PassRefPtr.h"
36 #include "wtf/ThreadingPrimitives.h"
37 #include "wtf/text/WTFString.h"
38 36
39 namespace blink { 37 namespace blink {
40 38
41 class AbstractDatabaseServer; 39 class AbstractDatabaseServer;
42 class Database; 40 class Database;
43 class DatabaseBackendBase; 41 class DatabaseBackendBase;
44 class DatabaseCallback; 42 class DatabaseCallback;
45 class DatabaseContext; 43 class DatabaseContext;
46 class TaskSynchronizer;
47 class ExceptionState; 44 class ExceptionState;
48 class SecurityOrigin; 45 class SecurityOrigin;
49 class ExecutionContext; 46 class ExecutionContext;
50 47
51 typedef int ExceptionCode;
52
53 class DatabaseManager { 48 class DatabaseManager {
54 WTF_MAKE_NONCOPYABLE(DatabaseManager); WTF_MAKE_FAST_ALLOCATED; 49 WTF_MAKE_NONCOPYABLE(DatabaseManager); WTF_MAKE_FAST_ALLOCATED;
55 public: 50 public:
56 static DatabaseManager& manager(); 51 static DatabaseManager& manager();
57 52
58 // These 2 methods are for DatabaseContext (un)registration, and should only 53 // These 2 methods are for DatabaseContext (un)registration, and should only
59 // be called by the DatabaseContext constructor and destructor. 54 // be called by the DatabaseContext constructor and destructor.
60 void registerDatabaseContext(DatabaseContext*); 55 void registerDatabaseContext(DatabaseContext*);
61 void unregisterDatabaseContext(DatabaseContext*); 56 void unregisterDatabaseContext(DatabaseContext*);
62 57
63 #if ENABLE(ASSERT) 58 #if ENABLE(ASSERT)
64 void didConstructDatabaseContext(); 59 void didConstructDatabaseContext();
65 void didDestructDatabaseContext(); 60 void didDestructDatabaseContext();
66 #else 61 #else
67 void didConstructDatabaseContext() { } 62 void didConstructDatabaseContext() { }
68 void didDestructDatabaseContext() { } 63 void didDestructDatabaseContext() { }
69 #endif 64 #endif
70 65
71 static void throwExceptionForDatabaseError(DatabaseError, const String& erro rMessage, ExceptionState&); 66 static void throwExceptionForDatabaseError(DatabaseError, const String& erro rMessage, ExceptionState&);
72 67
73 PassRefPtrWillBeRawPtr<Database> openDatabase(ExecutionContext*, const Strin g& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback>, DatabaseError&, String & errorMessage); 68 PassRefPtrWillBeRawPtr<Database> openDatabase(ExecutionContext*, const Strin g& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback>, DatabaseError&, String & errorMessage);
74 69
75 String fullPathForDatabase(SecurityOrigin*, const String& name, bool createI fDoesNotExist = true); 70 String fullPathForDatabase(SecurityOrigin*, const String& name, bool createI fDoesNotExist = true);
76 71
77 void closeDatabasesImmediately(const String& originIdentifier, const String& name);
78
79 private: 72 private:
80 DatabaseManager(); 73 DatabaseManager();
81 ~DatabaseManager(); 74 ~DatabaseManager();
82 75
83 // This gets a DatabaseContext for the specified ExecutionContext. 76 // This gets a DatabaseContext for the specified ExecutionContext.
84 // If one doesn't already exist, it will create a new one. 77 // If one doesn't already exist, it will create a new one.
85 DatabaseContext* databaseContextFor(ExecutionContext*); 78 DatabaseContext* databaseContextFor(ExecutionContext*);
86 // This gets a DatabaseContext for the specified ExecutionContext if 79 // This gets a DatabaseContext for the specified ExecutionContext if
87 // it already exist previously. Otherwise, it returns 0. 80 // it already exist previously. Otherwise, it returns 0.
88 DatabaseContext* existingDatabaseContextFor(ExecutionContext*); 81 DatabaseContext* existingDatabaseContextFor(ExecutionContext*);
89 82
90 PassRefPtrWillBeRawPtr<DatabaseBackendBase> openDatabaseBackend(ExecutionCon text*, 83 PassRefPtrWillBeRawPtr<DatabaseBackendBase> openDatabaseBackend(ExecutionCon text*,
91 const String& name, const String& expectedVersion, const String& display Name, 84 const String& name, const String& expectedVersion, const String& display Name,
92 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError &, String& errorMessage); 85 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError &, String& errorMessage);
93 86
94 static void logErrorMessage(ExecutionContext*, const String& message); 87 static void logErrorMessage(ExecutionContext*, const String& message);
95 88
96 AbstractDatabaseServer* m_server; 89 AbstractDatabaseServer* m_server;
97 90
98 // FIXME: Only one DatabaseContext object can be created. We can remove the 91 typedef WillBePersistentHeapHashMap<ExecutionContext*, RefPtrWillBeMember<Da tabaseContext> > ContextMap;
99 // following map, and don't need to worry about locking.
100 // Access to the following fields require locking m_contextMapLock:
101 #if ENABLE(OILPAN)
102 // We can't use PersistentHeapHashMap because multiple threads update the ma p.
103 typedef HashMap<ExecutionContext*, OwnPtr<Persistent<DatabaseContext> > > Co ntextMap;
104 #else
105 typedef HashMap<ExecutionContext*, RefPtr<DatabaseContext> > ContextMap;
106 #endif
107 ContextMap m_contextMap; 92 ContextMap m_contextMap;
108 #if ENABLE(ASSERT) 93 #if ENABLE(ASSERT)
109 int m_databaseContextRegisteredCount; 94 int m_databaseContextRegisteredCount;
110 int m_databaseContextInstanceCount; 95 int m_databaseContextInstanceCount;
111 #endif 96 #endif
112 Mutex m_contextMapLock;
113 }; 97 };
114 98
115 } // namespace blink 99 } // namespace blink
116 100
117 #endif // DatabaseManager_h 101 #endif // DatabaseManager_h
OLDNEW
« no previous file with comments | « Source/modules/webdatabase/AbstractDatabaseServer.h ('k') | Source/modules/webdatabase/DatabaseManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698