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

Unified Diff: extensions/browser/api/file_system/saved_files_service.h

Issue 2951003002: SavedFilesService interface in //extensions (Closed)
Patch Set: cleanup Created 3 years, 6 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: extensions/browser/api/file_system/saved_files_service.h
diff --git a/apps/saved_files_service.h b/extensions/browser/api/file_system/saved_files_service.h
similarity index 17%
rename from apps/saved_files_service.h
rename to extensions/browser/api/file_system/saved_files_service.h
index 927f22b985869eccca6f5787920c180b37b34dad..20fbfe723c249705e498ce0f469269ddb3fbc777 100644
--- a/apps/saved_files_service.h
+++ b/extensions/browser/api/file_system/saved_files_service.h
@@ -1,146 +1,71 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2017 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_
+#ifndef EXTENSIONS_BROWSER_API_FILE_SYSTEM_SAVED_FILES_SERVICE_H_
+#define EXTENSIONS_BROWSER_API_FILE_SYSTEM_SAVED_FILES_SERVICE_H_
-#include <map>
-#include <memory>
-#include <set>
#include <string>
-#include <vector>
#include "base/files/file_path.h"
-#include "base/gtest_prod_util.h"
-#include "components/keyed_service/core/keyed_service.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-
-namespace content {
-class BrowserContext;
-}
-
-class SavedFilesServiceUnitTest;
-FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, RetainTwoFilesTest);
-FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, EvictionTest);
-FORWARD_DECLARE_TEST(SavedFilesServiceUnitTest, SequenceNumberCompactionTest);
namespace extensions {
-class Extension;
-}
-
-namespace apps {
-// Represents a file entry that a user has given an app permission to
-// access. Will be persisted to disk (in the Preferences file), so should remain
-// serializable.
-struct SavedFileEntry {
- SavedFileEntry();
-
- SavedFileEntry(const std::string& id,
- const base::FilePath& path,
- bool is_directory,
- int sequence_number);
+// Provides an LRU of saved file entries that persist across app reloads.
+class SavedFilesService {
+ public:
+ // Represents a file entry that a user has given an app permission to
+ // access. Must be serializable for persisting to disk.
+ struct Entry {
+ Entry();
- // The opaque id of this file entry.
- std::string id;
+ Entry(const std::string& id,
+ const base::FilePath& path,
+ bool is_directory,
+ int sequence_number);
- // The path to a file entry that the app had permission to access.
- base::FilePath path;
+ // The opaque id of this file entry.
+ std::string id;
- // Whether or not the entry refers to a directory.
- bool is_directory;
+ // The path to a file entry that the app had permission to access.
+ base::FilePath path;
- // The sequence number in the LRU of the file entry. The value 0 indicates
- // that the entry is not in the LRU.
- int sequence_number;
-};
+ // Whether or not the entry refers to a directory.
+ bool is_directory;
-// Tracks the files that apps have retained access to both while running and
-// when suspended.
-class SavedFilesService : public KeyedService,
- public content::NotificationObserver {
- public:
- explicit SavedFilesService(content::BrowserContext* context);
- ~SavedFilesService() override;
+ // The sequence number in the LRU of the file entry. The value 0 indicates
+ // that the entry is not in the LRU.
+ int sequence_number;
+ };
- static SavedFilesService* Get(content::BrowserContext* context);
+ virtual ~SavedFilesService() {}
// Registers a file entry with the saved files service, making it eligible to
// be put into the queue. File entries that are in the retained files queue at
// object construction are automatically registered.
- void RegisterFileEntry(const std::string& extension_id,
- const std::string& id,
- const base::FilePath& file_path,
- bool is_directory);
+ virtual void RegisterFileEntry(const std::string& extension_id,
+ const std::string& id,
+ const base::FilePath& file_path,
+ bool is_directory) = 0;
// If the file with |id| is not in the queue of files to be retained
// permanently, adds the file to the back of the queue, evicting the least
// recently used entry at the front of the queue if it is full. If it is
// already present, moves it to the back of the queue. The |id| must have been
// registered.
- void EnqueueFileEntry(const std::string& extension_id, const std::string& id);
+ virtual void EnqueueFileEntry(const std::string& extension_id,
+ const std::string& id) = 0;
// Returns whether the file entry with the given |id| has been registered.
- bool IsRegistered(const std::string& extension_id, const std::string& id);
+ virtual bool IsRegistered(const std::string& extension_id,
+ const std::string& id) = 0;
// Gets a borrowed pointer to the file entry with the specified |id|. Returns
- // NULL if the file entry has not been registered.
- const SavedFileEntry* GetFileEntry(const std::string& extension_id,
- const std::string& id);
-
- // Returns all registered file entries.
- std::vector<SavedFileEntry> GetAllFileEntries(
- const std::string& extension_id);
-
- // Clears all retained files if the app does not have the
- // fileSystem.retainEntries permission.
- void ClearQueueIfNoRetainPermission(const extensions::Extension* extension);
-
- // Clears all retained files.
- void ClearQueue(const extensions::Extension* extension);
-
- // Called to notify that the application has begun to exit.
- void OnApplicationTerminating();
-
- private:
- FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, RetainTwoFilesTest);
- FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest, EvictionTest);
- FRIEND_TEST_ALL_PREFIXES(::SavedFilesServiceUnitTest,
- SequenceNumberCompactionTest);
- friend class ::SavedFilesServiceUnitTest;
-
- // A container for the registered files for an app.
- class SavedFiles;
-
- // content::NotificationObserver.
- void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) override;
-
- // Returns the SavedFiles for |extension_id| or NULL if one does not exist.
- SavedFiles* Get(const std::string& extension_id) const;
-
- // Returns the SavedFiles for |extension_id|, creating it if necessary.
- SavedFiles* GetOrInsert(const std::string& extension_id);
-
- // Clears the SavedFiles for |extension_id|.
- void Clear(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, std::unique_ptr<SavedFiles>>
- extension_id_to_saved_files_;
- content::NotificationRegistrar registrar_;
- content::BrowserContext* context_;
-
- DISALLOW_COPY_AND_ASSIGN(SavedFilesService);
+ // nullptr if the file entry has not been registered.
+ virtual const Entry* GetFileEntry(const std::string& extension_id,
+ const std::string& id) = 0;
};
-} // namespace apps
+} // namespace extensions
-#endif // APPS_SAVED_FILES_SERVICE_H_
+#endif // EXTENSIONS_BROWSER_API_FILE_SYSTEM_SAVED_FILES_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698