• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
7 
8 #include <set>
9 
10 #include "base/files/file_path.h"
11 
12 namespace drive {
13 
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 {
23  public:
24   enum Type {
25     DELETED,
26     ADDED,
27     CHANGED,
28   };
29 
30   // Created an object representing a change of file or directory pointed by
31   // |change_path|. The change is of |change_type| type.
32   FileChange(const base::FilePath& path, Type type);
33   ~FileChange();
34 
35   // Factory method to create a FileChangeSet object with only one element.
36   static FileChangeSet CreateSingleSet(const base::FilePath& path, Type type);
37 
38   bool operator==(const FileChange &file_change) const {
39     return path_ == file_change.path() && type_ == file_change.type();
40   }
41 
42   bool operator<(const FileChange &file_change) const {
43     return (path_ < file_change.path()) ||
44            (path_ == file_change.path() && type_ < file_change.type());
45   }
46 
path()47   const base::FilePath& path() const { return path_; }
48 
type()49   Type type() const { return type_; }
50 
51  private:
52   const base::FilePath path_;
53   const Type type_;
54 };
55 
56 }  // namespace drive
57 
58 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_CHANGE_H_
59