| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_CHANGE_TRACKER_H_ | 5 #ifndef WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_CHANGE_TRACKER_H_ |
| 6 #define WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_CHANGE_TRACKER_H_ | 6 #define WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_CHANGE_TRACKER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 virtual void OnRemoveDirectory(const FileSystemURL& url) OVERRIDE; | 58 virtual void OnRemoveDirectory(const FileSystemURL& url) OVERRIDE; |
| 59 | 59 |
| 60 // Retrieves an array of |url| which have more than one pending changes. | 60 // Retrieves an array of |url| which have more than one pending changes. |
| 61 // If |max_urls| is non-zero (recommended in production code) this | 61 // If |max_urls| is non-zero (recommended in production code) this |
| 62 // returns URLs up to the number from the ones that have smallest | 62 // returns URLs up to the number from the ones that have smallest |
| 63 // change_seq numbers (i.e. older changes). | 63 // change_seq numbers (i.e. older changes). |
| 64 void GetNextChangedURLs(std::deque<FileSystemURL>* urls, int max_urls); | 64 void GetNextChangedURLs(std::deque<FileSystemURL>* urls, int max_urls); |
| 65 | 65 |
| 66 // Returns all changes recorded for the given |url|. | 66 // Returns all changes recorded for the given |url|. |
| 67 // This should be called after writing is disabled. | 67 // This should be called after writing is disabled. |
| 68 void GetChangesForURL(const FileSystemURL& url, FileChangeList* changes); | 68 void GetChangesForURL(const FileSystemURL& url, |
| 69 sync_file_system::FileChangeList* changes); |
| 69 | 70 |
| 70 // Clears the pending changes recorded in this tracker for |url|. | 71 // Clears the pending changes recorded in this tracker for |url|. |
| 71 void ClearChangesForURL(const FileSystemURL& url); | 72 void ClearChangesForURL(const FileSystemURL& url); |
| 72 | 73 |
| 73 // Called by FileSyncService at the startup time to restore last dirty changes | 74 // Called by FileSyncService at the startup time to restore last dirty changes |
| 74 // left after the last shutdown (if any). | 75 // left after the last shutdown (if any). |
| 75 SyncStatusCode Initialize(FileSystemContext* file_system_context); | 76 SyncStatusCode Initialize(FileSystemContext* file_system_context); |
| 76 | 77 |
| 77 // This method is (exceptionally) thread-safe. | 78 // This method is (exceptionally) thread-safe. |
| 78 int64 num_changes() const { | 79 int64 num_changes() const { |
| 79 base::AutoLock lock(num_changes_lock_); | 80 base::AutoLock lock(num_changes_lock_); |
| 80 return num_changes_; | 81 return num_changes_; |
| 81 } | 82 } |
| 82 | 83 |
| 83 void UpdateNumChanges(); | 84 void UpdateNumChanges(); |
| 84 | 85 |
| 85 private: | 86 private: |
| 86 class TrackerDB; | 87 class TrackerDB; |
| 87 friend class CannedSyncableFileSystem; | 88 friend class CannedSyncableFileSystem; |
| 88 friend class LocalFileChangeTrackerTest; | 89 friend class LocalFileChangeTrackerTest; |
| 89 friend class LocalFileSyncContext; | 90 friend class LocalFileSyncContext; |
| 90 friend class SyncableFileSystemTest; | 91 friend class SyncableFileSystemTest; |
| 91 | 92 |
| 92 struct ChangeInfo { | 93 struct ChangeInfo { |
| 93 ChangeInfo(); | 94 ChangeInfo(); |
| 94 ~ChangeInfo(); | 95 ~ChangeInfo(); |
| 95 FileChangeList change_list; | 96 sync_file_system::FileChangeList change_list; |
| 96 int64 change_seq; | 97 int64 change_seq; |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 typedef std::map<FileSystemURL, ChangeInfo, FileSystemURL::Comparator> | 100 typedef std::map<FileSystemURL, ChangeInfo, FileSystemURL::Comparator> |
| 100 FileChangeMap; | 101 FileChangeMap; |
| 101 typedef std::map<int64, FileSystemURL> ChangeSeqMap; | 102 typedef std::map<int64, FileSystemURL> ChangeSeqMap; |
| 102 | 103 |
| 103 // This does mostly same as calling GetNextChangedURLs with max_url=0 | 104 // This does mostly same as calling GetNextChangedURLs with max_url=0 |
| 104 // except that it returns urls in set rather than in deque. | 105 // except that it returns urls in set rather than in deque. |
| 105 // Used only in testings. | 106 // Used only in testings. |
| 106 void GetAllChangedURLs(FileSystemURLSet* urls); | 107 void GetAllChangedURLs(FileSystemURLSet* urls); |
| 107 | 108 |
| 108 // Used only in testings. | 109 // Used only in testings. |
| 109 void DropAllChanges(); | 110 void DropAllChanges(); |
| 110 | 111 |
| 111 // Database related methods. | 112 // Database related methods. |
| 112 SyncStatusCode MarkDirtyOnDatabase(const FileSystemURL& url); | 113 SyncStatusCode MarkDirtyOnDatabase(const FileSystemURL& url); |
| 113 SyncStatusCode ClearDirtyOnDatabase(const FileSystemURL& url); | 114 SyncStatusCode ClearDirtyOnDatabase(const FileSystemURL& url); |
| 114 | 115 |
| 115 SyncStatusCode CollectLastDirtyChanges( | 116 SyncStatusCode CollectLastDirtyChanges( |
| 116 FileSystemContext* file_system_context); | 117 FileSystemContext* file_system_context); |
| 117 void RecordChange(const FileSystemURL& url, const FileChange& change); | 118 void RecordChange(const FileSystemURL& url, |
| 119 const sync_file_system::FileChange& change); |
| 118 | 120 |
| 119 bool initialized_; | 121 bool initialized_; |
| 120 | 122 |
| 121 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 123 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
| 122 | 124 |
| 123 FileChangeMap changes_; | 125 FileChangeMap changes_; |
| 124 ChangeSeqMap change_seqs_; | 126 ChangeSeqMap change_seqs_; |
| 125 | 127 |
| 126 scoped_ptr<TrackerDB> tracker_db_; | 128 scoped_ptr<TrackerDB> tracker_db_; |
| 127 | 129 |
| 128 // Change sequence number. Briefly gives a hint about the order of changes, | 130 // Change sequence number. Briefly gives a hint about the order of changes, |
| 129 // but they are updated when a new change comes on the same file (as | 131 // but they are updated when a new change comes on the same file (as |
| 130 // well as Drive's changestamps). | 132 // well as Drive's changestamps). |
| 131 int64 current_change_seq_; | 133 int64 current_change_seq_; |
| 132 | 134 |
| 133 // This can be accessed on any threads (with num_changes_lock_). | 135 // This can be accessed on any threads (with num_changes_lock_). |
| 134 int64 num_changes_; | 136 int64 num_changes_; |
| 135 mutable base::Lock num_changes_lock_; | 137 mutable base::Lock num_changes_lock_; |
| 136 | 138 |
| 137 DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTracker); | 139 DISALLOW_COPY_AND_ASSIGN(LocalFileChangeTracker); |
| 138 }; | 140 }; |
| 139 | 141 |
| 140 } // namespace fileapi | 142 } // namespace fileapi |
| 141 | 143 |
| 142 #endif // WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_CHANGE_TRACKER_H_ | 144 #endif // WEBKIT_FILEAPI_SYNCABLE_LOCAL_FILE_CHANGE_TRACKER_H_ |
| OLD | NEW |