| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" | 5 #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
| 10 #include "content/browser/in_process_webkit/indexed_db_callbacks.h" | 10 #include "content/browser/in_process_webkit/indexed_db_callbacks.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 using WebKit::WebIDBKey; | 39 using WebKit::WebIDBKey; |
| 40 using WebKit::WebIDBKeyRange; | 40 using WebKit::WebIDBKeyRange; |
| 41 using WebKit::WebIDBObjectStore; | 41 using WebKit::WebIDBObjectStore; |
| 42 using WebKit::WebIDBTransaction; | 42 using WebKit::WebIDBTransaction; |
| 43 using WebKit::WebSecurityOrigin; | 43 using WebKit::WebSecurityOrigin; |
| 44 using WebKit::WebSerializedScriptValue; | 44 using WebKit::WebSerializedScriptValue; |
| 45 using WebKit::WebVector; | 45 using WebKit::WebVector; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 // FIXME: Replace this magic constant once we have a more sophisticated quota | |
| 50 // system. | |
| 51 static const uint64 kDefaultQuota = 5 * 1024 * 1024; | |
| 52 | |
| 53 template <class T> | 49 template <class T> |
| 54 void DeleteOnWebKitThread(T* obj) { | 50 void DeleteOnWebKitThread(T* obj) { |
| 55 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT, FROM_HERE, obj)) | 51 if (!BrowserThread::DeleteSoon(BrowserThread::WEBKIT, FROM_HERE, obj)) |
| 56 delete obj; | 52 delete obj; |
| 57 } | 53 } |
| 58 | 54 |
| 59 } | 55 } |
| 60 | 56 |
| 61 IndexedDBDispatcherHost::IndexedDBDispatcherHost( | 57 IndexedDBDispatcherHost::IndexedDBDispatcherHost( |
| 62 int process_id, WebKitContext* webkit_context) | 58 int process_id, WebKitContext* webkit_context) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 197 FilePath base_path = webkit_context_->data_path(); | 193 FilePath base_path = webkit_context_->data_path(); |
| 198 FilePath indexed_db_path; | 194 FilePath indexed_db_path; |
| 199 if (!base_path.empty()) { | 195 if (!base_path.empty()) { |
| 200 indexed_db_path = base_path.Append( | 196 indexed_db_path = base_path.Append( |
| 201 IndexedDBContext::kIndexedDBDirectory); | 197 IndexedDBContext::kIndexedDBDirectory); |
| 202 } | 198 } |
| 203 | 199 |
| 204 // TODO(jorlow): This doesn't support file:/// urls properly. We probably need | 200 // TODO(jorlow): This doesn't support file:/// urls properly. We probably need |
| 205 // to add some toString method to WebSecurityOrigin that doesn't | 201 // to add some toString method to WebSecurityOrigin that doesn't |
| 206 // return null for them. | 202 // return null for them. Look at |
| 203 // DatabaseUtil::GetOriginFromIdentifier. |
| 207 WebSecurityOrigin origin( | 204 WebSecurityOrigin origin( |
| 208 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin)); | 205 WebSecurityOrigin::createFromDatabaseIdentifier(params.origin)); |
| 209 GURL origin_url(origin.toString()); | 206 GURL origin_url(origin.toString()); |
| 210 | 207 |
| 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
| 212 DCHECK(kDefaultQuota == params.maximum_size); | |
| 213 | |
| 214 uint64 quota = kDefaultQuota; | |
| 215 if (Context()->IsUnlimitedStorageGranted(origin_url) || | |
| 216 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 217 switches::kUnlimitedQuotaForIndexedDB)) { | |
| 218 // TODO(jorlow): For the IsUnlimitedStorageGranted case, we need some | |
| 219 // way to revoke it. | |
| 220 // TODO(jorlow): Use kint64max once we think we can scale over 1GB. | |
| 221 quota = 1024 * 1024 * 1024; // 1GB. More or less "unlimited". | |
| 222 } | |
| 223 | 209 |
| 224 WebKit::WebIDBFactory::BackingStoreType backingStoreType = | 210 WebKit::WebIDBFactory::BackingStoreType backingStoreType = |
| 225 WebKit::WebIDBFactory::LevelDBBackingStore; | 211 WebKit::WebIDBFactory::LevelDBBackingStore; |
| 226 | 212 |
| 227 if (CommandLine::ForCurrentProcess()->HasSwitch( | 213 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 228 switches::kSQLiteIndexedDatabase)) { | 214 switches::kSQLiteIndexedDatabase)) { |
| 229 backingStoreType = WebKit::WebIDBFactory::SQLiteBackingStore; | 215 backingStoreType = WebKit::WebIDBFactory::SQLiteBackingStore; |
| 230 } | 216 } |
| 231 | 217 |
| 218 // TODO(dgrogan): Delete this magic constant once we've removed sqlite. |
| 219 static const uint64 kIncognitoSqliteBackendQuota = 50 * 1024 * 1024; |
| 220 |
| 232 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore | 221 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore |
| 233 // created) if this origin is already over quota. | 222 // created) if this origin is already over quota. |
| 234 Context()->GetIDBFactory()->open( | 223 Context()->GetIDBFactory()->open( |
| 235 params.name, | 224 params.name, |
| 236 new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id, | 225 new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id, |
| 237 origin_url), | 226 origin_url), |
| 238 origin, NULL, webkit_glue::FilePathToWebString(indexed_db_path), quota, | 227 origin, NULL, webkit_glue::FilePathToWebString(indexed_db_path), |
| 239 backingStoreType); | 228 kIncognitoSqliteBackendQuota, backingStoreType); |
| 240 } | 229 } |
| 241 | 230 |
| 242 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( | 231 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( |
| 243 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { | 232 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { |
| 244 FilePath base_path = webkit_context_->data_path(); | 233 FilePath base_path = webkit_context_->data_path(); |
| 245 FilePath indexed_db_path; | 234 FilePath indexed_db_path; |
| 246 if (!base_path.empty()) { | 235 if (!base_path.empty()) { |
| 247 indexed_db_path = base_path.Append( | 236 indexed_db_path = base_path.Append( |
| 248 IndexedDBContext::kIndexedDBDirectory); | 237 IndexedDBContext::kIndexedDBDirectory); |
| 249 } | 238 } |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 } | 1053 } |
| 1065 idb_transaction->didCompleteTaskEvents(); | 1054 idb_transaction->didCompleteTaskEvents(); |
| 1066 } | 1055 } |
| 1067 | 1056 |
| 1068 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed( | 1057 void IndexedDBDispatcherHost::TransactionDispatcherHost::OnDestroyed( |
| 1069 int32 object_id) { | 1058 int32 object_id) { |
| 1070 transaction_size_map_.erase(object_id); | 1059 transaction_size_map_.erase(object_id); |
| 1071 transaction_url_map_.erase(object_id); | 1060 transaction_url_map_.erase(object_id); |
| 1072 parent_->DestroyObject(&map_, object_id); | 1061 parent_->DestroyObject(&map_, object_id); |
| 1073 } | 1062 } |
| OLD | NEW |