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

Side by Side Diff: apps/saved_files_service.h

Issue 14607023: Add support for persistent file access in apps. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 7 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
OLDNEW
(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 "chrome/browser/profiles/profile_keyed_service.h"
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, EvictionTest);
23 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, SequenceNumberCompactionTest);
24 FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest,
25 SequenceNumberCompactionFirstAboveOneTest);
26
27 namespace extensions {
28 class Extension;
29 } // namespace extensions
30
31 namespace apps {
32
33 // Represents a file entry that a user has given an app permission to
34 // access. Intended to be persisted to disk (in the Preferences file), so should
35 // remain serializable.
36 struct SavedFileEntry {
37 SavedFileEntry()
38 : writable(false),
39 sequence_number(0) {}
40
41 SavedFileEntry(const std::string& id,
42 const base::FilePath& path,
43 bool writable,
44 int sequence_number)
45 : id(id),
46 path(path),
47 writable(writable),
48 sequence_number(sequence_number) {}
49
50 // The opaque id of this file entry.
51 std::string id;
52 // The path to a file entry that an extension had permission to access.
53 base::FilePath path;
54 // Whether or not an extension had write access to a file entry.
55 bool writable;
56 // The sequence number in the LRU of the file entry.
57 int sequence_number;
58 };
59
60 class SavedFilesService : public ProfileKeyedService,
61 public content::NotificationObserver {
62 public:
63 explicit SavedFilesService(Profile* profile);
64 virtual ~SavedFilesService();
65
66 static SavedFilesService* Get(Profile* profile);
67
68 // Adds a file entry to be retained, but does not add it to the queue of
69 // entries to be retained between app runs.
70 void RetainFileEntry(const std::string& extension_id,
71 const std::string& id,
72 const base::FilePath& file_path,
73 bool writable);
74
75 // Moves the file entry with the specified |id| to the front of the LRU,
76 // evicting the least recently used entry if the queue is full and the entry
77 // specified by |id| is not already in the queue.
78 void MoveEntryToFrontOfQueue(const std::string& extension_id,
79 const std::string& id);
80
81 // Returns whether the file entry with the given |id| is retained. This does
82 // not consider whether or not the file entry is in the queue.
83 bool IsRetained(const std::string& extension_id, const std::string& id);
84
85 // Stores the file entry with the specified |id| in |out| and returns true if
86 // the file entry is retained or returns false.
87 bool GetFileEntry(const std::string& extension_id,
88 const std::string& id,
89 SavedFileEntry* out);
90
91 // Returns all retained file entries.
92 std::vector<SavedFileEntry> GetAllFileEntries(
93 const std::string& extension_id);
94
95 // Flushes retained entries that have been evicted from the queue and clears
96 // the queue if the app does not have the fileSystem.retainFiles permission.
97 void FlushRetainedEntries(const extensions::Extension* extension);
98
99 private:
100 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, EvictionTest);
101 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest,
102 SequenceNumberCompactionTest);
103 FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest,
104 SequenceNumberCompactionFirstAboveOneTest);
105 friend class ::SavedFilesServiceUnitTest;
106
107 class SavedFiles;
108
109 // content::NotificationObserver.
110 virtual void Observe(int type,
111 const content::NotificationSource& source,
112 const content::NotificationDetails& details) OVERRIDE;
113
114 SavedFiles* GetOrInsert(const std::string& extension_id);
115
116 static void SetMaxSequenceNumberForTest(int max_value);
117 static void ClearMaxSequenceNumberForTest();
118 static void SetLruSizeForTest(int size);
119 static void ClearLruSizeForTest();
120
121 std::map<std::string, SavedFiles*> extension_id_to_saved_files_;
122 STLValueDeleter<std::map<std::string, SavedFiles*> >
123 extension_id_to_saved_files_deleter_;
124 content::NotificationRegistrar registrar_;
125 Profile* profile_;
Matt Giuca 2013/05/20 05:02:03 Can this be a const reference?
126
127 DISALLOW_COPY_AND_ASSIGN(SavedFilesService);
128 };
129
130 } // namespace apps
131
132 #endif // APPS_SAVED_FILES_SERVICE_H_
OLDNEW
« no previous file with comments | « apps/apps.gypi ('k') | apps/saved_files_service.cc » ('j') | apps/saved_files_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698