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_
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h"
27 CHANGE_TYPE_ADD_OR_UPDATE
,
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();
58 typedef std::deque
<Change
> List
;
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;
82 typedef std::map
<base::FilePath
, FileChange::ChangeList
> Map
;
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
,
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;
117 #endif // COMPONENTS_DRIVE_FILE_CHANGE_H_