FilesystemManager::GetInstance().AddListener(this);
}
-FilesystemInstance::~FilesystemInstance() {}
+FilesystemInstance::~FilesystemInstance() {
+ LoggerD("enter");
+ FilesystemManager::GetInstance().StopListening();
+ FilesystemManager::GetInstance().RemoveListener();
+}
#define CHECK_EXIST(args, name, out) \
if (!args.contains(name)) { \
}
} // namespace
+std::vector<common::VirtualStorage> FilesystemManager::FillStorages() {
+ LoggerD("entered");
+ auto virtualStorages = common::VirtualFs::GetInstance().GetStorages();
+ if (ids_.empty()) {
+ for (auto storage : virtualStorages) {
+ if (storage.id_ >= 0) {
+ ids_.insert(storage.id_);
+ }
+ }
+ }
+ return virtualStorages;
+}
+
void FilesystemManager::FetchStorages(
const std::function<void(const std::vector<common::VirtualStorage>&)>& success_cb,
const std::function<void(FilesystemError)>& error_cb) {
- auto result = common::VirtualFs::GetInstance().GetStorages();
-
- for (auto storage : result) {
- if (storage.id_ >= 0) {
- ids_.insert(storage.id_);
- }
- }
-
+ auto result = FillStorages();
success_cb(result);
}
void FilesystemManager::StartListening() {
LoggerD("enter");
+ FillStorages();
if (!is_listener_registered_ && !ids_.empty()) {
int result = STORAGE_ERROR_NONE;
LoggerD("enter");
listener_ = listener;
}
+
+void FilesystemManager::RemoveListener() {
+ LoggerD("enter");
+ listener_ = NULL;
+}
} // namespace filesystem
} // namespace extension
const std::function<void(const FilesystemStat&)>& success_cb,
const std::function<void(FilesystemError)>& error_cb);
+ std::vector<common::VirtualStorage> FillStorages();
void FetchStorages(
const std::function<void(const std::vector<common::VirtualStorage>&)>& success_cb,
const std::function<void(FilesystemError)>& error_cb);
void StartListening();
void StopListening();
void AddListener(FilesystemStateChangeListener* listener);
+ void RemoveListener();
};
} // namespace filesystem
} // namespace extension