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

Unified Diff: chrome/browser/extensions/api/file_system/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: chrome/browser/extensions/api/file_system/saved_files_service.h
diff --git a/chrome/browser/extensions/api/file_system/saved_files_service.h b/chrome/browser/extensions/api/file_system/saved_files_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..823b8529ccfe06e5beedac7037fcef1d50b913c5
--- /dev/null
+++ b/chrome/browser/extensions/api/file_system/saved_files_service.h
@@ -0,0 +1,100 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
benwells 2013/05/16 06:50:17 Super nit: no (c)
Matt Giuca 2013/05/16 07:20:06 Meta-nit: This is a tiny nit, not a super nit.
Sam McNally 2013/05/17 03:38:52 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_SAVED_FILES_SERVICE_H_
+#define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_SAVED_FILES_SERVICE_H_
+
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+#include "base/files/file_path.h"
benwells 2013/05/16 06:50:17 Nit: blank line between <> includes and others
Sam McNally 2013/05/17 03:38:52 Done.
+#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;
+
+namespace extensions {
benwells 2013/05/16 06:50:17 I'm thinking this should be in the apps folder / n
Sam McNally 2013/05/17 03:38:52 Done.
+
+// Represents a file entry that a user has given an extension 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) {}
+
+ std::string id;
+ base::FilePath path;
+ bool writable;
+ int sequence_number;
+};
+
+class SavedFilesService : public ProfileKeyedService,
+ public content::NotificationObserver {
+ public:
+ explicit SavedFilesService(Profile* profile);
+ virtual ~SavedFilesService();
+
+ static SavedFilesService* Get(Profile* profile);
+
+ void AddFileEntry(const std::string& extension_id,
benwells 2013/05/16 06:50:17 Nit: I assume this maps to retainFileEntry, can we
Sam McNally 2013/05/17 03:38:52 Done.
+ const std::string& id,
+ const base::FilePath& file_path,
+ bool writable);
+
+ void RecordFileAccess(const std::string& extension_id, const std::string& id);
+
+ bool IsSaved(const std::string& extension_id, const std::string& id);
benwells 2013/05/16 06:50:17 Nit: IsRetained?
Sam McNally 2013/05/17 03:38:52 Done.
+
+ bool GetFileEntry(const std::string& extension_id,
+ const std::string& id,
+ SavedFileEntry* out);
+
+ void GetFileEntries(const std::string& extension_id,
benwells 2013/05/16 06:50:17 Why not return the vector? Nit: GetAllFileEntries
Sam McNally 2013/05/17 03:38:52 Done.
+ std::vector<SavedFileEntry>* out);
+
+ void ClearExtensionForTest(const std::string& extension_id);
+
+ private:
+ 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 ClearExtension(const std::string& extension_id);
+
+ std::map<std::string, SavedFiles*> extension_id_to_saved_files_;
+ STLValueDeleter<std::map<std::string, SavedFiles*> >
+ extension_id_to_saved_files_deleter_;
+ std::set<std::string> extensions_to_clear_;
+ content::NotificationRegistrar registrar_;
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(SavedFilesService);
+};
+
+void SetMaxSequenceNumberForTest(int max_value);
benwells 2013/05/16 06:50:17 Nit: Please make these static methods on the servi
Sam McNally 2013/05/17 03:38:52 Done.
+void ClearMaxSequenceNumberForTest();
+void SetLruSizeForTest(int size);
+void ClearLruSizeForTest();
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_SAVED_FILES_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698