Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ |
| 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 | |
| 8 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/memory/weak_ptr.h" | |
| 11 #include "webkit/browser/fileapi/syncable/sync_callbacks.h" | 14 #include "webkit/browser/fileapi/syncable/sync_callbacks.h" |
| 12 #include "webkit/browser/fileapi/syncable/sync_status_code.h" | 15 #include "webkit/browser/fileapi/syncable/sync_status_code.h" |
| 13 | 16 |
| 14 namespace base { | 17 namespace base { |
| 15 class FilePath; | 18 class FilePath; |
| 16 class SequencedTaskRunner; | 19 class SequencedTaskRunner; |
| 17 } | 20 } |
| 18 | 21 |
| 19 namespace leveldb { | 22 namespace leveldb { |
| 20 class DB; | 23 class DB; |
| 21 class WriteBatch; | 24 class WriteBatch; |
| 22 } | 25 } |
| 23 | 26 |
| 24 namespace google_apis { | 27 namespace google_apis { |
| 25 class ChangeResource; | 28 class ChangeResource; |
| 26 class FileResource; | 29 class FileResource; |
| 27 class ResourceEntry; | 30 class ResourceEntry; |
| 28 } | 31 } |
| 29 | 32 |
| 30 namespace sync_file_system { | 33 namespace sync_file_system { |
| 31 namespace drive_backend { | 34 namespace drive_backend { |
| 32 | 35 |
| 33 class ServiceMetadata; | 36 class ServiceMetadata; |
| 34 class DriveFileMetadata; | 37 class DriveFileMetadata; |
| 35 struct InitializeInfo; | |
| 36 | 38 |
| 37 // This class holds a snapshot of the server side metadata. | 39 // This class holds a snapshot of the server side metadata. |
| 38 class MetadataDatabase { | 40 class MetadataDatabase { |
| 39 public: | 41 public: |
| 42 struct FileIDComparator { | |
|
kinuko
2013/07/04 15:59:11
can't these typenames be kept private?
tzik
2013/07/05 07:42:28
Done.
| |
| 43 bool operator()(DriveFileMetadata* left, DriveFileMetadata* right); | |
| 44 }; | |
| 45 | |
| 46 typedef std::set<DriveFileMetadata*, FileIDComparator> FileSet; | |
| 47 typedef std::map<std::string, DriveFileMetadata*> FileByFileID; | |
| 48 typedef std::map<std::string, FileSet> FilesByParent; | |
| 49 typedef std::map<std::pair<std::string, std::string>, DriveFileMetadata*> | |
| 50 FileByParentAndTitle; | |
| 51 typedef std::map<std::string, DriveFileMetadata*> FileByAppID; | |
| 52 | |
| 53 struct InitializeInfo { | |
| 54 SyncStatusCode status; | |
| 55 scoped_ptr<leveldb::DB> db; | |
| 56 | |
| 57 scoped_ptr<ServiceMetadata> service_metadata; | |
| 58 ScopedVector<DriveFileMetadata> file_metadata; | |
| 59 | |
| 60 FileByFileID file_by_file_id; | |
| 61 FilesByParent files_by_parent; | |
| 62 FileByAppID app_root_by_app_id; | |
| 63 FileByParentAndTitle active_file_by_parent_and_title; | |
|
kinuko
2013/07/04 15:59:11
Is there a chance we could simplify some initializ
tzik
2013/07/05 07:42:28
Done.
| |
| 64 | |
| 65 bool created; | |
| 66 | |
| 67 InitializeInfo(); | |
| 68 ~InitializeInfo(); | |
| 69 }; | |
| 70 | |
| 40 explicit MetadataDatabase(base::SequencedTaskRunner* task_runner); | 71 explicit MetadataDatabase(base::SequencedTaskRunner* task_runner); |
| 41 ~MetadataDatabase(); | 72 ~MetadataDatabase(); |
| 42 | 73 |
| 43 // Initializes the internal database and loads its content to memory. | 74 // Initializes the internal database and loads its content to memory. |
| 44 // This function works asynchronously. | 75 // This function works asynchronously. |
|
kinuko
2013/07/04 15:59:11
nit: its async-ness seems obvious from the signatu
tzik
2013/07/05 07:42:28
Done.
| |
| 45 void Initialize(const base::FilePath& database_path, | 76 void Initialize(const base::FilePath& database_path, |
| 46 const SyncStatusCallback& callback); | 77 const SyncStatusCallback& callback); |
| 47 | 78 |
| 48 int64 GetLargestChangeID() const; | 79 int64 GetLargestChangeID() const; |
| 49 | 80 |
| 50 // Registers existing folder as the app-root for |app_id|. The folder | 81 // Registers existing folder as the app-root for |app_id|. The folder |
| 51 // must be an inactive folder that does not yet associated to any App. | 82 // must be an inactive folder that does not yet associated to any App. |
| 52 // This method associates the folder with |app_id| and activates it. | 83 // This method associates the folder with |app_id| and activates it. |
| 53 void RegisterApp(const std::string& app_id, | 84 void RegisterApp(const std::string& app_id, |
| 54 const std::string& folder_id, | 85 const std::string& folder_id, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 void UpdateByChangeList(ScopedVector<google_apis::ChangeResource> changes, | 148 void UpdateByChangeList(ScopedVector<google_apis::ChangeResource> changes, |
| 118 const SyncStatusCallback& callback); | 149 const SyncStatusCallback& callback); |
| 119 | 150 |
| 120 // Populates |folder| with |children|. Each |children| initially has empty | 151 // Populates |folder| with |children|. Each |children| initially has empty |
| 121 // |synced_details| and |remote_details|. | 152 // |synced_details| and |remote_details|. |
| 122 void PopulateFolder(const std::string& folder_id, | 153 void PopulateFolder(const std::string& folder_id, |
| 123 ScopedVector<google_apis::ResourceEntry> children, | 154 ScopedVector<google_apis::ResourceEntry> children, |
| 124 const SyncStatusCallback& callback); | 155 const SyncStatusCallback& callback); |
| 125 | 156 |
| 126 private: | 157 private: |
| 158 friend class SyncFS_MetadataDatabaseTest; | |
| 159 | |
| 160 static const char* kDatabaseVersionKey; | |
| 161 static const int64 kCurrentDatabaseVersion; | |
| 162 static const char* kServiceMetadataKey; | |
| 163 static const char* kFileMetadataKeyPrefix; | |
| 164 | |
| 165 static scoped_ptr<leveldb::DB> OpenDatabase( | |
| 166 const base::FilePath& path, | |
| 167 SyncStatusCode* status, | |
| 168 bool* created); | |
| 169 static SyncStatusCode WriteInitialData(leveldb::DB* db); | |
| 170 static SyncStatusCode MigrateDatabaseIfNeeded(leveldb::DB* db); | |
| 171 static SyncStatusCode ReadDatabaseContents(leveldb::DB* db, | |
| 172 InitializeInfo* info); | |
| 173 static SyncStatusCode ConstructDataStructure(InitializeInfo* info, | |
| 174 leveldb::WriteBatch* batch); | |
| 175 static scoped_ptr<InitializeInfo> InitializeOnWorker( | |
| 176 const base::FilePath& db_path); | |
| 177 | |
| 178 void WriteToDB(scoped_ptr<leveldb::WriteBatch> batch, | |
|
kinuko
2013/07/04 15:59:11
Do you want to use Database or DB in methods names
tzik
2013/07/05 07:42:28
Changed to WriteToDatabase. I prefer using Databas
| |
| 179 const SyncStatusCallback& callback); | |
| 180 | |
| 181 void DidInitialize(const SyncStatusCallback& callback, | |
| 182 scoped_ptr<InitializeInfo> contents); | |
| 183 | |
| 184 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 185 scoped_ptr<leveldb::DB> db_; | |
| 186 | |
| 187 scoped_ptr<ServiceMetadata> service_metadata_; | |
| 188 FileByFileID file_by_file_id_; // Owned. | |
| 189 | |
| 190 FilesByParent files_by_parent_; // Not owned. | |
| 191 FileByAppID app_root_by_app_id_; // Not owned. | |
| 192 FileByParentAndTitle active_file_by_parent_and_title_; // Not owned. | |
| 193 | |
| 194 base::WeakPtrFactory<MetadataDatabase> weak_ptr_factory_; | |
| 195 | |
| 127 DISALLOW_COPY_AND_ASSIGN(MetadataDatabase); | 196 DISALLOW_COPY_AND_ASSIGN(MetadataDatabase); |
| 128 }; | 197 }; |
| 129 | 198 |
| 130 } // namespace drive_backend | 199 } // namespace drive_backend |
| 131 } // namespace sync_file_system | 200 } // namespace sync_file_system |
| 132 | 201 |
| 133 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ | 202 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ |
| OLD | NEW |