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

Side by Side Diff: components/sync/engine/attachments/on_disk_attachment_store_unittest.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
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "components/sync/engine/attachments/attachment_store_test_template.h" 18 #include "components/sync/engine/attachments/attachment_store_test_template.h"
19 #include "components/sync/engine_impl/attachments/proto/attachment_store.pb.h" 19 #include "components/sync/engine_impl/attachments/proto/attachment_store.pb.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/leveldatabase/env_chromium.h"
22 #include "third_party/leveldatabase/src/include/leveldb/db.h" 23 #include "third_party/leveldatabase/src/include/leveldb/db.h"
23 #include "third_party/leveldatabase/src/include/leveldb/options.h" 24 #include "third_party/leveldatabase/src/include/leveldb/options.h"
24 #include "third_party/leveldatabase/src/include/leveldb/slice.h" 25 #include "third_party/leveldatabase/src/include/leveldb/slice.h"
25 #include "third_party/leveldatabase/src/include/leveldb/status.h" 26 #include "third_party/leveldatabase/src/include/leveldb/status.h"
26 27
27 namespace syncer { 28 namespace syncer {
28 29
29 namespace { 30 namespace {
30 31
31 void AttachmentStoreCreated(AttachmentStore::Result* result_dest, 32 void AttachmentStoreCreated(AttachmentStore::Result* result_dest,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 void CopyResultMetadata( 97 void CopyResultMetadata(
97 AttachmentStore::Result* destination_result, 98 AttachmentStore::Result* destination_result,
98 std::unique_ptr<AttachmentMetadataList>* destination_metadata, 99 std::unique_ptr<AttachmentMetadataList>* destination_metadata,
99 const AttachmentStore::Result& source_result, 100 const AttachmentStore::Result& source_result,
100 std::unique_ptr<AttachmentMetadataList> source_metadata) { 101 std::unique_ptr<AttachmentMetadataList> source_metadata) {
101 CopyResult(destination_result, source_result); 102 CopyResult(destination_result, source_result);
102 *destination_metadata = std::move(source_metadata); 103 *destination_metadata = std::move(source_metadata);
103 } 104 }
104 105
105 std::unique_ptr<leveldb::DB> OpenLevelDB() { 106 std::unique_ptr<leveldb::DB> OpenLevelDB() {
106 leveldb::DB* db; 107 std::unique_ptr<leveldb::DB> db;
107 leveldb::Options options; 108 leveldb::Options options;
108 options.create_if_missing = true; 109 options.create_if_missing = true;
109 leveldb::Status s = 110 leveldb::Status s =
110 leveldb::DB::Open(options, db_path_.AsUTF8Unsafe(), &db); 111 leveldb_env::OpenDB(options, db_path_.AsUTF8Unsafe(), &db);
111 EXPECT_TRUE(s.ok()); 112 EXPECT_TRUE(s.ok());
112 return base::WrapUnique(db); 113 return db;
113 } 114 }
114 115
115 void UpdateRecord(const std::string& key, const std::string& content) { 116 void UpdateRecord(const std::string& key, const std::string& content) {
116 std::unique_ptr<leveldb::DB> db = OpenLevelDB(); 117 std::unique_ptr<leveldb::DB> db = OpenLevelDB();
117 leveldb::Status s = db->Put(leveldb::WriteOptions(), key, content); 118 leveldb::Status s = db->Put(leveldb::WriteOptions(), key, content);
118 EXPECT_TRUE(s.ok()); 119 EXPECT_TRUE(s.ok());
119 } 120 }
120 121
121 void UpdateStoreMetadataRecord(const std::string& content) { 122 void UpdateStoreMetadataRecord(const std::string& content) {
122 UpdateRecord("database-metadata", content); 123 UpdateRecord("database-metadata", content);
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 store_->ReadMetadata( 513 store_->ReadMetadata(
513 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultMetadata, 514 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultMetadata,
514 base::Unretained(this), &metadata_result, &metadata_list)); 515 base::Unretained(this), &metadata_result, &metadata_list));
515 RunLoop(); 516 RunLoop();
516 EXPECT_EQ(AttachmentStore::SUCCESS, create_result); 517 EXPECT_EQ(AttachmentStore::SUCCESS, create_result);
517 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, metadata_result); 518 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, metadata_result);
518 EXPECT_EQ(2U, metadata_list->size()); 519 EXPECT_EQ(2U, metadata_list->size());
519 } 520 }
520 521
521 } // namespace syncer 522 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/engine/attachments/on_disk_attachment_store.cc ('k') | components/sync/model_impl/model_type_store_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698