summaryrefslogtreecommitdiffstats
path: root/components/filesystem/file_system_impl.h
blob: 4c18dd562cfe39aff61b94c69f98275f62e6f8d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2015 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 COMPONENTS_FILESYSTEM_FILE_SYSTEM_IMPL_H_
#define COMPONENTS_FILESYSTEM_FILE_SYSTEM_IMPL_H_

#include "base/macros.h"
#include "components/filesystem/public/interfaces/file_system.mojom.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/strong_binding.h"

namespace base {
class FilePath;
}

namespace mojo {
class Connection;
}

namespace filesystem {
class FileSystemApp;

class LockTable;

class FileSystemImpl : public FileSystem {
 public:
  FileSystemImpl(mojo::Connection* connection,
                 mojo::InterfaceRequest<FileSystem> request,
                 LockTable* lock_table);
  ~FileSystemImpl() override;

  // |Files| implementation:

  // Current valid values for |file_system| are "temp" for a temporary
  // filesystem and "origin" for a persistent filesystem bound to the origin of
  // the URL of the caller.
  void OpenFileSystem(const mojo::String& file_system,
                      mojo::InterfaceRequest<Directory> directory,
                      FileSystemClientPtr client,
                      const OpenFileSystemCallback& callback) override;

 private:
  // Gets the system specific toplevel profile directory.
  base::FilePath GetSystemProfileDir() const;

  // Takes the origin string from |remote_application_url_|.
  std::string GetOriginFromRemoteApplicationURL() const;

  // Sanitizes |origin| so it is an acceptable filesystem name.
  void BuildSanitizedOrigin(const std::string& origin,
                            std::string* sanitized_origin);

  const std::string remote_application_url_;
  mojo::StrongBinding<FileSystem> binding_;
  LockTable* lock_table_;

  DISALLOW_COPY_AND_ASSIGN(FileSystemImpl);
};

}  // namespace filesystem

#endif  // COMPONENTS_FILESYSTEM_FILE_SYSTEM_IMPL_H_