BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / components / drive / file_change.h
blob40e3a6a55b4fdeab9fd981017f5cccc457adb69c
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 COMPONENTS_DRIVE_FILE_CHANGE_H_
6 #define COMPONENTS_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"
15 namespace drive {
16 class ResourceEntry;
18 class FileChange {
19 public:
20 enum FileType {
21 FILE_TYPE_NO_INFO,
22 FILE_TYPE_FILE,
23 FILE_TYPE_DIRECTORY,
26 enum ChangeType {
27 CHANGE_TYPE_ADD_OR_UPDATE,
28 CHANGE_TYPE_DELETE,
31 class Change {
32 public:
33 Change(ChangeType change, FileType file_type);
35 bool IsAddOrUpdate() const { return change_ == CHANGE_TYPE_ADD_OR_UPDATE; }
36 bool IsDelete() const { return change_ == CHANGE_TYPE_DELETE; }
38 bool IsFile() const { return file_type_ == FILE_TYPE_FILE; }
39 bool IsDirectory() const { return file_type_ == FILE_TYPE_DIRECTORY; }
40 bool IsTypeUnknown() const { return !IsFile() && !IsDirectory(); }
42 ChangeType change() const { return change_; }
43 FileType file_type() const { return file_type_; }
45 std::string DebugString() const;
47 bool operator==(const Change& that) const {
48 return change() == that.change() && file_type() == that.file_type();
51 private:
52 ChangeType change_;
53 FileType file_type_;
56 class ChangeList {
57 public:
58 typedef std::deque<Change> List;
60 ChangeList();
61 ~ChangeList();
63 // Updates the list with the |new_change|.
64 void Update(const Change& new_change);
66 size_t size() const { return list_.size(); }
67 bool empty() const { return list_.empty(); }
68 void clear() { list_.clear(); }
69 const List& list() const { return list_; }
70 const Change& front() const { return list_.front(); }
71 const Change& back() const { return list_.back(); }
73 ChangeList PopAndGetNewList() const;
75 std::string DebugString() const;
77 private:
78 List list_;
81 public:
82 typedef std::map<base::FilePath, FileChange::ChangeList> Map;
84 FileChange();
85 ~FileChange();
87 void Update(const base::FilePath file_path,
88 const FileChange::Change& new_change);
89 void Update(const base::FilePath file_path,
90 const FileChange::ChangeList& list);
91 void Update(const base::FilePath file_path,
92 FileType type,
93 FileChange::ChangeType change);
94 void Update(const base::FilePath file_path,
95 const ResourceEntry& entry,
96 FileChange::ChangeType change);
97 void Apply(const FileChange& new_changed_files);
99 const Map& map() const { return map_; }
101 size_t size() const { return map_.size(); }
102 bool empty() const { return map_.empty(); }
103 void ClearForTest() { map_.clear(); }
104 size_t CountDirectory(const base::FilePath& directory_path) const;
105 size_t count(const base::FilePath& file_path) const {
106 return map_.count(file_path);
109 std::string DebugString() const;
111 private:
112 Map map_;
115 } // namespace drive
117 #endif // COMPONENTS_DRIVE_FILE_CHANGE_H_