| 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/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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "components/leveldb/public/cpp/util.h" | 10 #include "components/leveldb/public/cpp/util.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // database. | 331 // database. |
| 332 file_service_connection_->GetInterface(&file_system_); | 332 file_service_connection_->GetInterface(&file_system_); |
| 333 file_system_->GetSubDirectory( | 333 file_system_->GetSubDirectory( |
| 334 subdirectory_.AsUTF8Unsafe(), MakeRequest(&directory_), | 334 subdirectory_.AsUTF8Unsafe(), MakeRequest(&directory_), |
| 335 base::Bind(&LocalStorageContextMojo::OnDirectoryOpened, | 335 base::Bind(&LocalStorageContextMojo::OnDirectoryOpened, |
| 336 weak_ptr_factory_.GetWeakPtr())); | 336 weak_ptr_factory_.GetWeakPtr())); |
| 337 } else { | 337 } else { |
| 338 // We were not given a subdirectory. Use a memory backed database. | 338 // We were not given a subdirectory. Use a memory backed database. |
| 339 file_service_connection_->GetInterface(&leveldb_service_); | 339 file_service_connection_->GetInterface(&leveldb_service_); |
| 340 leveldb_service_->OpenInMemory( | 340 leveldb_service_->OpenInMemory( |
| 341 MakeRequest(&database_, leveldb_service_.associated_group()), | 341 MakeRequest(&database_), |
| 342 base::Bind(&LocalStorageContextMojo::OnDatabaseOpened, | 342 base::Bind(&LocalStorageContextMojo::OnDatabaseOpened, |
| 343 weak_ptr_factory_.GetWeakPtr(), true)); | 343 weak_ptr_factory_.GetWeakPtr(), true)); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 void LocalStorageContextMojo::OnDirectoryOpened( | 347 void LocalStorageContextMojo::OnDirectoryOpened( |
| 348 filesystem::mojom::FileError err) { | 348 filesystem::mojom::FileError err) { |
| 349 if (err != filesystem::mojom::FileError::OK) { | 349 if (err != filesystem::mojom::FileError::OK) { |
| 350 // We failed to open the directory; continue with startup so that we create | 350 // We failed to open the directory; continue with startup so that we create |
| 351 // the |level_db_wrappers_|. | 351 // the |level_db_wrappers_|. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 366 leveldb_service_->SetEnvironmentName("LevelDBEnv.LocalStorage"); | 366 leveldb_service_->SetEnvironmentName("LevelDBEnv.LocalStorage"); |
| 367 | 367 |
| 368 // We might still need to use the directory, so create a clone. | 368 // We might still need to use the directory, so create a clone. |
| 369 filesystem::mojom::DirectoryPtr directory_clone; | 369 filesystem::mojom::DirectoryPtr directory_clone; |
| 370 directory_->Clone(MakeRequest(&directory_clone)); | 370 directory_->Clone(MakeRequest(&directory_clone)); |
| 371 | 371 |
| 372 auto options = leveldb::mojom::OpenOptions::New(); | 372 auto options = leveldb::mojom::OpenOptions::New(); |
| 373 options->create_if_missing = true; | 373 options->create_if_missing = true; |
| 374 leveldb_service_->OpenWithOptions( | 374 leveldb_service_->OpenWithOptions( |
| 375 std::move(options), std::move(directory_clone), "leveldb", | 375 std::move(options), std::move(directory_clone), "leveldb", |
| 376 MakeRequest(&database_, leveldb_service_.associated_group()), | 376 MakeRequest(&database_), |
| 377 base::Bind(&LocalStorageContextMojo::OnDatabaseOpened, | 377 base::Bind(&LocalStorageContextMojo::OnDatabaseOpened, |
| 378 weak_ptr_factory_.GetWeakPtr(), false)); | 378 weak_ptr_factory_.GetWeakPtr(), false)); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void LocalStorageContextMojo::OnDatabaseOpened( | 381 void LocalStorageContextMojo::OnDatabaseOpened( |
| 382 bool in_memory, | 382 bool in_memory, |
| 383 leveldb::mojom::DatabaseError status) { | 383 leveldb::mojom::DatabaseError status) { |
| 384 if (status != leveldb::mojom::DatabaseError::OK) { | 384 if (status != leveldb::mojom::DatabaseError::OK) { |
| 385 UMA_HISTOGRAM_ENUMERATION("LocalStorageContext.DatabaseOpenError", | 385 UMA_HISTOGRAM_ENUMERATION("LocalStorageContext.DatabaseOpenError", |
| 386 leveldb::GetLevelDBStatusUMAValue(status), | 386 leveldb::GetLevelDBStatusUMAValue(status), |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 for (const auto& info : usage) { | 584 for (const auto& info : usage) { |
| 585 url::Origin origin_candidate(info.origin); | 585 url::Origin origin_candidate(info.origin); |
| 586 if (!origin_candidate.IsSameOriginWith(origin) && | 586 if (!origin_candidate.IsSameOriginWith(origin) && |
| 587 origin_candidate.IsSamePhysicalOriginWith(origin)) | 587 origin_candidate.IsSamePhysicalOriginWith(origin)) |
| 588 DeleteStorage(origin_candidate); | 588 DeleteStorage(origin_candidate); |
| 589 } | 589 } |
| 590 DeleteStorage(origin); | 590 DeleteStorage(origin); |
| 591 } | 591 } |
| 592 | 592 |
| 593 } // namespace content | 593 } // namespace content |
| OLD | NEW |