OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef APPS_SAVED_FILES_SERVICE_H_ | |
6 #define APPS_SAVED_FILES_SERVICE_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/files/file_path.h" | |
14 #include "base/gtest_prod_util.h" | |
15 #include "base/stl_util.h" | |
16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | |
Matt Giuca
2013/05/22 08:26:14
Line too long. Not sure if the style guide permits
| |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "content/public/browser/notification_registrar.h" | |
19 | |
20 class Profile; | |
21 class SavedFilesServiceUnitTest; | |
22 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, RetainTwoFilesTest); | |
23 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, EvictionTest); | |
24 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, SequenceNumberCompactionTest); | |
25 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, | |
26 SequenceNumberCompactionFirstAboveOneTest); | |
27 | |
28 namespace extensions { | |
29 class Extension; | |
30 } // namespace extensions | |
31 | |
32 namespace apps { | |
33 | |
34 // Represents a file entry that a user has given an app permission to | |
35 // access. Intended to be persisted to disk (in the Preferences file), so should | |
Matt Giuca
2013/05/22 08:26:14
s/intended to/will/
Sam McNally
2013/05/23 03:47:28
Done.
| |
36 // remain serializable. | |
37 struct SavedFileEntry { | |
38 SavedFileEntry() | |
Matt Giuca
2013/05/22 08:26:14
I don't think these constructors should be in the
Sam McNally
2013/05/23 03:47:28
Done.
| |
39 : writable(false), | |
40 sequence_number(0) {} | |
41 | |
42 SavedFileEntry(const std::string& id, | |
43 const base::FilePath& path, | |
44 bool writable, | |
45 int sequence_number) | |
46 : id(id), | |
47 path(path), | |
48 writable(writable), | |
49 sequence_number(sequence_number) {} | |
50 | |
51 // The opaque id of this file entry. | |
52 std::string id; | |
53 | |
54 // The path to a file entry that an extension had permission to access. | |
Matt Giuca
2013/05/22 08:26:14
s/an extension/the app
(Should be "the" to clarif
Sam McNally
2013/05/23 03:47:28
Done.
| |
55 base::FilePath path; | |
56 | |
57 // Whether or not an extension had write access to a file entry. | |
Matt Giuca
2013/05/22 08:26:14
s/an extension/the app
Sam McNally
2013/05/23 03:47:28
Done.
| |
58 bool writable; | |
59 | |
60 // The sequence number in the LRU of the file entry. | |
Matt Giuca
2013/05/22 08:26:14
// The value 0 indicates that the entry is not in
Sam McNally
2013/05/23 03:47:28
Done.
| |
61 int sequence_number; | |
62 }; | |
63 | |
64 class SavedFilesService : public ProfileKeyedService, | |
Matt Giuca
2013/05/22 08:26:14
Here I think is a good place to discuss what this
| |
65 public content::NotificationObserver { | |
66 public: | |
67 explicit SavedFilesService(Profile* profile); | |
68 virtual ~SavedFilesService(); | |
69 | |
70 static SavedFilesService* Get(Profile* profile); | |
71 | |
72 // Adds a file entry to be retained, but does not add it to the queue of | |
Matt Giuca
2013/05/22 08:26:14
"...to be retained if the app is automatically res
| |
73 // entries to be retained between app runs. | |
74 void RetainFileUntilAppSuspend(const std::string& extension_id, | |
Matt Giuca
2013/05/22 08:26:14
Can this be called RetainFileUntilAppQuit? Suspend
| |
75 const std::string& id, | |
76 const base::FilePath& file_path, | |
77 bool writable); | |
78 | |
79 // Adds the file with |id| to the back of the queue to be retained | |
80 // permanently, evicting the least recently used entry at the front of the | |
81 // queue if it is full, or moves it to the back if already present. | |
Matt Giuca
2013/05/22 08:26:14
Reword:
"If the file with |id| is not in the queu
Sam McNally
2013/05/23 03:47:28
Done.
| |
82 void MoveEntryToBackOfQueue(const std::string& extension_id, | |
Matt Giuca
2013/05/22 08:26:14
Hmm, actually, can we not use the word "Move"; it
| |
83 const std::string& id); | |
84 | |
85 // Returns whether the file entry with the given |id| is retained, either | |
86 // permanently or just until app suspend. | |
87 bool IsRetained(const std::string& extension_id, const std::string& id); | |
88 | |
89 // Stores the file entry with the specified |id| in |out| and returns true if | |
90 // the file entry is retained or returns false. | |
91 bool GetFileEntry(const std::string& extension_id, | |
92 const std::string& id, | |
93 SavedFileEntry* out); | |
94 | |
95 // Returns all retained file entries. | |
Matt Giuca
2013/05/22 08:26:14
Retained until app quit, or persistently retained?
Sam McNally
2013/05/23 03:47:28
all!
| |
96 std::vector<SavedFileEntry> GetAllFileEntries( | |
97 const std::string& extension_id); | |
98 | |
99 // Clears all retained files if the app does not have the | |
100 // fileSystem.retainFiles permission. | |
101 void MaybeClearQueue(const extensions::Extension* extension); | |
102 | |
103 private: | |
104 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, RetainTwoFilesTest); | |
105 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, EvictionTest); | |
106 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, | |
107 SequenceNumberCompactionTest); | |
108 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, | |
109 SequenceNumberCompactionFirstAboveOneTest); | |
110 friend class ::SavedFilesServiceUnitTest; | |
111 | |
112 class SavedFiles; | |
Matt Giuca
2013/05/22 08:26:14
Can you explain what SavedFiles represents? (I gat
Sam McNally
2013/05/23 03:47:28
Done.
| |
113 | |
114 // content::NotificationObserver. | |
115 virtual void Observe(int type, | |
116 const content::NotificationSource& source, | |
117 const content::NotificationDetails& details) OVERRIDE; | |
118 | |
119 SavedFiles* GetOrInsert(const std::string& extension_id); | |
Matt Giuca
2013/05/22 08:26:14
Brief comment.
Sam McNally
2013/05/23 03:47:28
Done.
| |
120 | |
121 void Clear(const std::string& extension_id); | |
Matt Giuca
2013/05/22 08:26:14
Brief comment.
Sam McNally
2013/05/23 03:47:28
Done.
| |
122 | |
123 static void SetMaxSequenceNumberForTest(int max_value); | |
124 static void ClearMaxSequenceNumberForTest(); | |
125 static void SetLruSizeForTest(int size); | |
126 static void ClearLruSizeForTest(); | |
127 | |
128 std::map<std::string, SavedFiles*> extension_id_to_saved_files_; | |
129 STLValueDeleter<std::map<std::string, SavedFiles*> > | |
130 extension_id_to_saved_files_deleter_; | |
131 content::NotificationRegistrar registrar_; | |
132 Profile* profile_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(SavedFilesService); | |
135 }; | |
136 | |
137 } // namespace apps | |
138 | |
139 #endif // APPS_SAVED_FILES_SERVICE_H_ | |
OLD | NEW |