#include "apps/saved_files_service.h"
#include <stdint.h>
#include <algorithm>
#include <map>
#include <memory>
#include <optional>
#include <unordered_map>
#include <utility>
#include "apps/saved_files_service_factory.h"
#include "base/json/values_util.h"
#include "base/memory/raw_ptr.h"
#include "base/not_fatal_until.h"
#include "build/chromeos_buildflags.h"
#include "content/public/browser/browser_context.h"
#include "extensions/browser/api/file_system/saved_file_entry.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/common/permissions/permission_set.h"
#include "extensions/common/permissions/permissions_data.h"
namespace apps {
APIPermission;
Extension;
ExtensionHost;
ExtensionPrefs;
SavedFileEntry;
namespace {
const char kFileEntries[] = …;
const char kFileEntryPath[] = …;
const char kFileEntryIsDirectory[] = …;
const char kFileEntrySequenceNumber[] = …;
const size_t kMaxSavedFileEntries = …;
const int kMaxSequenceNumber = …;
size_t g_max_saved_file_entries = …;
int g_max_sequence_number = …;
void AddSavedFileEntry(ExtensionPrefs* prefs,
const extensions::ExtensionId& extension_id,
const SavedFileEntry& file_entry) { … }
void UpdateSavedFileEntry(ExtensionPrefs* prefs,
const extensions::ExtensionId& extension_id,
const SavedFileEntry& file_entry) { … }
void RemoveSavedFileEntry(ExtensionPrefs* prefs,
const extensions::ExtensionId& extension_id,
const std::string& file_entry_id) { … }
void ClearSavedFileEntries(ExtensionPrefs* prefs,
const extensions::ExtensionId& extension_id) { … }
std::vector<SavedFileEntry> GetSavedFileEntries(
ExtensionPrefs* prefs,
const extensions::ExtensionId& extension_id) { … }
}
class SavedFilesService::SavedFiles { … };
SavedFilesService* SavedFilesService::Get(content::BrowserContext* context) { … }
SavedFilesService::SavedFilesService(content::BrowserContext* context)
: … { … }
SavedFilesService::~SavedFilesService() = default;
void SavedFilesService::OnExtensionHostDestroyed(
content::BrowserContext* browser_context,
extensions::ExtensionHost* host) { … }
void SavedFilesService::RegisterFileEntry(
const extensions::ExtensionId& extension_id,
const std::string& id,
const base::FilePath& file_path,
bool is_directory) { … }
void SavedFilesService::EnqueueFileEntry(
const extensions::ExtensionId& extension_id,
const std::string& id) { … }
std::vector<SavedFileEntry> SavedFilesService::GetAllFileEntries(
const extensions::ExtensionId& extension_id) { … }
bool SavedFilesService::IsRegistered(
const extensions::ExtensionId& extension_id,
const std::string& id) { … }
const SavedFileEntry* SavedFilesService::GetFileEntry(
const extensions::ExtensionId& extension_id,
const std::string& id) { … }
void SavedFilesService::ClearQueueIfNoRetainPermission(
const Extension* extension) { … }
void SavedFilesService::ClearQueue(const extensions::Extension* extension) { … }
void SavedFilesService::OnApplicationTerminating() { … }
SavedFilesService::SavedFiles* SavedFilesService::Get(
const extensions::ExtensionId& extension_id) const { … }
SavedFilesService::SavedFiles* SavedFilesService::GetOrInsert(
const extensions::ExtensionId& extension_id) { … }
void SavedFilesService::Clear(const extensions::ExtensionId& extension_id) { … }
SavedFilesService::SavedFiles::SavedFiles(
content::BrowserContext* context,
const extensions::ExtensionId& extension_id)
: … { … }
SavedFilesService::SavedFiles::~SavedFiles() = default;
void SavedFilesService::SavedFiles::RegisterFileEntry(
const std::string& id,
const base::FilePath& file_path,
bool is_directory) { … }
void SavedFilesService::SavedFiles::EnqueueFileEntry(const std::string& id) { … }
bool SavedFilesService::SavedFiles::IsRegistered(const std::string& id) const { … }
const SavedFileEntry* SavedFilesService::SavedFiles::GetFileEntry(
const std::string& id) const { … }
std::vector<SavedFileEntry> SavedFilesService::SavedFiles::GetAllFileEntries()
const { … }
void SavedFilesService::SavedFiles::MaybeCompactSequenceNumbers() { … }
void SavedFilesService::SavedFiles::LoadSavedFileEntriesFromPreferences() { … }
void SavedFilesService::SetMaxSequenceNumberForTest(int max_value) { … }
void SavedFilesService::ClearMaxSequenceNumberForTest() { … }
void SavedFilesService::SetLruSizeForTest(int size) { … }
void SavedFilesService::ClearLruSizeForTest() { … }
}