Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / file_change.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_FILE_CHANGE_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_FILE_CHANGE_H_
7
8 #include <deque>
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "chrome/browser/sync_file_system/sync_file_type.h"
14 #include "storage/browser/fileapi/file_system_url.h"
15
16 namespace sync_file_system {
17
18 class FileChange {
19  public:
20   enum ChangeType {
21     FILE_CHANGE_ADD_OR_UPDATE,
22     FILE_CHANGE_DELETE,
23   };
24
25   FileChange(ChangeType change, SyncFileType file_type);
26
27   bool IsAddOrUpdate() const { return change_ == FILE_CHANGE_ADD_OR_UPDATE; }
28   bool IsDelete() const { return change_ == FILE_CHANGE_DELETE; }
29
30   bool IsFile() const { return file_type_ == SYNC_FILE_TYPE_FILE; }
31   bool IsDirectory() const { return file_type_ == SYNC_FILE_TYPE_DIRECTORY; }
32   bool IsTypeUnknown() const { return !IsFile() && !IsDirectory(); }
33
34   ChangeType change() const { return change_; }
35   SyncFileType file_type() const { return file_type_; }
36
37   std::string DebugString() const;
38
39   bool operator==(const FileChange& that) const {
40     return change() == that.change() &&
41         file_type() == that.file_type();
42   }
43
44  private:
45   ChangeType change_;
46   SyncFileType file_type_;
47 };
48
49 class FileChangeList {
50  public:
51   typedef std::deque<FileChange> List;
52
53   FileChangeList();
54   ~FileChangeList();
55
56   // Updates the list with the |new_change|.
57   void Update(const FileChange& new_change);
58
59   size_t size() const { return list_.size(); }
60   bool empty() const { return list_.empty(); }
61   void clear() { list_.clear(); }
62   const List& list() const { return list_; }
63   const FileChange& front() const { return list_.front(); }
64   const FileChange& back() const { return list_.back(); }
65
66   FileChangeList PopAndGetNewList() const;
67
68   std::string DebugString() const;
69
70  private:
71   List list_;
72 };
73
74 }  // namespace sync_file_system
75
76 #endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_FILE_CHANGE_H_