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

Side by Side Diff: WebCore/storage/DatabaseTracker.h

Issue 596028: Make the DatabaseTracker thread-safe. (Closed) Base URL: http://svn.webkit.org/repository/webkit/trunk/
Patch Set: '' Created 10 years, 10 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
« no previous file with comments | « WebCore/storage/DatabaseThread.cpp ('k') | WebCore/storage/DatabaseTracker.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #if !PLATFORM(CHROMIUM) 53 #if !PLATFORM(CHROMIUM)
54 class DatabaseTrackerClient; 54 class DatabaseTrackerClient;
55 class OriginQuotaManager; 55 class OriginQuotaManager;
56 56
57 struct SecurityOriginTraits; 57 struct SecurityOriginTraits;
58 #endif // !PLATFORM(CHROMIUM) 58 #endif // !PLATFORM(CHROMIUM)
59 59
60 class DatabaseTracker : public Noncopyable { 60 class DatabaseTracker : public Noncopyable {
61 public: 61 public:
62 static DatabaseTracker& tracker(); 62 static DatabaseTracker& tracker();
63 // FIXME: Due to workers having multiple threads in a single process sharing 63 // This singleton will potentially be used from multiple worker threads and the page's context thread simultaneously. To keep this safe, it's
64 // a DatabaseTracker, this singleton will have to be synchronized or moved 64 // currently using 4 locks. In order to avoid deadlock when taking multiple locks, you must take them in the correct order:
65 // to TLS. 65 // originQuotaManager() before m_databaseGuard or m_openDatabaseMapGuard
66 // m_databaseGuard before m_openDatabaseMapGuard
67 // notificationMutex() is currently independent of the other locks.
66 68
67 bool canEstablishDatabase(ScriptExecutionContext*, const String& name, const String& displayName, unsigned long estimatedSize); 69 bool canEstablishDatabase(ScriptExecutionContext*, const String& name, const String& displayName, unsigned long estimatedSize);
68 void setDatabaseDetails(SecurityOrigin*, const String& name, const String& d isplayName, unsigned long estimatedSize); 70 void setDatabaseDetails(SecurityOrigin*, const String& name, const String& d isplayName, unsigned long estimatedSize);
69 String fullPathForDatabase(SecurityOrigin*, const String& name, bool createI fDoesNotExist = true); 71 String fullPathForDatabase(SecurityOrigin*, const String& name, bool createI fDoesNotExist = true);
70 72
71 void addOpenDatabase(Database*); 73 void addOpenDatabase(Database*);
72 void removeOpenDatabase(Database*); 74 void removeOpenDatabase(Database*);
73 void getOpenDatabases(SecurityOrigin* origin, const String& name, HashSet<Re fPtr<Database> >* databases); 75 void getOpenDatabases(SecurityOrigin* origin, const String& name, HashSet<Re fPtr<Database> >* databases);
74 76
75 unsigned long long getMaxSizeForDatabase(const Database*); 77 unsigned long long getMaxSizeForDatabase(const Database*);
76 78
77 private: 79 private:
78 DatabaseTracker(); 80 DatabaseTracker();
79 81
80 typedef HashSet<Database*> DatabaseSet; 82 typedef HashSet<Database*> DatabaseSet;
81 typedef HashMap<String, DatabaseSet*> DatabaseNameMap; 83 typedef HashMap<String, DatabaseSet*> DatabaseNameMap;
82 typedef HashMap<RefPtr<SecurityOrigin>, DatabaseNameMap*, SecurityOriginHash > DatabaseOriginMap; 84 typedef HashMap<RefPtr<SecurityOrigin>, DatabaseNameMap*, SecurityOriginHash > DatabaseOriginMap;
83 85
84 Mutex m_openDatabaseMapGuard; 86 Mutex m_openDatabaseMapGuard;
85 mutable OwnPtr<DatabaseOriginMap> m_openDatabaseMap; 87 mutable OwnPtr<DatabaseOriginMap> m_openDatabaseMap;
86 88
87 #if !PLATFORM(CHROMIUM) 89 #if !PLATFORM(CHROMIUM)
88 public: 90 public:
89 void setDatabaseDirectoryPath(const String&); 91 void setDatabaseDirectoryPath(const String&);
90 const String& databaseDirectoryPath() const; 92 String databaseDirectoryPath() const;
91 93
92 void origins(Vector<RefPtr<SecurityOrigin> >& result); 94 void origins(Vector<RefPtr<SecurityOrigin> >& result);
93 bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result); 95 bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result);
94 96
95 DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*); 97 DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*);
96 98
97 unsigned long long usageForDatabase(const String&, SecurityOrigin*); 99 unsigned long long usageForDatabase(const String&, SecurityOrigin*);
98 unsigned long long usageForOrigin(SecurityOrigin*); 100 unsigned long long usageForOrigin(SecurityOrigin*);
99 unsigned long long quotaForOrigin(SecurityOrigin*); 101 unsigned long long quotaForOrigin(SecurityOrigin*);
100 void setQuota(SecurityOrigin*, unsigned long long); 102 void setQuota(SecurityOrigin*, unsigned long long);
101 103
102 void deleteAllDatabases(); 104 void deleteAllDatabases();
103 void deleteOrigin(SecurityOrigin*); 105 void deleteOrigin(SecurityOrigin*);
104 void deleteDatabase(SecurityOrigin*, const String& name); 106 void deleteDatabase(SecurityOrigin*, const String& name);
105 107
106 void setClient(DatabaseTrackerClient*); 108 void setClient(DatabaseTrackerClient*);
107 109
108 // From a secondary thread, must be thread safe with its data 110 // From a secondary thread, must be thread safe with its data
109 void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name); 111 void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name);
110 112
111 OriginQuotaManager& originQuotaManager(); 113 OriginQuotaManager& originQuotaManager();
112 114
113 115
114 bool hasEntryForOrigin(SecurityOrigin*); 116 bool hasEntryForOrigin(SecurityOrigin*);
115 117
116 private: 118 private:
119 OriginQuotaManager& originQuotaManagerNoLock();
120 bool hasEntryForOriginNoLock(SecurityOrigin* origin);
121 String fullPathForDatabaseNoLock(SecurityOrigin*, const String& name, bool c reateIfDoesNotExist);
122 bool databaseNamesForOriginNoLock(SecurityOrigin* origin, Vector<String>& re sultVector);
123 unsigned long long usageForOriginNoLock(SecurityOrigin* origin);
124 unsigned long long quotaForOriginNoLock(SecurityOrigin* origin);
125
117 String trackerDatabasePath() const; 126 String trackerDatabasePath() const;
118 void openTrackerDatabase(bool createIfDoesNotExist); 127 void openTrackerDatabase(bool createIfDoesNotExist);
119 128
120 String originPath(SecurityOrigin*) const; 129 String originPath(SecurityOrigin*) const;
121 130
122 bool hasEntryForDatabase(SecurityOrigin*, const String& databaseIdentifier); 131 bool hasEntryForDatabase(SecurityOrigin*, const String& databaseIdentifier);
123 132
124 bool addDatabase(SecurityOrigin*, const String& name, const String& path); 133 bool addDatabase(SecurityOrigin*, const String& name, const String& path);
125 void populateOrigins(); 134 void populateOrigins();
126 135
127 bool deleteDatabaseFile(SecurityOrigin*, const String& name); 136 bool deleteDatabaseFile(SecurityOrigin*, const String& name);
128 137
138 // This lock protects m_database, m_quotaMap, and m_proposedDatabases.
139 Mutex m_databaseGuard;
129 SQLiteDatabase m_database; 140 SQLiteDatabase m_database;
130 141
131 typedef HashMap<RefPtr<SecurityOrigin>, unsigned long long, SecurityOriginHa sh> QuotaMap; 142 typedef HashMap<RefPtr<SecurityOrigin>, unsigned long long, SecurityOriginHa sh> QuotaMap;
132 Mutex m_quotaMapGuard;
133 mutable OwnPtr<QuotaMap> m_quotaMap; 143 mutable OwnPtr<QuotaMap> m_quotaMap;
134 144
135 OwnPtr<OriginQuotaManager> m_quotaManager; 145 OwnPtr<OriginQuotaManager> m_quotaManager;
136 146
137 String m_databaseDirectoryPath; 147 String m_databaseDirectoryPath;
138 148
139 DatabaseTrackerClient* m_client; 149 DatabaseTrackerClient* m_client;
140 150
141 std::pair<SecurityOrigin*, DatabaseDetails>* m_proposedDatabase; 151 typedef std::pair<SecurityOrigin*, DatabaseDetails> ProposedDatabase;
142 152 HashSet<ProposedDatabase*> m_proposedDatabases;
143 #ifndef NDEBUG
144 ThreadIdentifier m_thread;
145 #endif
146 153
147 static void scheduleForNotification(); 154 static void scheduleForNotification();
148 static void notifyDatabasesChanged(void*); 155 static void notifyDatabasesChanged(void*);
149 #endif // !PLATFORM(CHROMIUM) 156 #endif // !PLATFORM(CHROMIUM)
150 }; 157 };
151 158
152 } // namespace WebCore 159 } // namespace WebCore
153 160
154 #endif // ENABLE(DATABASE) 161 #endif // ENABLE(DATABASE)
155 #endif // DatabaseTracker_h 162 #endif // DatabaseTracker_h
OLDNEW
« no previous file with comments | « WebCore/storage/DatabaseThread.cpp ('k') | WebCore/storage/DatabaseTracker.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698