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