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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_database.h

Issue 18591004: [SyncFS] Implement MetadataDatabase initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_backend/metadata_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8 #include <string> 9 #include <string>
9 10
10 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h"
13 #include "webkit/browser/fileapi/syncable/sync_callbacks.h" 15 #include "webkit/browser/fileapi/syncable/sync_callbacks.h"
14 #include "webkit/browser/fileapi/syncable/sync_status_code.h" 16 #include "webkit/browser/fileapi/syncable/sync_status_code.h"
15 17
16 namespace base { 18 namespace base {
17 class FilePath; 19 class FilePath;
18 class SequencedTaskRunner; 20 class SequencedTaskRunner;
21 class SingleThreadTaskRunner;
19 } 22 }
20 23
21 namespace leveldb { 24 namespace leveldb {
22 class DB; 25 class DB;
23 class WriteBatch; 26 class WriteBatch;
24 } 27 }
25 28
26 namespace google_apis { 29 namespace google_apis {
27 class ChangeResource; 30 class ChangeResource;
28 class FileResource; 31 class FileResource;
29 class ResourceEntry; 32 class ResourceEntry;
30 } 33 }
31 34
32 namespace sync_file_system { 35 namespace sync_file_system {
33 namespace drive_backend { 36 namespace drive_backend {
34 37
35 class ServiceMetadata; 38 class ServiceMetadata;
36 class DriveFileMetadata; 39 class DriveFileMetadata;
37 struct InitializeInfo; 40 struct DatabaseContents;
38 41
39 // This class holds a snapshot of the server side metadata. 42 // This class holds a snapshot of the server side metadata.
40 class MetadataDatabase { 43 class MetadataDatabase {
44 private:
45 struct FileIDComparator {
46 bool operator()(DriveFileMetadata* left, DriveFileMetadata* right);
47 };
48
41 public: 49 public:
42 explicit MetadataDatabase(base::SequencedTaskRunner* task_runner); 50 typedef std::set<DriveFileMetadata*, FileIDComparator> FileSet;
51 typedef std::map<std::string, DriveFileMetadata*> FileByFileID;
52 typedef std::map<std::string, FileSet> FilesByParent;
53 typedef std::map<std::pair<std::string, std::string>, DriveFileMetadata*>
54 FileByParentAndTitle;
55 typedef std::map<std::string, DriveFileMetadata*> FileByAppID;
56
57 typedef base::Callback<
58 void(SyncStatusCode status, scoped_ptr<MetadataDatabase> instance)>
59 CreateCallback;
60
61 static void Create(base::SequencedTaskRunner* task_runner,
62 const base::FilePath& database_path,
63 const CreateCallback& callback);
43 ~MetadataDatabase(); 64 ~MetadataDatabase();
44 65
45 // Initializes the internal database and loads its content to memory.
46 // This function works asynchronously.
47 void Initialize(const base::FilePath& database_path,
48 const SyncStatusCallback& callback);
49
50 int64 GetLargestChangeID() const; 66 int64 GetLargestChangeID() const;
51 67
52 // Registers existing folder as the app-root for |app_id|. The folder 68 // Registers existing folder as the app-root for |app_id|. The folder
53 // must be an inactive folder that does not yet associated to any App. 69 // must be an inactive folder that does not yet associated to any App.
54 // This method associates the folder with |app_id| and activates it. 70 // This method associates the folder with |app_id| and activates it.
55 void RegisterApp(const std::string& app_id, 71 void RegisterApp(const std::string& app_id,
56 const std::string& folder_id, 72 const std::string& folder_id,
57 const SyncStatusCallback& callback); 73 const SyncStatusCallback& callback);
58 74
59 // Inactivates the folder associated to the app to disable |app_id|. 75 // Inactivates the folder associated to the app to disable |app_id|.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Copies the DriveFileMetadata instance into |file| if the file is found and 118 // Copies the DriveFileMetadata instance into |file| if the file is found and
103 // |file| is non-NULL. 119 // |file| is non-NULL.
104 // |path| must be an absolute path in |app_id|. (i.e. relative to the app-root 120 // |path| must be an absolute path in |app_id|. (i.e. relative to the app-root
105 // folder.) 121 // folder.)
106 bool FindActiveFileByPath(const std::string& app_id, 122 bool FindActiveFileByPath(const std::string& app_id,
107 const base::FilePath& path, 123 const base::FilePath& path,
108 DriveFileMetadata* file) const; 124 DriveFileMetadata* file) const;
109 125
110 // Looks up FilePath from FileID. Returns true on success. 126 // Looks up FilePath from FileID. Returns true on success.
111 // |path| must be non-NULL. 127 // |path| must be non-NULL.
112 bool ConstructPathForFile(const std::string& file_id, 128 bool BuildPathForFile(const std::string& file_id,
113 base::FilePath* path) const; 129 base::FilePath* path) const;
114 130
115 // Updates database by |changes|. 131 // Updates database by |changes|.
116 // Marks dirty for each changed file if the file has the metadata in the 132 // Marks dirty for each changed file if the file has the metadata in the
117 // database. Adds new metadata to track the file if the file doesn't have 133 // database. Adds new metadata to track the file if the file doesn't have
118 // the metadata and its parent folder has the active metadata. 134 // the metadata and its parent folder has the active metadata.
119 void UpdateByChangeList(ScopedVector<google_apis::ChangeResource> changes, 135 void UpdateByChangeList(ScopedVector<google_apis::ChangeResource> changes,
120 const SyncStatusCallback& callback); 136 const SyncStatusCallback& callback);
121 137
122 // Populates |folder| with |children|. Each |children| initially has empty 138 // Populates |folder| with |children|. Each |children| initially has empty
123 // |synced_details| and |remote_details|. 139 // |synced_details| and |remote_details|.
124 void PopulateFolder(const std::string& folder_id, 140 void PopulateFolder(const std::string& folder_id,
125 ScopedVector<google_apis::ResourceEntry> children, 141 ScopedVector<google_apis::ResourceEntry> children,
126 const SyncStatusCallback& callback); 142 const SyncStatusCallback& callback);
127 143
128 private: 144 private:
145 friend class MetadataDatabaseTest;
146
147 explicit MetadataDatabase(base::SequencedTaskRunner* task_runner);
148 static void CreateOnTaskRunner(base::SingleThreadTaskRunner* callback_runner,
149 base::SequencedTaskRunner* task_runner,
150 const base::FilePath& database_path,
151 const CreateCallback& callback);
152 SyncStatusCode InitializeOnTaskRunner(const base::FilePath& database_path);
153 void BuildIndexes(DatabaseContents* contents);
154
155 void WriteToDatabase(scoped_ptr<leveldb::WriteBatch> batch,
156 const SyncStatusCallback& callback);
157
158 scoped_refptr<base::SequencedTaskRunner> task_runner_;
159 scoped_ptr<leveldb::DB> db_;
160
161 scoped_ptr<ServiceMetadata> service_metadata_;
162 FileByFileID file_by_file_id_; // Owned.
163
164 FilesByParent files_by_parent_; // Not owned.
165 FileByAppID app_root_by_app_id_; // Not owned.
166 FileByParentAndTitle active_file_by_parent_and_title_; // Not owned.
167
168 base::WeakPtrFactory<MetadataDatabase> weak_ptr_factory_;
169
129 DISALLOW_COPY_AND_ASSIGN(MetadataDatabase); 170 DISALLOW_COPY_AND_ASSIGN(MetadataDatabase);
130 }; 171 };
131 172
132 } // namespace drive_backend 173 } // namespace drive_backend
133 } // namespace sync_file_system 174 } // namespace sync_file_system
134 175
135 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_ 176 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_METADATA_DATABASE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync_file_system/drive_backend/metadata_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698