Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / local / local_file_change_tracker.h
index 456a489..104e1e5 100644 (file)
@@ -29,6 +29,11 @@ class FileSystemContext;
 class FileSystemURL;
 }
 
+namespace leveldb {
+class Env;
+class WriteBatch;
+}
+
 namespace sync_file_system {
 
 // Tracks local file changes for cloud-backed file systems.
@@ -42,6 +47,7 @@ class LocalFileChangeTracker
   // (So that we can make sure DB operations are done before actual update
   // happens)
   LocalFileChangeTracker(const base::FilePath& base_path,
+                         leveldb::Env* env_override,
                          base::SequencedTaskRunner* file_task_runner);
   virtual ~LocalFileChangeTracker();
 
@@ -68,6 +74,7 @@ class LocalFileChangeTracker
                           int max_urls);
 
   // Returns all changes recorded for the given |url|.
+  // Note that this also returns demoted changes.
   // This should be called after writing is disabled.
   void GetChangesForURL(const fileapi::FileSystemURL& url,
                         FileChangeList* changes);
@@ -86,18 +93,33 @@ class LocalFileChangeTracker
   // commits the updated change status to database.
   void ResetToMirrorAndCommitChangesForURL(const fileapi::FileSystemURL& url);
 
+  // Re-inserts changes into the separate demoted_changes_ queue. They won't
+  // be fetched by GetNextChangedURLs() unless PromoteDemotedChanges() is
+  // called.
+  void DemoteChangesForURL(const fileapi::FileSystemURL& url);
+
+  // Promotes demoted changes for |url| to the normal queue.
+  void PromoteDemotedChangesForURL(const fileapi::FileSystemURL& url);
+
+  // Promotes all demoted changes to the normal queue. Returns true if it has
+  // promoted any changes.
+  bool PromoteDemotedChanges();
+
   // Called by FileSyncService at the startup time to restore last dirty changes
   // left after the last shutdown (if any).
   SyncStatusCode Initialize(fileapi::FileSystemContext* file_system_context);
 
+  // Resets all the changes recorded for the given |origin| and |type|.
+  // TODO(kinuko,nhiroki): Ideally this should be automatically called in
+  // DeleteFileSystem via QuotaUtil::DeleteOriginDataOnFileThread.
+  void ResetForFileSystem(const GURL& origin, fileapi::FileSystemType type);
+
   // This method is (exceptionally) thread-safe.
   int64 num_changes() const {
     base::AutoLock lock(num_changes_lock_);
     return num_changes_;
   }
 
-  void UpdateNumChanges();
-
  private:
   class TrackerDB;
   friend class CannedSyncableFileSystem;
@@ -118,6 +140,8 @@ class LocalFileChangeTracker
           FileChangeMap;
   typedef std::map<int64, fileapi::FileSystemURL> ChangeSeqMap;
 
+  void UpdateNumChanges();
+
   // This does mostly same as calling GetNextChangedURLs with max_url=0
   // except that it returns urls in set rather than in deque.
   // Used only in testings.
@@ -141,6 +165,10 @@ class LocalFileChangeTracker
                                        FileChangeMap* changes,
                                        ChangeSeqMap* change_seqs);
 
+  void ResetForURL(const fileapi::FileSystemURL& url,
+                   int change_seq,
+                   leveldb::WriteBatch* batch);
+
   bool initialized_;
 
   scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
@@ -148,15 +176,15 @@ class LocalFileChangeTracker
   FileChangeMap changes_;
   ChangeSeqMap change_seqs_;
 
-  // For mirrors.
-  FileChangeMap mirror_changes_;
+  FileChangeMap mirror_changes_;  // For mirrors.
+  FileChangeMap demoted_changes_;  // For demoted changes.
 
   scoped_ptr<TrackerDB> tracker_db_;
 
   // Change sequence number. Briefly gives a hint about the order of changes,
   // but they are updated when a new change comes on the same file (as
   // well as Drive's changestamps).
-  int64 current_change_seq_;
+  int64 current_change_seq_number_;
 
   // This can be accessed on any threads (with num_changes_lock_).
   int64 num_changes_;