Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/chromeos/drive/file_change.h

Issue 343073003: Files.app: Provide detailed change information on onDirectoryChanged event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_ 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
7 7
8 #include <set> 8 #include <deque>
9 #include <map>
10 #include <string>
9 11
12 #include "base/basictypes.h"
10 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "webkit/browser/fileapi/file_system_url.h"
11 15
12 namespace drive { 16 namespace drive {
17 class ResourceEntry;
13 18
14 class FileChange;
15
16 // Set of changes.
17 typedef std::set<FileChange> FileChangeSet;
18
19 // Represents change in the filesystem. Rename is represented as two entries:
20 // of type DELETED and ADDED. CHANGED type is for changed contents of
21 // directories or for changed metadata and/or contents of files.
22 class FileChange { 19 class FileChange {
23 public: 20 public:
24 enum Type { 21 enum FileType {
25 DELETED, 22 FILE_TYPE_UNKNOWN,
26 ADDED, 23 FILE_TYPE_FILE,
27 CHANGED, 24 FILE_TYPE_DIRECTORY,
28 }; 25 };
29 26
30 // Created an object representing a change of file or directory pointed by 27 enum ChangeType {
31 // |change_path|. The change is of |change_type| type. 28 ADD_OR_UPDATE,
32 FileChange(const base::FilePath& path, Type type); 29 DELETE,
30 };
31
32 class Change {
33 public:
34 Change(ChangeType change, FileType file_type);
35
36 bool IsAddOrUpdate() const { return change_ == ADD_OR_UPDATE; }
37 bool IsDelete() const { return change_ == DELETE; }
38
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();
62 ~ChangeList();
63
64 // Updates the list with the |new_change|.
65 void Update(const Change& new_change);
66
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(); }
73
74 ChangeList PopAndGetNewList() const;
75
76 std::string DebugString() const;
77
78 private:
79 List list_;
80 };
81
82 public:
83 typedef std::map<base::FilePath, FileChange::ChangeList> Map;
84
85 FileChange();
33 ~FileChange(); 86 ~FileChange();
34 87
35 // Factory method to create a FileChangeSet object with only one element. 88 void Update(const base::FilePath file_path,
36 static FileChangeSet CreateSingleSet(const base::FilePath& path, Type type); 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);
37 99
38 bool operator==(const FileChange &file_change) const { 100 const Map& map() const { return map_; }
39 return path_ == file_change.path() && type_ == file_change.type(); 101
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);
40 } 108 }
41 109
42 bool operator<(const FileChange &file_change) const { 110 std::string DebugString() const;
43 return (path_ < file_change.path()) ||
44 (path_ == file_change.path() && type_ < file_change.type());
45 }
46
47 const base::FilePath& path() const { return path_; }
48
49 Type type() const { return type_; }
50 111
51 private: 112 private:
52 const base::FilePath path_; 113 Map map_;
53 const Type type_;
54 }; 114 };
55 115
56 } // namespace drive 116 } // namespace drive
57 117
58 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_ 118 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/directory_loader_unittest.cc ('k') | chrome/browser/chromeos/drive/file_change.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698