Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / resource_metadata.h
blobfdafc87d7fba8ed7ff3d0dc167b03333c62d547c
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 CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/chromeos/drive/file_errors.h"
15 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h"
17 namespace base {
18 class SequencedTaskRunner;
21 namespace drive {
23 typedef std::vector<ResourceEntry> ResourceEntryVector;
25 namespace internal {
27 class FileCache;
29 // Storage for Drive Metadata.
30 // All methods except the constructor and Destroy() function must be run with
31 // |blocking_task_runner| unless otherwise noted.
32 class ResourceMetadata {
33 public:
34 typedef ResourceMetadataStorage::Iterator Iterator;
36 ResourceMetadata(
37 ResourceMetadataStorage* storage,
38 FileCache* cache,
39 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner);
41 // Initializes this object.
42 // This method should be called before any other methods.
43 FileError Initialize() WARN_UNUSED_RESULT;
45 // Destroys this object. This method posts a task to |blocking_task_runner_|
46 // to safely delete this object.
47 // Must be called on the UI thread.
48 void Destroy();
50 // Resets this object.
51 FileError Reset();
53 // Returns the largest changestamp.
54 FileError GetLargestChangestamp(int64* out_value);
56 // Sets the largest changestamp.
57 FileError SetLargestChangestamp(int64 value);
59 // Adds |entry| to the metadata tree based on its parent_local_id.
60 FileError AddEntry(const ResourceEntry& entry, std::string* out_id);
62 // Removes entry with |id| from its parent.
63 FileError RemoveEntry(const std::string& id);
65 // Finds an entry (a file or a directory) by |id|.
66 FileError GetResourceEntryById(const std::string& id,
67 ResourceEntry* out_entry);
69 // Synchronous version of GetResourceEntryByPathOnUIThread().
70 FileError GetResourceEntryByPath(const base::FilePath& file_path,
71 ResourceEntry* out_entry);
73 // Finds and reads a directory by |file_path|.
74 FileError ReadDirectoryByPath(const base::FilePath& file_path,
75 ResourceEntryVector* out_entries);
77 // Finds and reads a directory by |id|.
78 FileError ReadDirectoryById(const std::string& id,
79 ResourceEntryVector* out_entries);
81 // Replaces an existing entry with the same local ID as |entry|.
82 FileError RefreshEntry(const ResourceEntry& entry);
84 // Recursively gets directories under the entry pointed to by |id|.
85 FileError GetSubDirectoriesRecursively(
86 const std::string& id,
87 std::set<base::FilePath>* sub_directories);
89 // Returns the id of the resource named |base_name| directly under
90 // the directory with |parent_local_id|.
91 // If not found, empty string will be returned.
92 FileError GetChildId(const std::string& parent_local_id,
93 const std::string& base_name,
94 std::string* out_child_id);
96 // Returns an object to iterate over entries.
97 scoped_ptr<Iterator> GetIterator();
99 // Returns virtual file path of the entry.
100 FileError GetFilePath(const std::string& id, base::FilePath* out_file_path);
102 // Returns ID of the entry at the given path.
103 FileError GetIdByPath(const base::FilePath& file_path, std::string* out_id);
105 // Returns the local ID associated with the given resource ID.
106 FileError GetIdByResourceId(const std::string& resource_id,
107 std::string* out_local_id);
109 private:
110 // Note: Use Destroy() to delete this object.
111 ~ResourceMetadata();
113 // Sets up entries which should be present by default.
114 FileError SetUpDefaultEntries();
116 // Used to implement Destroy().
117 void DestroyOnBlockingPool();
119 // Puts an entry under its parent directory. Removes the child from the old
120 // parent if there is. This method will also do name de-duplication to ensure
121 // that the exposed presentation path does not have naming conflicts. Two
122 // files with the same name "Foo" will be renamed to "Foo (1)" and "Foo (2)".
123 FileError PutEntryUnderDirectory(const ResourceEntry& entry);
125 // Returns an unused base name for |entry|.
126 FileError GetDeduplicatedBaseName(const ResourceEntry& entry,
127 std::string* base_name);
129 // Removes the entry and its descendants.
130 FileError RemoveEntryRecursively(const std::string& id);
132 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
134 ResourceMetadataStorage* storage_;
135 FileCache* cache_;
137 DISALLOW_COPY_AND_ASSIGN(ResourceMetadata);
140 } // namespace internal
141 } // namespace drive
143 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_RESOURCE_METADATA_H_