Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_change.h
blob1314c7e6bff233b83b4ac61c709335b2baf0afcd
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
8 #include <deque>
9 #include <map>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h"
14 #include "storage/browser/fileapi/file_system_url.h"
16 namespace drive {
17 class ResourceEntry;
19 class FileChange {
20 public:
21 enum FileType {
22 FILE_TYPE_UNKNOWN,
23 FILE_TYPE_FILE,
24 FILE_TYPE_DIRECTORY,
27 enum ChangeType {
28 ADD_OR_UPDATE,
29 DELETE,
32 class Change {
33 public:
34 Change(ChangeType change, FileType file_type);
36 bool IsAddOrUpdate() const { return change_ == ADD_OR_UPDATE; }
37 bool IsDelete() const { return change_ == DELETE; }
39 bool IsFile() const { return file_type_ == FILE_TYPE_FILE; }
40 bool IsDirectory() const { return file_type_ == FILE_TYPE_DIRECTORY; }
41 bool IsTypeUnknown() const { return !IsFile() && !IsDirectory(); }
43 ChangeType change() const { return change_; }
44 FileType file_type() const { return file_type_; }
46 std::string DebugString() const;
48 bool operator==(const Change& that) const {
49 return change() == that.change() && file_type() == that.file_type();
52 private:
53 ChangeType change_;
54 FileType file_type_;
57 class ChangeList {
58 public:
59 typedef std::deque<Change> List;
61 ChangeList();
62 ~ChangeList();
64 // Updates the list with the |new_change|.
65 void Update(const Change& new_change);
67 size_t size() const { return list_.size(); }
68 bool empty() const { return list_.empty(); }
69 void clear() { list_.clear(); }
70 const List& list() const { return list_; }
71 const Change& front() const { return list_.front(); }
72 const Change& back() const { return list_.back(); }
74 ChangeList PopAndGetNewList() const;
76 std::string DebugString() const;
78 private:
79 List list_;
82 public:
83 typedef std::map<base::FilePath, FileChange::ChangeList> Map;
85 FileChange();
86 ~FileChange();
88 void Update(const base::FilePath file_path,
89 const FileChange::Change& new_change);
90 void Update(const base::FilePath file_path,
91 const FileChange::ChangeList& list);
92 void Update(const base::FilePath file_path,
93 FileType type,
94 FileChange::ChangeType change);
95 void Update(const base::FilePath file_path,
96 const ResourceEntry& entry,
97 FileChange::ChangeType change);
98 void Apply(const FileChange& new_changed_files);
100 const Map& map() const { return map_; }
102 size_t size() const { return map_.size(); }
103 bool empty() const { return map_.empty(); }
104 void ClearForTest() { map_.clear(); }
105 size_t CountDirectory(const base::FilePath& directory_path) const;
106 size_t count(const base::FilePath& file_path) const {
107 return map_.count(file_path);
110 std::string DebugString() const;
112 private:
113 Map map_;
116 } // namespace drive
118 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_