blob: d4e4f13e4e75e6158dfae79c0b4c64d72969b716 [file] [log] [blame]
// Copyright 2013 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.
//
// This file provides file system related API functions.
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_
#include <string>
#include "base/platform_file.h"
#include "chrome/browser/chromeos/drive/file_errors.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
class GURL;
namespace base {
class FilePath;
}
namespace fileapi {
class FileSystemContext;
}
namespace file_manager {
// Implements the chrome.fileBrowserPrivate.requestFileSystem method.
class RequestFileSystemFunction : public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.requestFileSystem",
FILEBROWSERPRIVATE_REQUESTFILESYSTEM)
RequestFileSystemFunction();
protected:
virtual ~RequestFileSystemFunction();
// AsyncExtensionFunction overrides.
virtual bool RunImpl() OVERRIDE;
private:
void RespondSuccessOnUIThread(const std::string& name,
const GURL& root_path);
void RespondFailedOnUIThread(base::PlatformFileError error_code);
// Called when FileSystemContext::OpenFileSystem() is done.
void DidOpenFileSystem(
scoped_refptr<fileapi::FileSystemContext> file_system_context,
base::PlatformFileError result,
const std::string& name,
const GURL& root_path);
// Called when something goes wrong. Records the error to |error_| per the
// error code and reports that the private API function failed.
void DidFail(base::PlatformFileError error_code);
// Sets up file system access permissions to the extension identified by
// |child_id|.
bool SetupFileSystemAccessPermissions(
scoped_refptr<fileapi::FileSystemContext> file_system_context,
int child_id,
scoped_refptr<const extensions::Extension> extension);
};
// Base class for AddFileWatchFunction and RemoveFileWatchFunction. Although
// it's called "FileWatch", the class and its sub classes are used only for
// watching changes in directories.
class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
public:
FileWatchFunctionBase();
protected:
virtual ~FileWatchFunctionBase();
// Performs a file watch operation (ex. adds or removes a file watch).
virtual void PerformFileWatchOperation(
const base::FilePath& local_path,
const base::FilePath& virtual_path,
const std::string& extension_id) = 0;
// AsyncExtensionFunction overrides.
virtual bool RunImpl() OVERRIDE;
// Calls SendResponse() with |success| converted to base::Value.
void Respond(bool success);
};
// Implements the chrome.fileBrowserPrivate.addFileWatch method.
// Starts watching changes in directories.
class AddFileWatchFunction : public FileWatchFunctionBase {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.addFileWatch",
FILEBROWSERPRIVATE_ADDFILEWATCH)
AddFileWatchFunction();
protected:
virtual ~AddFileWatchFunction();
// FileWatchFunctionBase override.
virtual void PerformFileWatchOperation(
const base::FilePath& local_path,
const base::FilePath& virtual_path,
const std::string& extension_id) OVERRIDE;
};
// Implements the chrome.fileBrowserPrivate.removeFileWatch method.
// Stops watching changes in directories.
class RemoveFileWatchFunction : public FileWatchFunctionBase {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.removeFileWatch",
FILEBROWSERPRIVATE_REMOVEFILEWATCH)
RemoveFileWatchFunction();
protected:
virtual ~RemoveFileWatchFunction();
// FileWatchFunctionBase override.
virtual void PerformFileWatchOperation(
const base::FilePath& local_path,
const base::FilePath& virtual_path,
const std::string& extension_id) OVERRIDE;
};
// Implements the chrome.fileBrowserPrivate.setLastModified method.
// Sets last modified date in seconds of local file
class SetLastModifiedFunction : public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.setLastModified",
FILEBROWSERPRIVATE_SETLASTMODIFIED)
SetLastModifiedFunction();
protected:
virtual ~SetLastModifiedFunction();
// AsyncExtensionFunction overrides.
virtual bool RunImpl() OVERRIDE;
};
// Implements the chrome.fileBrowserPrivate.getSizeStats method.
class GetSizeStatsFunction : public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getSizeStats",
FILEBROWSERPRIVATE_GETSIZESTATS)
GetSizeStatsFunction();
protected:
virtual ~GetSizeStatsFunction();
// AsyncExtensionFunction overrides.
virtual bool RunImpl() OVERRIDE;
private:
void GetDriveAvailableSpaceCallback(drive::FileError error,
int64 bytes_total,
int64 bytes_used);
void GetSizeStatsCallback(const uint64* total_size,
const uint64* remaining_size);
};
// Implements the chrome.fileBrowserPrivate.getVolumeMetadata method.
// Retrieves devices meta-data. Expects volume's device path as an argument.
class GetVolumeMetadataFunction : public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getVolumeMetadata",
FILEBROWSERPRIVATE_GETVOLUMEMETADATA)
GetVolumeMetadataFunction();
protected:
virtual ~GetVolumeMetadataFunction();
// AsyncExtensionFunction overrides.
virtual bool RunImpl() OVERRIDE;
};
// Implements the chrome.fileBrowserPrivate.validatePathNameLength method.
class ValidatePathNameLengthFunction : public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.validatePathNameLength",
FILEBROWSERPRIVATE_VALIDATEPATHNAMELENGTH)
ValidatePathNameLengthFunction();
protected:
virtual ~ValidatePathNameLengthFunction();
void OnFilePathLimitRetrieved(size_t current_length, size_t max_length);
// AsyncExtensionFunction overrides.
virtual bool RunImpl() OVERRIDE;
};
// Implements the chrome.fileBrowserPrivate.formatDevice method.
// Formats Device given its mount path.
class FormatDeviceFunction : public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.formatDevice",
FILEBROWSERPRIVATE_FORMATDEVICE)
FormatDeviceFunction();
protected:
virtual ~FormatDeviceFunction();
// AsyncExtensionFunction overrides.
virtual bool RunImpl() OVERRIDE;
};
} // namespace file_manager
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_H_