| OLD | NEW | 
|    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 "chrome/browser/sync_file_system/drive_backend/metadata_database_index.
     h" |    5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database_index.
     h" | 
|    6  |    6  | 
|    7 #include <stdint.h> |    7 #include <stdint.h> | 
|    8  |    8  | 
|    9 #include <utility> |    9 #include <utility> | 
|   10  |   10  | 
|   11 #include "base/memory/ptr_util.h" |   11 #include "base/memory/ptr_util.h" | 
|   12 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
     h" |   12 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.
     h" | 
|   13 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_test_util.
     h" |   13 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_test_util.
     h" | 
|   14 #include "chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.h" |   14 #include "chrome/browser/sync_file_system/drive_backend/leveldb_wrapper.h" | 
|   15 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" |   15 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" | 
|   16 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" |   16 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" | 
|   17 #include "testing/gtest/include/gtest/gtest.h" |   17 #include "testing/gtest/include/gtest/gtest.h" | 
 |   18 #include "third_party/leveldatabase/env_chromium.h" | 
|   18 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |   19 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 
|   19 #include "third_party/leveldatabase/src/include/leveldb/db.h" |   20 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 
|   20 #include "third_party/leveldatabase/src/include/leveldb/env.h" |   21 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 
|   21  |   22  | 
|   22 namespace sync_file_system { |   23 namespace sync_file_system { | 
|   23 namespace drive_backend { |   24 namespace drive_backend { | 
|   24  |   25  | 
|   25 namespace { |   26 namespace { | 
|   26  |   27  | 
|   27 const int64_t kSyncRootTrackerID = 1; |   28 const int64_t kSyncRootTrackerID = 1; | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   74  |   75  | 
|   75     contents_ = CreateTestDatabaseContents(); |   76     contents_ = CreateTestDatabaseContents(); | 
|   76     index_ = MetadataDatabaseIndex::CreateForTesting(contents_.get(), |   77     index_ = MetadataDatabaseIndex::CreateForTesting(contents_.get(), | 
|   77                                                      db_.get()); |   78                                                      db_.get()); | 
|   78   } |   79   } | 
|   79  |   80  | 
|   80   MetadataDatabaseIndex* index() { return index_.get(); } |   81   MetadataDatabaseIndex* index() { return index_.get(); } | 
|   81  |   82  | 
|   82  private: |   83  private: | 
|   83   void InitializeLevelDB() { |   84   void InitializeLevelDB() { | 
|   84     leveldb::DB* db = nullptr; |   85     std::unique_ptr<leveldb::DB> db; | 
|   85     leveldb::Options options; |   86     leveldb::Options options; | 
|   86     options.create_if_missing = true; |   87     options.create_if_missing = true; | 
|   87     options.max_open_files = 0;  // Use minimum. |   88     options.max_open_files = 0;  // Use minimum. | 
|   88     options.env = in_memory_env_.get(); |   89     options.env = in_memory_env_.get(); | 
|   89     leveldb::Status status = leveldb::DB::Open(options, "", &db); |   90     leveldb::Status status = leveldb_env::OpenDB(options, "", &db); | 
|   90     ASSERT_TRUE(status.ok()); |   91     ASSERT_TRUE(status.ok()); | 
|   91  |   92  | 
|   92     db_.reset(new LevelDBWrapper(base::WrapUnique(db))); |   93     db_.reset(new LevelDBWrapper(std::move(db))); | 
|   93   } |   94   } | 
|   94  |   95  | 
|   95   std::unique_ptr<DatabaseContents> contents_; |   96   std::unique_ptr<DatabaseContents> contents_; | 
|   96   std::unique_ptr<MetadataDatabaseIndex> index_; |   97   std::unique_ptr<MetadataDatabaseIndex> index_; | 
|   97  |   98  | 
|   98   std::unique_ptr<leveldb::Env> in_memory_env_; |   99   std::unique_ptr<leveldb::Env> in_memory_env_; | 
|   99   std::unique_ptr<LevelDBWrapper> db_; |  100   std::unique_ptr<LevelDBWrapper> db_; | 
|  100 }; |  101 }; | 
|  101  |  102  | 
|  102 TEST_F(MetadataDatabaseIndexTest, GetEntryTest) { |  103 TEST_F(MetadataDatabaseIndexTest, GetEntryTest) { | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  158  |  159  | 
|  159   index()->RemoveFileMetadata("file_id"); |  160   index()->RemoveFileMetadata("file_id"); | 
|  160   index()->RemoveFileTracker(kFileTrackerID); |  161   index()->RemoveFileTracker(kFileTrackerID); | 
|  161  |  162  | 
|  162   EXPECT_FALSE(index()->GetFileMetadata("file_id", nullptr)); |  163   EXPECT_FALSE(index()->GetFileMetadata("file_id", nullptr)); | 
|  163   EXPECT_FALSE(index()->GetFileTracker(kFileTrackerID, nullptr)); |  164   EXPECT_FALSE(index()->GetFileTracker(kFileTrackerID, nullptr)); | 
|  164 } |  165 } | 
|  165  |  166  | 
|  166 }  // namespace drive_backend |  167 }  // namespace drive_backend | 
|  167 }  // namespace sync_file_system |  168 }  // namespace sync_file_system | 
| OLD | NEW |