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

Side by Side Diff: content/renderer/dom_storage/local_storage_cached_area.cc

Issue 2748023008: Future-proof data format used for LocalStorage. (Closed)
Patch Set: no CHECK, just silently ignore broken data for now Created 3 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO(mek): Better error recovery when corrupt (or otherwise invalid) data
29 input.size() / sizeof(base::char16)); 33 // is detected.
34 if (input.size() % sizeof(base::char16) != 1 ||
35 input[0] != static_cast<uint8_t>(StorageFormat::UTF16)) {
36 VLOG(1) << "Corrupt data in localstorage";
37 return base::string16();
38 }
39 base::string16 result;
40 result.resize(input.size() / sizeof(base::char16));
41 std::memcpy(reinterpret_cast<void*>(&result[0]), input.data() + 1,
42 input.size() - 1);
43 return result;
30 } 44 }
31 45
32 std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) { 46 std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) {
33 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data()); 47 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data());
34 return std::vector<uint8_t>(data, data + input.size() * sizeof(base::char16)); 48 std::vector<uint8_t> result;
49 result.reserve(input.size() * sizeof(base::char16) + 1);
50 result.push_back(static_cast<uint8_t>(StorageFormat::UTF16));
51 result.insert(result.end(), data, data + input.size() * sizeof(base::char16));
52 return result;
35 } 53 }
36 54
37 class GetAllCallback : public mojom::LevelDBWrapperGetAllCallback { 55 class GetAllCallback : public mojom::LevelDBWrapperGetAllCallback {
38 public: 56 public:
39 static mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo CreateAndBind( 57 static mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo CreateAndBind(
40 const base::Callback<void(bool)>& callback) { 58 const base::Callback<void(bool)>& callback) {
41 mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo ptr_info; 59 mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo ptr_info;
42 auto request = mojo::MakeRequest(&ptr_info); 60 auto request = mojo::MakeRequest(&ptr_info);
43 mojo::MakeStrongAssociatedBinding( 61 mojo::MakeStrongAssociatedBinding(
44 base::WrapUnique(new GetAllCallback(callback)), std::move(request)); 62 base::WrapUnique(new GetAllCallback(callback)), std::move(request));
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 378 }
361 379
362 void LocalStorageCachedArea::Reset() { 380 void LocalStorageCachedArea::Reset() {
363 map_ = NULL; 381 map_ = NULL;
364 ignore_key_mutations_.clear(); 382 ignore_key_mutations_.clear();
365 ignore_all_mutations_ = false; 383 ignore_all_mutations_ = false;
366 weak_factory_.InvalidateWeakPtrs(); 384 weak_factory_.InvalidateWeakPtrs();
367 } 385 }
368 386
369 } // namespace content 387 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698