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

Unified Diff: components/filesystem/file_system_app.cc

Issue 1231493002: mandoline filesystem: Save cookie data to the mojo:filesystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT for jam's core services patch. Created 5 years, 5 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: components/filesystem/file_system_app.cc
diff --git a/components/filesystem/file_system_app.cc b/components/filesystem/file_system_app.cc
index d69df2eeff9d296fd13c6d0b23ddef667d758820..c1e3e16bb8fbd94ad3b4478a68ccff576e6ed119 100644
--- a/components/filesystem/file_system_app.cc
+++ b/components/filesystem/file_system_app.cc
@@ -4,24 +4,95 @@
#include "components/filesystem/file_system_app.h"
+#include "base/bind.h"
+#include "base/logging.h"
#include "mojo/application/public/cpp/application_connection.h"
+#include "mojo/application/public/cpp/application_impl.h"
namespace filesystem {
-FileSystemApp::FileSystemApp() {}
+FileSystemApp::FileSystemApp() : app_(nullptr), in_shutdown_(false) {}
FileSystemApp::~FileSystemApp() {}
+void FileSystemApp::Initialize(mojo::ApplicationImpl* app) {
+ app_ = app;
+}
+
bool FileSystemApp::ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) {
connection->AddService<FileSystem>(this);
return true;
}
+void FileSystemApp::RegisterDirectoryToClient(DirectoryImpl* directory,
+ FileSystemClientPtr client) {
+ directory->set_connection_error_handler(
+ base::Bind(&FileSystemApp::OnDirectoryConnectionError,
+ base::Unretained(this),
+ directory));
+ client_mapping_.emplace_back(directory, client.Pass());
+}
+
+bool FileSystemApp::OnShellConnectionError() {
+ if (client_mapping_.empty()) {
+ // If we have no current connections, we can shutdown immediately.
+ return true;
+ }
+
+ in_shutdown_ = true;
+
+ // We have live connections. Send a notification to each one indicating that
+ // they should shutdown.
+ for (std::vector<Client>::iterator it = client_mapping_.begin();
+ it != client_mapping_.end(); ++it) {
+ it->fs_client_->OnFileSystemShutdown();
+ }
+
+ return false;
+}
+
// |InterfaceFactory<Files>| implementation:
void FileSystemApp::Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<FileSystem> request) {
- new FileSystemImpl(connection, request.Pass());
+ new FileSystemImpl(this, connection, request.Pass());
+}
+
+void FileSystemApp::OnDirectoryConnectionError(DirectoryImpl* directory) {
+ for (std::vector<Client>::iterator it = client_mapping_.begin();
+ it != client_mapping_.end(); ++it) {
+ if (it->directory_ == directory) {
+ client_mapping_.erase(it);
+
+ if (in_shutdown_ && client_mapping_.empty()) {
+ // We just cleared the last directory after our shell connection went
+ // away. Time to shut ourselves down.
+ app_->QuitNow();
+ }
+
+ return;
+ }
+ }
+}
+
+FileSystemApp::Client::Client(DirectoryImpl* directory,
+ FileSystemClientPtr fs_client)
+ : directory_(directory),
+ fs_client_(fs_client.Pass()) {
+}
+
+FileSystemApp::Client::Client(Client&& rhs)
+ : directory_(rhs.directory_),
+ fs_client_(rhs.fs_client_.Pass()) {
+}
+
+FileSystemApp::Client::~Client() {}
+
+FileSystemApp::Client& FileSystemApp::Client::operator=(
+ FileSystemApp::Client&& rhs) {
+ directory_ = rhs.directory_;
+ fs_client_ = rhs.fs_client_.Pass();
+ return *this;
}
} // namespace filesystem

Powered by Google App Engine
This is Rietveld 408576698