Chromium Code Reviews| 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/renderer/dom_storage/local_storage_cached_area.h" | 5 #include "content/renderer/dom_storage/local_storage_cached_area.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/common/dom_storage/dom_storage_map.h" | 15 #include "content/common/dom_storage/dom_storage_map.h" |
| 16 #include "content/common/storage_partition_service.mojom.h" | 16 #include "content/common/storage_partition_service.mojom.h" |
| 17 #include "content/renderer/dom_storage/local_storage_area.h" | 17 #include "content/renderer/dom_storage/local_storage_area.h" |
| 18 #include "content/renderer/dom_storage/local_storage_cached_areas.h" | 18 #include "content/renderer/dom_storage/local_storage_cached_areas.h" |
| 19 #include "mojo/public/cpp/bindings/strong_associated_binding.h" | 19 #include "mojo/public/cpp/bindings/strong_associated_binding.h" |
| 20 #include "third_party/WebKit/public/platform/WebURL.h" | 20 #include "third_party/WebKit/public/platform/WebURL.h" |
| 21 #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" | 21 #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // Don't change or reorder any of the values in this enum, as these values | |
| 28 // are serialized on disk. | |
| 29 enum class StorageFormat : uint8_t { UTF16 = 0 }; | |
| 30 | |
| 27 base::string16 Uint8VectorToString16(const std::vector<uint8_t>& input) { | 31 base::string16 Uint8VectorToString16(const std::vector<uint8_t>& input) { |
| 28 return base::string16(reinterpret_cast<const base::char16*>(input.data()), | 32 CHECK(input.size() % sizeof(base::char16) == 1); |
| 29 input.size() / sizeof(base::char16)); | 33 CHECK_EQ(input[0], static_cast<uint8_t>(StorageFormat::UTF16)); |
|
michaeln
2017/03/18 01:00:30
Not sure we should crash the renderer here? Most u
Marijn Kruisselbrink
2017/03/21 23:16:29
Or compromised renderers, yes. So yeah, crashing t
| |
| 34 base::string16 result; | |
| 35 result.resize(input.size() / sizeof(base::char16)); | |
| 36 std::memcpy(reinterpret_cast<void*>(&result[0]), input.data() + 1, | |
|
michaeln
2017/03/18 01:00:30
is there a reason to use memcpy instead of a strin
Marijn Kruisselbrink
2017/03/21 23:16:29
I believe that using a string16 ctor directly woul
| |
| 37 input.size() - 1); | |
| 38 return result; | |
| 30 } | 39 } |
| 31 | 40 |
| 32 std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) { | 41 std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) { |
| 33 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data()); | 42 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data()); |
| 34 return std::vector<uint8_t>(data, data + input.size() * sizeof(base::char16)); | 43 std::vector<uint8_t> result; |
| 44 result.reserve(input.size() * sizeof(base::char16) + 1); | |
| 45 result.push_back(static_cast<uint8_t>(StorageFormat::UTF16)); | |
| 46 result.insert(result.end(), data, data + input.size() * sizeof(base::char16)); | |
| 47 return result; | |
| 35 } | 48 } |
| 36 | 49 |
| 37 class GetAllCallback : public mojom::LevelDBWrapperGetAllCallback { | 50 class GetAllCallback : public mojom::LevelDBWrapperGetAllCallback { |
| 38 public: | 51 public: |
| 39 static mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo CreateAndBind( | 52 static mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo CreateAndBind( |
| 40 const base::Callback<void(bool)>& callback) { | 53 const base::Callback<void(bool)>& callback) { |
| 41 mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo ptr_info; | 54 mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo ptr_info; |
| 42 auto request = mojo::MakeRequest(&ptr_info); | 55 auto request = mojo::MakeRequest(&ptr_info); |
| 43 mojo::MakeStrongAssociatedBinding( | 56 mojo::MakeStrongAssociatedBinding( |
| 44 base::WrapUnique(new GetAllCallback(callback)), std::move(request)); | 57 base::WrapUnique(new GetAllCallback(callback)), std::move(request)); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 } | 373 } |
| 361 | 374 |
| 362 void LocalStorageCachedArea::Reset() { | 375 void LocalStorageCachedArea::Reset() { |
| 363 map_ = NULL; | 376 map_ = NULL; |
| 364 ignore_key_mutations_.clear(); | 377 ignore_key_mutations_.clear(); |
| 365 ignore_all_mutations_ = false; | 378 ignore_all_mutations_ = false; |
| 366 weak_factory_.InvalidateWeakPtrs(); | 379 weak_factory_.InvalidateWeakPtrs(); |
| 367 } | 380 } |
| 368 | 381 |
| 369 } // namespace content | 382 } // namespace content |
| OLD | NEW |