cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / filesystem / file_system_app.cc
blobc42b606b0bf83f65cde0b5736e89ae31de8aa54a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/filesystem/file_system_app.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "mojo/application/public/cpp/application_connection.h"
10 #include "mojo/application/public/cpp/application_impl.h"
12 namespace filesystem {
14 FileSystemApp::FileSystemApp() : app_(nullptr), in_shutdown_(false) {}
16 FileSystemApp::~FileSystemApp() {}
18 void FileSystemApp::Initialize(mojo::ApplicationImpl* app) {
19 app_ = app;
22 bool FileSystemApp::ConfigureIncomingConnection(
23 mojo::ApplicationConnection* connection) {
24 connection->AddService<FileSystem>(this);
25 return true;
28 void FileSystemApp::RegisterDirectoryToClient(DirectoryImpl* directory,
29 FileSystemClientPtr client) {
30 directory->set_connection_error_handler(
31 base::Bind(&FileSystemApp::OnDirectoryConnectionError,
32 base::Unretained(this),
33 directory));
34 client_mapping_.emplace_back(directory, client.Pass());
37 bool FileSystemApp::OnShellConnectionError() {
38 if (client_mapping_.empty()) {
39 // If we have no current connections, we can shutdown immediately.
40 return true;
43 in_shutdown_ = true;
45 // We have live connections. Send a notification to each one indicating that
46 // they should shutdown.
47 for (std::vector<Client>::iterator it = client_mapping_.begin();
48 it != client_mapping_.end(); ++it) {
49 it->fs_client_->OnFileSystemShutdown();
52 return false;
55 // |InterfaceFactory<Files>| implementation:
56 void FileSystemApp::Create(mojo::ApplicationConnection* connection,
57 mojo::InterfaceRequest<FileSystem> request) {
58 new FileSystemImpl(this, connection, request.Pass());
61 void FileSystemApp::OnDirectoryConnectionError(DirectoryImpl* directory) {
62 for (std::vector<Client>::iterator it = client_mapping_.begin();
63 it != client_mapping_.end(); ++it) {
64 if (it->directory_ == directory) {
65 client_mapping_.erase(it);
67 if (in_shutdown_ && client_mapping_.empty()) {
68 // We just cleared the last directory after our shell connection went
69 // away. Time to shut ourselves down.
70 app_->Quit();
73 return;
78 FileSystemApp::Client::Client(DirectoryImpl* directory,
79 FileSystemClientPtr fs_client)
80 : directory_(directory),
81 fs_client_(fs_client.Pass()) {
84 FileSystemApp::Client::Client(Client&& rhs)
85 : directory_(rhs.directory_),
86 fs_client_(rhs.fs_client_.Pass()) {
89 FileSystemApp::Client::~Client() {}
91 FileSystemApp::Client& FileSystemApp::Client::operator=(
92 FileSystemApp::Client&& rhs) {
93 directory_ = rhs.directory_;
94 fs_client_ = rhs.fs_client_.Pass();
95 return *this;
98 } // namespace filesystem