blob: 1cfc69113aaf5ee678d49fe5634096be7afc0020 [file] [log] [blame]
[email protected]e12c2d02012-10-24 08:19:031// 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.
4
lukasza76b4a982015-08-08 00:36:395#ifndef COMPONENTS_DRIVE_FILE_CHANGE_H_
6#define COMPONENTS_DRIVE_FILE_CHANGE_H_
[email protected]e12c2d02012-10-24 08:19:037
avibc5337b2015-12-25 23:16:338#include <stddef.h>
9
[email protected]741a1772014-07-01 18:40:2910#include <deque>
11#include <map>
12#include <string>
[email protected]e12c2d02012-10-24 08:19:0313
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
[email protected]e12c2d02012-10-24 08:19:0315
16namespace drive {
[email protected]741a1772014-07-01 18:40:2917class ResourceEntry;
[email protected]e12c2d02012-10-24 08:19:0318
[email protected]e12c2d02012-10-24 08:19:0319class FileChange {
20 public:
[email protected]741a1772014-07-01 18:40:2921 enum FileType {
lukasza66fa07f2015-06-12 18:36:4422 FILE_TYPE_NO_INFO,
[email protected]741a1772014-07-01 18:40:2923 FILE_TYPE_FILE,
24 FILE_TYPE_DIRECTORY,
[email protected]e12c2d02012-10-24 08:19:0325 };
26
[email protected]741a1772014-07-01 18:40:2927 enum ChangeType {
lukasza66fa07f2015-06-12 18:36:4428 CHANGE_TYPE_ADD_OR_UPDATE,
29 CHANGE_TYPE_DELETE,
[email protected]741a1772014-07-01 18:40:2930 };
31
32 class Change {
33 public:
34 Change(ChangeType change, FileType file_type);
35
lukasza66fa07f2015-06-12 18:36:4436 bool IsAddOrUpdate() const { return change_ == CHANGE_TYPE_ADD_OR_UPDATE; }
37 bool IsDelete() const { return change_ == CHANGE_TYPE_DELETE; }
[email protected]741a1772014-07-01 18:40:2938
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(); }
42
43 ChangeType change() const { return change_; }
44 FileType file_type() const { return file_type_; }
45
46 std::string DebugString() const;
47
48 bool operator==(const Change& that) const {
49 return change() == that.change() && file_type() == that.file_type();
50 }
51
52 private:
53 ChangeType change_;
54 FileType file_type_;
55 };
56
57 class ChangeList {
58 public:
59 typedef std::deque<Change> List;
60
61 ChangeList();
vmpstrb6449d512016-02-25 23:55:4062 ChangeList(const ChangeList& other);
[email protected]741a1772014-07-01 18:40:2963 ~ChangeList();
64
65 // Updates the list with the |new_change|.
66 void Update(const Change& new_change);
67
68 size_t size() const { return list_.size(); }
69 bool empty() const { return list_.empty(); }
70 void clear() { list_.clear(); }
71 const List& list() const { return list_; }
72 const Change& front() const { return list_.front(); }
73 const Change& back() const { return list_.back(); }
74
75 ChangeList PopAndGetNewList() const;
76
77 std::string DebugString() const;
78
79 private:
80 List list_;
81 };
82
83 public:
84 typedef std::map<base::FilePath, FileChange::ChangeList> Map;
85
86 FileChange();
vmpstr64511012016-04-08 19:59:3487 FileChange(const FileChange& other);
[email protected]e12c2d02012-10-24 08:19:0388 ~FileChange();
89
[email protected]741a1772014-07-01 18:40:2990 void Update(const base::FilePath file_path,
91 const FileChange::Change& new_change);
92 void Update(const base::FilePath file_path,
93 const FileChange::ChangeList& list);
94 void Update(const base::FilePath file_path,
95 FileType type,
96 FileChange::ChangeType change);
97 void Update(const base::FilePath file_path,
98 const ResourceEntry& entry,
99 FileChange::ChangeType change);
100 void Apply(const FileChange& new_changed_files);
[email protected]e12c2d02012-10-24 08:19:03101
[email protected]741a1772014-07-01 18:40:29102 const Map& map() const { return map_; }
103
104 size_t size() const { return map_.size(); }
105 bool empty() const { return map_.empty(); }
106 void ClearForTest() { map_.clear(); }
107 size_t CountDirectory(const base::FilePath& directory_path) const;
108 size_t count(const base::FilePath& file_path) const {
109 return map_.count(file_path);
[email protected]e12c2d02012-10-24 08:19:03110 }
111
[email protected]741a1772014-07-01 18:40:29112 std::string DebugString() const;
[email protected]e12c2d02012-10-24 08:19:03113
114 private:
[email protected]741a1772014-07-01 18:40:29115 Map map_;
[email protected]e12c2d02012-10-24 08:19:03116};
117
118} // namespace drive
119
lukasza76b4a982015-08-08 00:36:39120#endif // COMPONENTS_DRIVE_FILE_CHANGE_H_