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_V1_DRIVE_METADATA_STORE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_DRIVE_METADATA_STORE_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_DRIVE_METADATA_STORE_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_DRIVE_METADATA_STORE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "chrome/browser/sync_file_system/sync_callbacks.h" | 19 #include "chrome/browser/sync_file_system/sync_callbacks.h" |
20 #include "chrome/browser/sync_file_system/sync_status_code.h" | 20 #include "chrome/browser/sync_file_system/sync_status_code.h" |
21 #include "webkit/browser/fileapi/file_system_url.h" | 21 #include "storage/browser/fileapi/file_system_url.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class ListValue; | 24 class ListValue; |
25 class SequencedTaskRunner; | 25 class SequencedTaskRunner; |
26 } | 26 } |
27 | 27 |
28 namespace leveldb { | 28 namespace leveldb { |
29 class DB; | 29 class DB; |
30 class WriteBatch; | 30 class WriteBatch; |
31 } | 31 } |
32 | 32 |
33 class GURL; | 33 class GURL; |
34 | 34 |
35 namespace sync_file_system { | 35 namespace sync_file_system { |
36 | 36 |
37 class DriveMetadata; | 37 class DriveMetadata; |
38 struct DBContents; | 38 struct DBContents; |
39 struct FileMetadata; | 39 struct FileMetadata; |
40 | 40 |
41 // This class holds a snapshot of the server side metadata. | 41 // This class holds a snapshot of the server side metadata. |
42 class DriveMetadataStore | 42 class DriveMetadataStore |
43 : public base::NonThreadSafe, | 43 : public base::NonThreadSafe, |
44 public base::SupportsWeakPtr<DriveMetadataStore> { | 44 public base::SupportsWeakPtr<DriveMetadataStore> { |
45 public: | 45 public: |
46 typedef std::map<GURL, std::string> ResourceIdByOrigin; | 46 typedef std::map<GURL, std::string> ResourceIdByOrigin; |
47 typedef std::map<std::string, GURL> OriginByResourceId; | 47 typedef std::map<std::string, GURL> OriginByResourceId; |
48 typedef std::map<base::FilePath, DriveMetadata> PathToMetadata; | 48 typedef std::map<base::FilePath, DriveMetadata> PathToMetadata; |
49 typedef std::map<GURL, PathToMetadata> MetadataMap; | 49 typedef std::map<GURL, PathToMetadata> MetadataMap; |
50 typedef std::vector<std::pair<fileapi::FileSystemURL, DriveMetadata> > | 50 typedef std::vector<std::pair<storage::FileSystemURL, DriveMetadata> > |
51 URLAndDriveMetadataList; | 51 URLAndDriveMetadataList; |
52 typedef base::Callback<void(SyncStatusCode status, bool created)> | 52 typedef base::Callback<void(SyncStatusCode status, bool created)> |
53 InitializationCallback; | 53 InitializationCallback; |
54 | 54 |
55 static const base::FilePath::CharType kDatabaseName[]; | 55 static const base::FilePath::CharType kDatabaseName[]; |
56 | 56 |
57 DriveMetadataStore(const base::FilePath& base_dir, | 57 DriveMetadataStore(const base::FilePath& base_dir, |
58 base::SequencedTaskRunner* file_task_runner); | 58 base::SequencedTaskRunner* file_task_runner); |
59 ~DriveMetadataStore(); | 59 ~DriveMetadataStore(); |
60 | 60 |
61 // Initializes the internal database and loads its content to memory. | 61 // Initializes the internal database and loads its content to memory. |
62 // This function works asynchronously. | 62 // This function works asynchronously. |
63 void Initialize(const InitializationCallback& callback); | 63 void Initialize(const InitializationCallback& callback); |
64 | 64 |
65 void SetLargestChangeStamp(int64 largest_changestamp, | 65 void SetLargestChangeStamp(int64 largest_changestamp, |
66 const SyncStatusCallback& callback); | 66 const SyncStatusCallback& callback); |
67 int64 GetLargestChangeStamp() const; | 67 int64 GetLargestChangeStamp() const; |
68 | 68 |
69 // Updates database entry. Invokes |callback|, upon completion. | 69 // Updates database entry. Invokes |callback|, upon completion. |
70 void UpdateEntry(const fileapi::FileSystemURL& url, | 70 void UpdateEntry(const storage::FileSystemURL& url, |
71 const DriveMetadata& metadata, | 71 const DriveMetadata& metadata, |
72 const SyncStatusCallback& callback); | 72 const SyncStatusCallback& callback); |
73 | 73 |
74 // Deletes database entry for |url|. Invokes |callback|, upon completion. | 74 // Deletes database entry for |url|. Invokes |callback|, upon completion. |
75 void DeleteEntry(const fileapi::FileSystemURL& url, | 75 void DeleteEntry(const storage::FileSystemURL& url, |
76 const SyncStatusCallback& callback); | 76 const SyncStatusCallback& callback); |
77 | 77 |
78 // Lookups and reads the database entry for |url|. | 78 // Lookups and reads the database entry for |url|. |
79 SyncStatusCode ReadEntry(const fileapi::FileSystemURL& url, | 79 SyncStatusCode ReadEntry(const storage::FileSystemURL& url, |
80 DriveMetadata* metadata) const; | 80 DriveMetadata* metadata) const; |
81 | 81 |
82 // Marks |origin| as incremental sync and associates it with the directory | 82 // Marks |origin| as incremental sync and associates it with the directory |
83 // identified by |resource_id|. | 83 // identified by |resource_id|. |
84 // |origin| must not already be an incremental sync origin. | 84 // |origin| must not already be an incremental sync origin. |
85 void AddIncrementalSyncOrigin(const GURL& origin, | 85 void AddIncrementalSyncOrigin(const GURL& origin, |
86 const std::string& resource_id); | 86 const std::string& resource_id); |
87 | 87 |
88 // Returns true if |origin| is an incremental sync or disabled origin. | 88 // Returns true if |origin| is an incremental sync or disabled origin. |
89 bool IsKnownOrigin(const GURL& origin) const; | 89 bool IsKnownOrigin(const GURL& origin) const; |
(...skipping 15 matching lines...) Expand all Loading... |
105 void RemoveOrigin(const GURL& origin, | 105 void RemoveOrigin(const GURL& origin, |
106 const SyncStatusCallback& callback); | 106 const SyncStatusCallback& callback); |
107 | 107 |
108 // Sets the directory identified by |resource_id| as the sync data directory. | 108 // Sets the directory identified by |resource_id| as the sync data directory. |
109 // All data for the Sync FileSystem should be store into the directory. | 109 // All data for the Sync FileSystem should be store into the directory. |
110 void SetSyncRootDirectory(const std::string& resource_id); | 110 void SetSyncRootDirectory(const std::string& resource_id); |
111 void SetOriginRootDirectory(const GURL& origin, | 111 void SetOriginRootDirectory(const GURL& origin, |
112 const std::string& resource_id); | 112 const std::string& resource_id); |
113 | 113 |
114 // Returns a set of URLs for files in conflict. | 114 // Returns a set of URLs for files in conflict. |
115 SyncStatusCode GetConflictURLs( | 115 SyncStatusCode GetConflictURLs(storage::FileSystemURLSet* urls) const; |
116 fileapi::FileSystemURLSet* urls) const; | |
117 | 116 |
118 // Returns a set of URLs and Resource IDs for files to be fetched. | 117 // Returns a set of URLs and Resource IDs for files to be fetched. |
119 SyncStatusCode GetToBeFetchedFiles(URLAndDriveMetadataList* list) const; | 118 SyncStatusCode GetToBeFetchedFiles(URLAndDriveMetadataList* list) const; |
120 | 119 |
121 // Returns resource id for |origin|. | 120 // Returns resource id for |origin|. |
122 // This may return an empty string if |origin| is not a incremental or | 121 // This may return an empty string if |origin| is not a incremental or |
123 // disabled origin. | 122 // disabled origin. |
124 std::string GetResourceIdForOrigin(const GURL& origin) const; | 123 std::string GetResourceIdForOrigin(const GURL& origin) const; |
125 | 124 |
126 const std::string& sync_root_directory() const { | 125 const std::string& sync_root_directory() const { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 ResourceIdByOrigin disabled_origins_; | 175 ResourceIdByOrigin disabled_origins_; |
177 | 176 |
178 OriginByResourceId origin_by_resource_id_; | 177 OriginByResourceId origin_by_resource_id_; |
179 | 178 |
180 DISALLOW_COPY_AND_ASSIGN(DriveMetadataStore); | 179 DISALLOW_COPY_AND_ASSIGN(DriveMetadataStore); |
181 }; | 180 }; |
182 | 181 |
183 } // namespace sync_file_system | 182 } // namespace sync_file_system |
184 | 183 |
185 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_DRIVE_METADATA_STORE
_H_ | 184 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_V1_DRIVE_METADATA_STORE
_H_ |
OLD | NEW |