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

Unified Diff: content/browser/dom_storage/local_storage_context_mojo.cc

Issue 2767103002: Fix localstorage data migration. (Closed)
Patch Set: share one encoding function 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/dom_storage/local_storage_context_mojo.cc
diff --git a/content/browser/dom_storage/local_storage_context_mojo.cc b/content/browser/dom_storage/local_storage_context_mojo.cc
index 6cc0c76f6b6e2d9ff749ead7c50cbf3e5b2092b0..1bbd8d30c93d864371d5377708dc9092d2284dc4 100644
--- a/content/browser/dom_storage/local_storage_context_mojo.cc
+++ b/content/browser/dom_storage/local_storage_context_mojo.cc
@@ -68,11 +68,6 @@ std::vector<uint8_t> CreateMetaDataKey(const url::Origin& origin) {
void NoOpSuccess(bool success) {}
-std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) {
- const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data());
- return std::vector<uint8_t>(data, data + input.size() * sizeof(base::char16));
-}
-
void MigrateStorageHelper(
base::FilePath db_path,
const scoped_refptr<base::SingleThreadTaskRunner> reply_task_runner,
@@ -83,8 +78,8 @@ void MigrateStorageHelper(
db.ReadAllValues(&map);
auto values = base::MakeUnique<LevelDBWrapperImpl::ValueMap>();
for (const auto& it : map) {
- (*values)[String16ToUint8Vector(it.first)] =
- String16ToUint8Vector(it.second.string());
+ (*values)[LocalStorageContextMojo::MigrateString(it.first)] =
+ LocalStorageContextMojo::MigrateString(it.second.string());
}
reply_task_runner->PostTask(FROM_HERE,
base::Bind(callback, base::Passed(&values)));
@@ -295,6 +290,19 @@ LocalStorageContextMojo::DatabaseRequestForTesting() {
return request;
}
+// static
+std::vector<uint8_t> LocalStorageContextMojo::MigrateString(
+ const base::string16& input) {
+ static const uint8_t kUTF16Format = 0;
+
+ const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data());
+ std::vector<uint8_t> result;
+ result.reserve(input.size() * sizeof(base::char16) + 1);
+ result.push_back(kUTF16Format);
+ result.insert(result.end(), data, data + input.size() * sizeof(base::char16));
+ return result;
+}
+
void LocalStorageContextMojo::RunWhenConnected(base::OnceClosure callback) {
// If we don't have a filesystem_connection_, we'll need to establish one.
if (connection_state_ == NO_CONNECTION) {

Powered by Google App Engine
This is Rietveld 408576698