mount_path_util.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 2014 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. 4 5#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_MOUNT_PATH_UTIL_H_ 6#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_MOUNT_PATH_UTIL_H_ 7 8#include <string> 9 10#include "base/files/file_path.h" 11#include "storage/browser/fileapi/file_system_url.h" 12 13class Profile; 14 15namespace chromeos { 16namespace file_system_provider { 17 18class ProvidedFileSystemInterface; 19 20namespace util { 21 22// Constructs a safe mount point path for the provided file system. 23base::FilePath GetMountPath(Profile* profile, 24 const std::string& extension_id, 25 const std::string& file_system_id); 26 27// Checks whether a local path is handled by File System Provider API or not. 28bool IsFileSystemProviderLocalPath(const base::FilePath& local_path); 29 30// Finds a file system, which is responsible for handling the specified |url| by 31// analysing the mount path. Also, extract the file path from the virtual path 32// to be used by the file system operations. 33class FileSystemURLParser { 34 public: 35 explicit FileSystemURLParser(const storage::FileSystemURL& url); 36 virtual ~FileSystemURLParser(); 37 38 // Parses the |url| passed to the constructor. If parsing succeeds, then 39 // returns true. Otherwise, false. Must be called on UI thread. 40 bool Parse(); 41 42 ProvidedFileSystemInterface* file_system() const { return file_system_; } 43 const base::FilePath& file_path() const { return file_path_; } 44 45 private: 46 storage::FileSystemURL url_; 47 ProvidedFileSystemInterface* file_system_; 48 base::FilePath file_path_; 49 50 DISALLOW_COPY_AND_ASSIGN(FileSystemURLParser); 51}; 52 53// Finds a file system, which is responsible for handling the specified 54// |local_path| by analysing the mount point name. Alsoo, extract the file path 55// from the local path to be used by the file system operations. 56class LocalPathParser { 57 public: 58 LocalPathParser(Profile* profile, const base::FilePath& local_path); 59 virtual ~LocalPathParser(); 60 61 // Parses the |local_path| passed to the constructor. If parsing succeeds, 62 // then returns true. Otherwise, false. Must be called on UI thread. 63 bool Parse(); 64 65 ProvidedFileSystemInterface* file_system() const { return file_system_; } 66 const base::FilePath& file_path() const { return file_path_; } 67 68 private: 69 Profile* profile_; 70 base::FilePath local_path_; 71 ProvidedFileSystemInterface* file_system_; 72 base::FilePath file_path_; 73 74 DISALLOW_COPY_AND_ASSIGN(LocalPathParser); 75}; 76} // namespace util 77} // namespace file_system_provider 78} // namespace chromeos 79 80#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_MOUNT_PATH_UTIL_H_ 81