OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 APPS_SAVED_FILES_SERVICE_H_ | 5 #ifndef APPS_SAVED_FILES_SERVICE_H_ |
6 #define APPS_SAVED_FILES_SERVICE_H_ | 6 #define APPS_SAVED_FILES_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 19 matching lines...) Expand all Loading... |
30 namespace apps { | 30 namespace apps { |
31 | 31 |
32 // Represents a file entry that a user has given an app permission to | 32 // Represents a file entry that a user has given an app permission to |
33 // access. Will be persisted to disk (in the Preferences file), so should remain | 33 // access. Will be persisted to disk (in the Preferences file), so should remain |
34 // serializable. | 34 // serializable. |
35 struct SavedFileEntry { | 35 struct SavedFileEntry { |
36 SavedFileEntry(); | 36 SavedFileEntry(); |
37 | 37 |
38 SavedFileEntry(const std::string& id, | 38 SavedFileEntry(const std::string& id, |
39 const base::FilePath& path, | 39 const base::FilePath& path, |
| 40 bool is_directory, |
40 int sequence_number); | 41 int sequence_number); |
41 | 42 |
42 // The opaque id of this file entry. | 43 // The opaque id of this file entry. |
43 std::string id; | 44 std::string id; |
44 | 45 |
45 // The path to a file entry that the app had permission to access. | 46 // The path to a file entry that the app had permission to access. |
46 base::FilePath path; | 47 base::FilePath path; |
47 | 48 |
| 49 // Whether or not the entry refers to a directory. |
| 50 bool is_directory; |
| 51 |
48 // The sequence number in the LRU of the file entry. The value 0 indicates | 52 // The sequence number in the LRU of the file entry. The value 0 indicates |
49 // that the entry is not in the LRU. | 53 // that the entry is not in the LRU. |
50 int sequence_number; | 54 int sequence_number; |
51 }; | 55 }; |
52 | 56 |
53 // Tracks the files that apps have retained access to both while running and | 57 // Tracks the files that apps have retained access to both while running and |
54 // when suspended. | 58 // when suspended. |
55 class SavedFilesService : public BrowserContextKeyedService, | 59 class SavedFilesService : public BrowserContextKeyedService, |
56 public content::NotificationObserver { | 60 public content::NotificationObserver { |
57 public: | 61 public: |
58 explicit SavedFilesService(Profile* profile); | 62 explicit SavedFilesService(Profile* profile); |
59 virtual ~SavedFilesService(); | 63 virtual ~SavedFilesService(); |
60 | 64 |
61 static SavedFilesService* Get(Profile* profile); | 65 static SavedFilesService* Get(Profile* profile); |
62 | 66 |
63 // Registers a file entry with the saved files service, making it eligible to | 67 // Registers a file entry with the saved files service, making it eligible to |
64 // be put into the queue. File entries that are in the retained files queue at | 68 // be put into the queue. File entries that are in the retained files queue at |
65 // object construction are automatically registered. | 69 // object construction are automatically registered. |
66 void RegisterFileEntry(const std::string& extension_id, | 70 void RegisterFileEntry(const std::string& extension_id, |
67 const std::string& id, | 71 const std::string& id, |
68 const base::FilePath& file_path); | 72 const base::FilePath& file_path, |
| 73 bool is_directory); |
69 | 74 |
70 // If the file with |id| is not in the queue of files to be retained | 75 // If the file with |id| is not in the queue of files to be retained |
71 // permanently, adds the file to the back of the queue, evicting the least | 76 // permanently, adds the file to the back of the queue, evicting the least |
72 // recently used entry at the front of the queue if it is full. If it is | 77 // recently used entry at the front of the queue if it is full. If it is |
73 // already present, moves it to the back of the queue. The |id| must have been | 78 // already present, moves it to the back of the queue. The |id| must have been |
74 // registered. | 79 // registered. |
75 void EnqueueFileEntry(const std::string& extension_id, const std::string& id); | 80 void EnqueueFileEntry(const std::string& extension_id, const std::string& id); |
76 | 81 |
77 // Returns whether the file entry with the given |id| has been registered. | 82 // Returns whether the file entry with the given |id| has been registered. |
78 bool IsRegistered(const std::string& extension_id, const std::string& id); | 83 bool IsRegistered(const std::string& extension_id, const std::string& id); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 extension_id_to_saved_files_deleter_; | 132 extension_id_to_saved_files_deleter_; |
128 content::NotificationRegistrar registrar_; | 133 content::NotificationRegistrar registrar_; |
129 Profile* profile_; | 134 Profile* profile_; |
130 | 135 |
131 DISALLOW_COPY_AND_ASSIGN(SavedFilesService); | 136 DISALLOW_COPY_AND_ASSIGN(SavedFilesService); |
132 }; | 137 }; |
133 | 138 |
134 } // namespace apps | 139 } // namespace apps |
135 | 140 |
136 #endif // APPS_SAVED_FILES_SERVICE_H_ | 141 #endif // APPS_SAVED_FILES_SERVICE_H_ |
OLD | NEW |