OLD | NEW |
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 |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "wtf/ThreadingPrimitives.h" | 36 #include "wtf/ThreadingPrimitives.h" |
37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 class AbstractDatabaseServer; | 41 class AbstractDatabaseServer; |
42 class Database; | 42 class Database; |
43 class DatabaseBackendBase; | 43 class DatabaseBackendBase; |
44 class DatabaseCallback; | 44 class DatabaseCallback; |
45 class DatabaseContext; | 45 class DatabaseContext; |
46 class DatabaseSync; | |
47 class TaskSynchronizer; | 46 class TaskSynchronizer; |
48 class ExceptionState; | 47 class ExceptionState; |
49 class SecurityOrigin; | 48 class SecurityOrigin; |
50 class ExecutionContext; | 49 class ExecutionContext; |
51 | 50 |
52 typedef int ExceptionCode; | 51 typedef int ExceptionCode; |
53 | 52 |
54 class DatabaseManager { | 53 class DatabaseManager { |
55 WTF_MAKE_NONCOPYABLE(DatabaseManager); WTF_MAKE_FAST_ALLOCATED; | 54 WTF_MAKE_NONCOPYABLE(DatabaseManager); WTF_MAKE_FAST_ALLOCATED; |
56 public: | 55 public: |
57 static DatabaseManager& manager(); | 56 static DatabaseManager& manager(); |
58 | 57 |
59 // These 2 methods are for DatabaseContext (un)registration, and should only | 58 // These 2 methods are for DatabaseContext (un)registration, and should only |
60 // be called by the DatabaseContext constructor and destructor. | 59 // be called by the DatabaseContext constructor and destructor. |
61 void registerDatabaseContext(DatabaseContext*); | 60 void registerDatabaseContext(DatabaseContext*); |
62 void unregisterDatabaseContext(DatabaseContext*); | 61 void unregisterDatabaseContext(DatabaseContext*); |
63 | 62 |
64 #if ENABLE(ASSERT) | 63 #if ENABLE(ASSERT) |
65 void didConstructDatabaseContext(); | 64 void didConstructDatabaseContext(); |
66 void didDestructDatabaseContext(); | 65 void didDestructDatabaseContext(); |
67 #else | 66 #else |
68 void didConstructDatabaseContext() { } | 67 void didConstructDatabaseContext() { } |
69 void didDestructDatabaseContext() { } | 68 void didDestructDatabaseContext() { } |
70 #endif | 69 #endif |
71 | 70 |
72 static void throwExceptionForDatabaseError(DatabaseError, const String& erro
rMessage, ExceptionState&); | 71 static void throwExceptionForDatabaseError(DatabaseError, const String& erro
rMessage, ExceptionState&); |
73 | 72 |
74 PassRefPtrWillBeRawPtr<Database> openDatabase(ExecutionContext*, const Strin
g& name, const String& expectedVersion, const String& displayName, unsigned long
estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback>, DatabaseError&, String
& errorMessage); | 73 PassRefPtrWillBeRawPtr<Database> openDatabase(ExecutionContext*, const Strin
g& name, const String& expectedVersion, const String& displayName, unsigned long
estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback>, DatabaseError&, String
& errorMessage); |
75 PassRefPtrWillBeRawPtr<DatabaseSync> openDatabaseSync(ExecutionContext*, con
st String& name, const String& expectedVersion, const String& displayName, unsig
ned long estimatedSize, PassOwnPtrWillBeRawPtr<DatabaseCallback>, DatabaseError&
, String& errorMessage); | |
76 | 74 |
77 String fullPathForDatabase(SecurityOrigin*, const String& name, bool createI
fDoesNotExist = true); | 75 String fullPathForDatabase(SecurityOrigin*, const String& name, bool createI
fDoesNotExist = true); |
78 | 76 |
79 void closeDatabasesImmediately(const String& originIdentifier, const String&
name); | 77 void closeDatabasesImmediately(const String& originIdentifier, const String&
name); |
80 | 78 |
81 void interruptAllDatabasesForContext(DatabaseContext*); | |
82 | |
83 private: | 79 private: |
84 DatabaseManager(); | 80 DatabaseManager(); |
85 ~DatabaseManager(); | 81 ~DatabaseManager(); |
86 | 82 |
87 // This gets a DatabaseContext for the specified ExecutionContext. | 83 // This gets a DatabaseContext for the specified ExecutionContext. |
88 // If one doesn't already exist, it will create a new one. | 84 // If one doesn't already exist, it will create a new one. |
89 DatabaseContext* databaseContextFor(ExecutionContext*); | 85 DatabaseContext* databaseContextFor(ExecutionContext*); |
90 // This gets a DatabaseContext for the specified ExecutionContext if | 86 // This gets a DatabaseContext for the specified ExecutionContext if |
91 // it already exist previously. Otherwise, it returns 0. | 87 // it already exist previously. Otherwise, it returns 0. |
92 DatabaseContext* existingDatabaseContextFor(ExecutionContext*); | 88 DatabaseContext* existingDatabaseContextFor(ExecutionContext*); |
93 | 89 |
94 PassRefPtrWillBeRawPtr<DatabaseBackendBase> openDatabaseBackend(ExecutionCon
text*, | 90 PassRefPtrWillBeRawPtr<DatabaseBackendBase> openDatabaseBackend(ExecutionCon
text*, |
95 DatabaseType, const String& name, const String& expectedVersion, const S
tring& displayName, | 91 const String& name, const String& expectedVersion, const String& display
Name, |
96 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError
&, String& errorMessage); | 92 unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError
&, String& errorMessage); |
97 | 93 |
98 static void logErrorMessage(ExecutionContext*, const String& message); | 94 static void logErrorMessage(ExecutionContext*, const String& message); |
99 | 95 |
100 AbstractDatabaseServer* m_server; | 96 AbstractDatabaseServer* m_server; |
101 | 97 |
| 98 // FIXME: Only one DatabaseContext object can be created. We can remove the |
| 99 // following map, and don't need to worry about locking. |
102 // Access to the following fields require locking m_contextMapLock: | 100 // Access to the following fields require locking m_contextMapLock: |
103 #if ENABLE(OILPAN) | 101 #if ENABLE(OILPAN) |
104 // We can't use PersistentHeapHashMap because multiple threads update the ma
p. | 102 // We can't use PersistentHeapHashMap because multiple threads update the ma
p. |
105 typedef HashMap<ExecutionContext*, OwnPtr<Persistent<DatabaseContext> > > Co
ntextMap; | 103 typedef HashMap<ExecutionContext*, OwnPtr<Persistent<DatabaseContext> > > Co
ntextMap; |
106 #else | 104 #else |
107 typedef HashMap<ExecutionContext*, RefPtr<DatabaseContext> > ContextMap; | 105 typedef HashMap<ExecutionContext*, RefPtr<DatabaseContext> > ContextMap; |
108 #endif | 106 #endif |
109 ContextMap m_contextMap; | 107 ContextMap m_contextMap; |
110 #if ENABLE(ASSERT) | 108 #if ENABLE(ASSERT) |
111 int m_databaseContextRegisteredCount; | 109 int m_databaseContextRegisteredCount; |
112 int m_databaseContextInstanceCount; | 110 int m_databaseContextInstanceCount; |
113 #endif | 111 #endif |
114 Mutex m_contextMapLock; | 112 Mutex m_contextMapLock; |
115 }; | 113 }; |
116 | 114 |
117 } // namespace blink | 115 } // namespace blink |
118 | 116 |
119 #endif // DatabaseManager_h | 117 #endif // DatabaseManager_h |
OLD | NEW |