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

Side by Side Diff: components/sync/engine/attachments/on_disk_attachment_store.cc

Issue 2953473002: Use leveldb_env::OpenDB() to open leveldb databases. (Closed)
Patch Set: Rebase; add comments to CHECK() Created 3 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/sync/engine/attachments/on_disk_attachment_store.h" 5 #include "components/sync/engine/attachments/on_disk_attachment_store.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 352 }
353 353
354 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list))); 354 PostCallback(base::Bind(callback, result_code, base::Passed(&metadata_list)));
355 } 355 }
356 356
357 AttachmentStore::Result OnDiskAttachmentStore::OpenOrCreate( 357 AttachmentStore::Result OnDiskAttachmentStore::OpenOrCreate(
358 const base::FilePath& path) { 358 const base::FilePath& path) {
359 DCHECK(!db_); 359 DCHECK(!db_);
360 base::FilePath leveldb_path = path.Append(kLeveldbDirectory); 360 base::FilePath leveldb_path = path.Append(kLeveldbDirectory);
361 361
362 leveldb::DB* db_raw;
363 std::unique_ptr<leveldb::DB> db; 362 std::unique_ptr<leveldb::DB> db;
364 leveldb::Options options; 363 leveldb::Options options;
365 options.create_if_missing = true; 364 options.create_if_missing = true;
366 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue; 365 options.reuse_logs = leveldb_env::kDefaultLogReuseOptionValue;
367 // TODO(pavely): crbug/424287 Consider adding info_log, block_cache and 366 // TODO(pavely): crbug/424287 Consider adding info_log, block_cache and
368 // filter_policy to options. 367 // filter_policy to options.
369 leveldb::Status status = 368 leveldb::Status status =
370 leveldb::DB::Open(options, leveldb_path.AsUTF8Unsafe(), &db_raw); 369 leveldb_env::OpenDB(options, leveldb_path.AsUTF8Unsafe(), &db);
371 if (!status.ok()) { 370 if (!status.ok()) {
372 DVLOG(1) << "DB::Open failed: status=" << status.ToString() 371 DVLOG(1) << "OpenDB failed: status=" << status.ToString()
373 << ", path=" << path.AsUTF8Unsafe(); 372 << ", path=" << path.AsUTF8Unsafe();
374 return AttachmentStore::UNSPECIFIED_ERROR; 373 return AttachmentStore::UNSPECIFIED_ERROR;
375 } 374 }
376 375
377 db.reset(db_raw);
378
379 attachment_store_pb::StoreMetadata metadata; 376 attachment_store_pb::StoreMetadata metadata;
380 status = ReadStoreMetadata(db.get(), &metadata); 377 status = ReadStoreMetadata(db.get(), &metadata);
381 if (!status.ok() && !status.IsNotFound()) { 378 if (!status.ok() && !status.IsNotFound()) {
382 DVLOG(1) << "ReadStoreMetadata failed: status=" << status.ToString(); 379 DVLOG(1) << "ReadStoreMetadata failed: status=" << status.ToString();
383 return AttachmentStore::UNSPECIFIED_ERROR; 380 return AttachmentStore::UNSPECIFIED_ERROR;
384 } 381 }
385 if (status.IsNotFound()) { 382 if (status.IsNotFound()) {
386 // Brand new database. 383 // Brand new database.
387 metadata.set_schema_version(kCurrentSchemaVersion); 384 metadata.set_schema_version(kCurrentSchemaVersion);
388 status = WriteStoreMetadata(db.get(), metadata); 385 status = WriteStoreMetadata(db.get(), metadata);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 return key; 530 return key;
534 } 531 }
535 532
536 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata( 533 AttachmentMetadata OnDiskAttachmentStore::MakeAttachmentMetadata(
537 const AttachmentId& attachment_id, 534 const AttachmentId& attachment_id,
538 const attachment_store_pb::RecordMetadata& record_metadata) { 535 const attachment_store_pb::RecordMetadata& record_metadata) {
539 return AttachmentMetadata(attachment_id, record_metadata.attachment_size()); 536 return AttachmentMetadata(attachment_id, record_metadata.attachment_size());
540 } 537 }
541 538
542 } // namespace syncer 539 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698