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

Side by Side Diff: content/browser/dom_storage/local_storage_context_mojo.cc

Issue 2847013002: Switch to mojo localstorage backend by default. (Closed)
Patch Set: minor cleanup Created 3 years, 7 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
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/browser/dom_storage/local_storage_context_mojo.h" 5 #include "content/browser/dom_storage/local_storage_context_mojo.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // Queue this OpenLocalStorage call for when we have a level db pointer. 381 // Queue this OpenLocalStorage call for when we have a level db pointer.
382 on_database_opened_callbacks_.push_back(std::move(callback)); 382 on_database_opened_callbacks_.push_back(std::move(callback));
383 return; 383 return;
384 } 384 }
385 385
386 std::move(callback).Run(); 386 std::move(callback).Run();
387 } 387 }
388 388
389 void LocalStorageContextMojo::InitiateConnection(bool in_memory_only) { 389 void LocalStorageContextMojo::InitiateConnection(bool in_memory_only) {
390 DCHECK_EQ(connection_state_, CONNECTION_IN_PROGRESS); 390 DCHECK_EQ(connection_state_, CONNECTION_IN_PROGRESS);
391 CHECK(connector_); 391
392 // Unit tests might not always have a Connector, use in-memory only if that
393 // happens.
394 if (!connector_) {
395 OnDatabaseOpened(false, leveldb::mojom::DatabaseError::OK);
396 return;
397 }
398
392 if (!subdirectory_.empty() && !in_memory_only) { 399 if (!subdirectory_.empty() && !in_memory_only) {
393 // We were given a subdirectory to write to. Get it and use a disk backed 400 // We were given a subdirectory to write to. Get it and use a disk backed
394 // database. 401 // database.
395 connector_->BindInterface(file::mojom::kServiceName, &file_system_); 402 connector_->BindInterface(file::mojom::kServiceName, &file_system_);
396 file_system_->GetSubDirectory( 403 file_system_->GetSubDirectory(
397 subdirectory_.AsUTF8Unsafe(), MakeRequest(&directory_), 404 subdirectory_.AsUTF8Unsafe(), MakeRequest(&directory_),
398 base::Bind(&LocalStorageContextMojo::OnDirectoryOpened, 405 base::Bind(&LocalStorageContextMojo::OnDirectoryOpened,
399 weak_ptr_factory_.GetWeakPtr())); 406 weak_ptr_factory_.GetWeakPtr()));
400 } else { 407 } else {
401 // We were not given a subdirectory. Use a memory backed database. 408 // We were not given a subdirectory. Use a memory backed database.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 return found->second->level_db_wrapper(); 607 return found->second->level_db_wrapper();
601 608
602 auto holder = base::MakeUnique<LevelDBWrapperHolder>(this, origin); 609 auto holder = base::MakeUnique<LevelDBWrapperHolder>(this, origin);
603 LevelDBWrapperImpl* wrapper_ptr = holder->level_db_wrapper(); 610 LevelDBWrapperImpl* wrapper_ptr = holder->level_db_wrapper();
604 level_db_wrappers_[origin] = std::move(holder); 611 level_db_wrappers_[origin] = std::move(holder);
605 return wrapper_ptr; 612 return wrapper_ptr;
606 } 613 }
607 614
608 void LocalStorageContextMojo::RetrieveStorageUsage( 615 void LocalStorageContextMojo::RetrieveStorageUsage(
609 GetStorageUsageCallback callback) { 616 GetStorageUsageCallback callback) {
617 if (!database_) {
618 // If for whatever reason no leveldb database is available, no storage is
619 // used, so return an empty array.
620 std::move(callback).Run(std::vector<LocalStorageUsageInfo>());
621 return;
622 }
623
610 database_->GetPrefixed( 624 database_->GetPrefixed(
611 std::vector<uint8_t>(kMetaPrefix, kMetaPrefix + arraysize(kMetaPrefix)), 625 std::vector<uint8_t>(kMetaPrefix, kMetaPrefix + arraysize(kMetaPrefix)),
612 base::Bind(&LocalStorageContextMojo::OnGotMetaData, 626 base::Bind(&LocalStorageContextMojo::OnGotMetaData,
613 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); 627 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
614 } 628 }
615 629
616 void LocalStorageContextMojo::OnGotMetaData( 630 void LocalStorageContextMojo::OnGotMetaData(
617 GetStorageUsageCallback callback, 631 GetStorageUsageCallback callback,
618 leveldb::mojom::DatabaseError status, 632 leveldb::mojom::DatabaseError status,
619 std::vector<leveldb::mojom::KeyValuePtr> data) { 633 std::vector<leveldb::mojom::KeyValuePtr> data) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 OnShutdownComplete(leveldb::mojom::DatabaseError::OK); 686 OnShutdownComplete(leveldb::mojom::DatabaseError::OK);
673 } 687 }
674 } 688 }
675 689
676 void LocalStorageContextMojo::OnShutdownComplete( 690 void LocalStorageContextMojo::OnShutdownComplete(
677 leveldb::mojom::DatabaseError error) { 691 leveldb::mojom::DatabaseError error) {
678 delete this; 692 delete this;
679 } 693 }
680 694
681 } // namespace content 695 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698