| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/child/indexed_db/indexed_db_callbacks_impl.h" | 5 #include "content/child/indexed_db/indexed_db_callbacks_impl.h" |
| 6 | 6 |
| 7 #include "content/child/indexed_db/indexed_db_dispatcher.h" | 7 #include "content/child/indexed_db/indexed_db_dispatcher.h" |
| 8 #include "content/child/indexed_db/indexed_db_key_builders.h" | 8 #include "content/child/indexed_db/indexed_db_key_builders.h" |
| 9 #include "content/child/indexed_db/webidbcursor_impl.h" | 9 #include "content/child/indexed_db/webidbcursor_impl.h" |
| 10 #include "content/child/indexed_db/webidbdatabase_impl.h" | 10 #include "content/child/indexed_db/webidbdatabase_impl.h" |
| 11 #include "content/common/indexed_db/indexed_db_constants.h" | 11 #include "content/common/indexed_db/indexed_db_constants.h" |
| 12 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
| 13 #include "third_party/WebKit/public/platform/StringVectorCopier.h" |
| 12 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h
" | 14 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h
" |
| 13 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" | 15 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseErr
or.h" |
| 14 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h" | 16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBMetadata.h" |
| 15 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" | 17 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" |
| 16 | 18 |
| 17 using blink::WebBlobInfo; | 19 using blink::WebBlobInfo; |
| 18 using blink::WebIDBCallbacks; | 20 using blink::WebIDBCallbacks; |
| 19 using blink::WebIDBDatabase; | 21 using blink::WebIDBDatabase; |
| 20 using blink::WebIDBMetadata; | 22 using blink::WebIDBMetadata; |
| 21 using blink::WebIDBValue; | 23 using blink::WebIDBValue; |
| 22 using blink::WebString; | 24 using blink::WebString; |
| 23 using blink::WebVector; | 25 using blink::WebVector; |
| 24 using indexed_db::mojom::DatabaseAssociatedPtrInfo; | 26 using indexed_db::mojom::DatabaseAssociatedPtrInfo; |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 void ConvertIndexMetadata(const content::IndexedDBIndexMetadata& metadata, | 32 void ConvertIndexMetadata(const content::IndexedDBIndexMetadata& metadata, |
| 31 WebIDBMetadata::Index* output) { | 33 WebIDBMetadata::Index* output) { |
| 32 output->id = metadata.id; | 34 output->id = metadata.id; |
| 33 output->name = metadata.name; | 35 output->name = WebString::fromUTF16(metadata.name); |
| 34 output->keyPath = WebIDBKeyPathBuilder::Build(metadata.key_path); | 36 output->keyPath = WebIDBKeyPathBuilder::Build(metadata.key_path); |
| 35 output->unique = metadata.unique; | 37 output->unique = metadata.unique; |
| 36 output->multiEntry = metadata.multi_entry; | 38 output->multiEntry = metadata.multi_entry; |
| 37 } | 39 } |
| 38 | 40 |
| 39 void ConvertObjectStoreMetadata( | 41 void ConvertObjectStoreMetadata( |
| 40 const content::IndexedDBObjectStoreMetadata& metadata, | 42 const content::IndexedDBObjectStoreMetadata& metadata, |
| 41 WebIDBMetadata::ObjectStore* output) { | 43 WebIDBMetadata::ObjectStore* output) { |
| 42 output->id = metadata.id; | 44 output->id = metadata.id; |
| 43 output->name = metadata.name; | 45 output->name = WebString::fromUTF16(metadata.name); |
| 44 output->keyPath = WebIDBKeyPathBuilder::Build(metadata.key_path); | 46 output->keyPath = WebIDBKeyPathBuilder::Build(metadata.key_path); |
| 45 output->autoIncrement = metadata.auto_increment; | 47 output->autoIncrement = metadata.auto_increment; |
| 46 output->maxIndexId = metadata.max_index_id; | 48 output->maxIndexId = metadata.max_index_id; |
| 47 output->indexes = WebVector<WebIDBMetadata::Index>(metadata.indexes.size()); | 49 output->indexes = WebVector<WebIDBMetadata::Index>(metadata.indexes.size()); |
| 48 size_t i = 0; | 50 size_t i = 0; |
| 49 for (const auto& iter : metadata.indexes) | 51 for (const auto& iter : metadata.indexes) |
| 50 ConvertIndexMetadata(iter.second, &output->indexes[i++]); | 52 ConvertIndexMetadata(iter.second, &output->indexes[i++]); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void ConvertDatabaseMetadata(const content::IndexedDBDatabaseMetadata& metadata, | 55 void ConvertDatabaseMetadata(const content::IndexedDBDatabaseMetadata& metadata, |
| 54 WebIDBMetadata* output) { | 56 WebIDBMetadata* output) { |
| 55 output->id = metadata.id; | 57 output->id = metadata.id; |
| 56 output->name = metadata.name; | 58 output->name = WebString::fromUTF16(metadata.name); |
| 57 output->version = metadata.version; | 59 output->version = metadata.version; |
| 58 output->maxObjectStoreId = metadata.max_object_store_id; | 60 output->maxObjectStoreId = metadata.max_object_store_id; |
| 59 output->objectStores = | 61 output->objectStores = |
| 60 WebVector<WebIDBMetadata::ObjectStore>(metadata.object_stores.size()); | 62 WebVector<WebIDBMetadata::ObjectStore>(metadata.object_stores.size()); |
| 61 size_t i = 0; | 63 size_t i = 0; |
| 62 for (const auto& iter : metadata.object_stores) | 64 for (const auto& iter : metadata.object_stores) |
| 63 ConvertObjectStoreMetadata(iter.second, &output->objectStores[i++]); | 65 ConvertObjectStoreMetadata(iter.second, &output->objectStores[i++]); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void ConvertValue(const indexed_db::mojom::ValuePtr& value, | 68 void ConvertValue(const indexed_db::mojom::ValuePtr& value, |
| 67 WebIDBValue* web_value) { | 69 WebIDBValue* web_value) { |
| 68 if (value->bits.empty()) | 70 if (value->bits.empty()) |
| 69 return; | 71 return; |
| 70 | 72 |
| 71 blink::WebVector<WebBlobInfo> local_blob_info( | 73 blink::WebVector<WebBlobInfo> local_blob_info( |
| 72 value->blob_or_file_info.size()); | 74 value->blob_or_file_info.size()); |
| 73 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { | 75 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { |
| 74 const auto& info = value->blob_or_file_info[i]; | 76 const auto& info = value->blob_or_file_info[i]; |
| 75 if (info->file) { | 77 if (info->file) { |
| 76 local_blob_info[i] = WebBlobInfo( | 78 local_blob_info[i] = |
| 77 WebString::fromUTF8(info->uuid), info->file->path.AsUTF16Unsafe(), | 79 WebBlobInfo(WebString::fromUTF8(info->uuid), |
| 78 info->file->name, info->mime_type, | 80 blink::FilePathToWebString(info->file->path), |
| 79 info->file->last_modified.ToDoubleT(), info->size); | 81 WebString::fromUTF16(info->file->name), |
| 82 WebString::fromUTF16(info->mime_type), |
| 83 info->file->last_modified.ToDoubleT(), info->size); |
| 80 } else { | 84 } else { |
| 81 local_blob_info[i] = WebBlobInfo(WebString::fromUTF8(info->uuid), | 85 local_blob_info[i] = |
| 82 info->mime_type, info->size); | 86 WebBlobInfo(WebString::fromUTF8(info->uuid), |
| 87 WebString::fromUTF16(info->mime_type), info->size); |
| 83 } | 88 } |
| 84 } | 89 } |
| 85 | 90 |
| 86 web_value->data.assign(&*value->bits.begin(), value->bits.size()); | 91 web_value->data.assign(&*value->bits.begin(), value->bits.size()); |
| 87 web_value->webBlobInfo.swap(local_blob_info); | 92 web_value->webBlobInfo.swap(local_blob_info); |
| 88 } | 93 } |
| 89 | 94 |
| 90 void ConvertReturnValue(const indexed_db::mojom::ReturnValuePtr& value, | 95 void ConvertReturnValue(const indexed_db::mojom::ReturnValuePtr& value, |
| 91 WebIDBValue* web_value) { | 96 WebIDBValue* web_value) { |
| 92 ConvertValue(value->value, web_value); | 97 ConvertValue(value->value, web_value); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 239 } |
| 235 | 240 |
| 236 IndexedDBCallbacksImpl::InternalState::~InternalState() { | 241 IndexedDBCallbacksImpl::InternalState::~InternalState() { |
| 237 IndexedDBDispatcher::ThreadSpecificInstance()->UnregisterMojoOwnedCallbacks( | 242 IndexedDBDispatcher::ThreadSpecificInstance()->UnregisterMojoOwnedCallbacks( |
| 238 this); | 243 this); |
| 239 } | 244 } |
| 240 | 245 |
| 241 void IndexedDBCallbacksImpl::InternalState::Error( | 246 void IndexedDBCallbacksImpl::InternalState::Error( |
| 242 int32_t code, | 247 int32_t code, |
| 243 const base::string16& message) { | 248 const base::string16& message) { |
| 244 callbacks_->onError(blink::WebIDBDatabaseError(code, message)); | 249 callbacks_->onError( |
| 250 blink::WebIDBDatabaseError(code, WebString::fromUTF16(message))); |
| 245 callbacks_.reset(); | 251 callbacks_.reset(); |
| 246 } | 252 } |
| 247 | 253 |
| 248 void IndexedDBCallbacksImpl::InternalState::SuccessStringList( | 254 void IndexedDBCallbacksImpl::InternalState::SuccessStringList( |
| 249 const std::vector<base::string16>& value) { | 255 const std::vector<base::string16>& value) { |
| 250 callbacks_->onSuccess(WebVector<WebString>(value)); | 256 callbacks_->onSuccess(blink::CopyStringVectorFromUTF16(value)); |
| 251 callbacks_.reset(); | 257 callbacks_.reset(); |
| 252 } | 258 } |
| 253 | 259 |
| 254 void IndexedDBCallbacksImpl::InternalState::Blocked(int64_t existing_version) { | 260 void IndexedDBCallbacksImpl::InternalState::Blocked(int64_t existing_version) { |
| 255 callbacks_->onBlocked(existing_version); | 261 callbacks_->onBlocked(existing_version); |
| 256 // Not resetting |callbacks_|. | 262 // Not resetting |callbacks_|. |
| 257 } | 263 } |
| 258 | 264 |
| 259 void IndexedDBCallbacksImpl::InternalState::UpgradeNeeded( | 265 void IndexedDBCallbacksImpl::InternalState::UpgradeNeeded( |
| 260 DatabaseAssociatedPtrInfo database_info, | 266 DatabaseAssociatedPtrInfo database_info, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 callbacks_->onSuccess(value); | 361 callbacks_->onSuccess(value); |
| 356 callbacks_.reset(); | 362 callbacks_.reset(); |
| 357 } | 363 } |
| 358 | 364 |
| 359 void IndexedDBCallbacksImpl::InternalState::Success() { | 365 void IndexedDBCallbacksImpl::InternalState::Success() { |
| 360 callbacks_->onSuccess(); | 366 callbacks_->onSuccess(); |
| 361 callbacks_.reset(); | 367 callbacks_.reset(); |
| 362 } | 368 } |
| 363 | 369 |
| 364 } // namespace content | 370 } // namespace content |
| OLD | NEW |