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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: apps/saved_files_service.h
diff --git a/apps/saved_files_service.h b/apps/saved_files_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..599114c72b18150f56c0ae04b82a6af098f86024
--- /dev/null
+++ b/apps/saved_files_service.h
@@ -0,0 +1,135 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_SAVED_FILES_SERVICE_H_
+#define APPS_SAVED_FILES_SERVICE_H_
+
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/files/file_path.h"
+#include "base/gtest_prod_util.h"
+#include "base/stl_util.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+class Profile;
+class SavedFilesServiceUnitTest;
+FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, EvictionTest);
+FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, SequenceNumberCompactionTest);
+FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest,
+ SequenceNumberCompactionFirstAboveOneTest);
+
+namespace extensions {
+class Extension;
+} // namespace extensions
+
+namespace apps {
+
+// Represents a file entry that a user has given an app permission to
+// access. Intended to be persisted to disk (in the Preferences file), so should
+// remain serializable.
+struct SavedFileEntry {
+ SavedFileEntry()
+ : writable(false),
+ sequence_number(0) {}
+
+ SavedFileEntry(const std::string& id,
+ const base::FilePath& path,
+ bool writable,
+ int sequence_number)
+ : id(id),
+ path(path),
+ writable(writable),
+ sequence_number(sequence_number) {}
+
+ // The opaque id of this file entry.
+ std::string id;
koz (OOO until 15th September) 2013/05/20 05:33:51 nit: newlines between these fields.
Sam McNally 2013/05/20 07:13:33 Done.
+ // The path to a file entry that an extension had permission to access.
+ base::FilePath path;
+ // Whether or not an extension had write access to a file entry.
+ bool writable;
+ // The sequence number in the LRU of the file entry.
+ int sequence_number;
+};
+
+class SavedFilesService : public ProfileKeyedService,
+ public content::NotificationObserver {
+ public:
+ explicit SavedFilesService(Profile* profile);
+ virtual ~SavedFilesService();
+
+ static SavedFilesService* Get(Profile* profile);
+
+ // Adds a file entry to be retained, but does not add it to the queue of
+ // entries to be retained between app runs.
+ void RetainFileEntry(const std::string& extension_id,
koz (OOO until 15th September) 2013/05/20 05:33:51 Sounds like SavedFilesService has two sets of file
Matt Giuca 2013/05/20 05:41:05 I don't like RetainFilePermanently because it does
Sam McNally 2013/05/20 07:13:33 Done.
+ const std::string& id,
+ const base::FilePath& file_path,
+ bool writable);
+
+ // Moves the file entry with the specified |id| to the front of the LRU,
+ // evicting the least recently used entry if the queue is full and the entry
+ // specified by |id| is not already in the queue.
+ void MoveEntryToFrontOfQueue(const std::string& extension_id,
+ const std::string& id);
+
+ // Returns whether the file entry with the given |id| is retained. This does
+ // not consider whether or not the file entry is in the queue.
+ bool IsRetained(const std::string& extension_id, const std::string& id);
+
+ // Stores the file entry with the specified |id| in |out| and returns true if
+ // the file entry is retained or returns false.
+ bool GetFileEntry(const std::string& extension_id,
+ const std::string& id,
+ SavedFileEntry* out);
+
+ // Returns all retained file entries.
+ std::vector<SavedFileEntry> GetAllFileEntries(
+ const std::string& extension_id);
+
+ // Clears all retained files that are not in the retained files queue. If the
+ // app does not have the fileSystem.retainFiles permission, the queue will
+ // also be cleared.
+ void ClearRetainedFiles(const extensions::Extension* extension);
Matt Giuca 2013/05/20 01:32:57 This name is not appropriate. Because it basically
Sam McNally 2013/05/20 04:25:20 Done.
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, EvictionTest);
+ FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest,
+ SequenceNumberCompactionTest);
+ FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest,
+ SequenceNumberCompactionFirstAboveOneTest);
+ friend class ::SavedFilesServiceUnitTest;
+
+ class SavedFiles;
+
+ // content::NotificationObserver.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ SavedFiles* GetOrInsert(const std::string& extension_id);
+
+ void Cleanup(const std::string& extension_id);
+
+ static void SetMaxSequenceNumberForTest(int max_value);
+ static void ClearMaxSequenceNumberForTest();
+ static void SetLruSizeForTest(int size);
+ static void ClearLruSizeForTest();
+
+ std::map<std::string, SavedFiles*> extension_id_to_saved_files_;
+ STLValueDeleter<std::map<std::string, SavedFiles*> >
+ extension_id_to_saved_files_deleter_;
+ content::NotificationRegistrar registrar_;
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(SavedFilesService);
+};
+
+} // namespace apps
+
+#endif // APPS_SAVED_FILES_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698