Commit 81c5deab authored by achuith@chromium.org's avatar achuith@chromium.org

Replace FileManagerUtil class with namespace file_manager_util.

file_manager_util namespace is consistent with other utils in the codebase (platform_util, mime_util, file_util), and is the preferred way in the google style guide to do this kind of thing. The FileManagerUtil class is never initialized and has no state.

BUG=None, cleanup
TEST=Compiles, tests pass.
Review URL: http://codereview.chromium.org/8574054

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110600 0039d316-1c4b-4281-b951-d872f2087c98
parent 58264a37
......@@ -299,9 +299,9 @@ void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent(
if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
GURL source_url;
if (FileManagerUtil::ConvertFileToFileSystemUrl(profile_,
if (file_manager_util::ConvertFileToFileSystemUrl(profile_,
FilePath(mount_info.source_path),
FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(),
file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(),
&source_url)) {
mount_info_value->SetString("sourceUrl", source_url.spec());
}
......@@ -318,7 +318,7 @@ void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent(
mount_info.mount_condition) {
// Convert mount point path to relative path with the external file system
// exposed within File API.
if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_,
if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile_,
FilePath(mount_info.mount_path),
&relative_mount_path)) {
mount_info_value->SetString("mountPath",
......@@ -337,7 +337,7 @@ void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent(
mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE &&
!mount_info.mount_condition &&
event == chromeos::disks::DiskMountManager::MOUNTING) {
FileManagerUtil::ViewFolder(FilePath(mount_info.mount_path));
file_manager_util::ViewFolder(FilePath(mount_info.mount_path));
}
}
......
......@@ -89,8 +89,8 @@ MediaPlayer* MediaPlayer::GetInstance() {
void MediaPlayer::EnqueueMediaFile(Profile* profile,
const FilePath& file_path) {
GURL url;
if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path,
GetOriginUrl(), &url)) {
if (!file_manager_util::ConvertFileToFileSystemUrl(profile, file_path,
GetOriginUrl(), &url)) {
}
EnqueueMediaFileUrl(url);
}
......@@ -103,8 +103,8 @@ void MediaPlayer::EnqueueMediaFileUrl(const GURL& url) {
void MediaPlayer::ForcePlayMediaFile(Profile* profile,
const FilePath& file_path) {
GURL url;
if (!FileManagerUtil::ConvertFileToFileSystemUrl(profile, file_path,
GetOriginUrl(), &url)) {
if (!file_manager_util::ConvertFileToFileSystemUrl(profile, file_path,
GetOriginUrl(), &url)) {
return;
}
ForcePlayMediaURL(url);
......@@ -286,15 +286,15 @@ net::URLRequestJob* MediaPlayer::MaybeInterceptResponse(
}
GURL MediaPlayer::GetOriginUrl() const {
return FileManagerUtil::GetMediaPlayerUrl().GetOrigin();
return file_manager_util::GetMediaPlayerUrl().GetOrigin();
}
GURL MediaPlayer::GetMediaplayerPlaylistUrl() const {
return FileManagerUtil::GetMediaPlayerPlaylistUrl();
return file_manager_util::GetMediaPlayerPlaylistUrl();
}
GURL MediaPlayer::GetMediaPlayerUrl() const {
return FileManagerUtil::GetMediaPlayerUrl();
return file_manager_util::GetMediaPlayerUrl();
}
MediaPlayer::MediaPlayer()
......
......@@ -275,9 +275,9 @@ base::DictionaryValue* MountPointToValue(Profile* profile,
if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
GURL source_url;
if (FileManagerUtil::ConvertFileToFileSystemUrl(profile,
if (file_manager_util::ConvertFileToFileSystemUrl(profile,
FilePath(mount_point_info.source_path),
FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(),
file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(),
&source_url)) {
mount_info->SetString("sourceUrl", source_url.spec());
}
......@@ -288,7 +288,7 @@ base::DictionaryValue* MountPointToValue(Profile* profile,
FilePath relative_mount_path;
// Convert mount point path to relative path with the external file system
// exposed within File API.
if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile,
if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile,
FilePath(mount_point_info.mount_path),
&relative_mount_path)) {
mount_info->SetString("mountPath", relative_mount_path.value());
......@@ -1124,8 +1124,8 @@ void ViewFilesFunction::GetLocalPathsResponseOnUIThread(
for (FilePathList::const_iterator iter = files.begin();
iter != files.end();
++iter) {
FileManagerUtil::ViewItem(*iter,
internal_task_id == kEnqueueTaskId ||
file_manager_util::ViewItem(*iter,
internal_task_id == kEnqueueTaskId ||
// Start the first one, enqueue others.
iter != files.begin());
}
......@@ -1465,7 +1465,7 @@ bool GetVolumeMetadataFunction::RunImpl() {
std::string mount_path;
if (!volume->mount_path().empty()) {
FilePath relative_mount_path;
FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_,
file_manager_util::ConvertFileToRelativeFileSystemPath(profile_,
FilePath(volume->mount_path()), &relative_mount_path);
mount_path = relative_mount_path.value();
}
......
......@@ -38,6 +38,7 @@ using content::BrowserThread;
#define FILEBROWSER_DOMAIN "hhaomjibdihmijegdhdafkllkbggdgoj"
const char kFileBrowserDomain[] = FILEBROWSER_DOMAIN;
namespace file_manager_util {
namespace {
#define FILEBROWSER_URL(PATH) \
......@@ -135,30 +136,57 @@ int UMAExtensionIndex(const char *ext,
return 0;
}
// Convert numeric dialog type to a string.
std::string GetDialogTypeAsString(
SelectFileDialog::Type dialog_type) {
std::string type_str;
switch (dialog_type) {
case SelectFileDialog::SELECT_NONE:
type_str = "full-page";
break;
case SelectFileDialog::SELECT_FOLDER:
type_str = "folder";
break;
case SelectFileDialog::SELECT_SAVEAS_FILE:
type_str = "saveas-file";
break;
case SelectFileDialog::SELECT_OPEN_FILE:
type_str = "open-file";
break;
case SelectFileDialog::SELECT_OPEN_MULTI_FILE:
type_str = "open-multi-file";
break;
default:
NOTREACHED();
}
return type_str;
}
} // namespace
// static
GURL FileManagerUtil::GetFileBrowserExtensionUrl() {
GURL GetFileBrowserExtensionUrl() {
return GURL(kFileBrowserExtensionUrl);
}
// static
GURL FileManagerUtil::GetFileBrowserUrl() {
GURL GetFileBrowserUrl() {
return GURL(kBaseFileBrowserUrl);
}
// static
GURL FileManagerUtil::GetMediaPlayerUrl() {
GURL GetMediaPlayerUrl() {
return GURL(kMediaPlayerUrl);
}
// static
GURL FileManagerUtil::GetMediaPlayerPlaylistUrl() {
GURL GetMediaPlayerPlaylistUrl() {
return GURL(kMediaPlayerPlaylistUrl);
}
// static
bool FileManagerUtil::ConvertFileToFileSystemUrl(
bool ConvertFileToFileSystemUrl(
Profile* profile, const FilePath& full_file_path, const GURL& origin_url,
GURL* url) {
FilePath virtual_path;
......@@ -173,8 +201,7 @@ bool FileManagerUtil::ConvertFileToFileSystemUrl(
return true;
}
// static
bool FileManagerUtil::ConvertFileToRelativeFileSystemPath(
bool ConvertFileToRelativeFileSystemPath(
Profile* profile, const FilePath& full_file_path, FilePath* virtual_path) {
fileapi::FileSystemPathManager* path_manager =
profile->GetFileSystemContext()->path_manager();
......@@ -190,8 +217,7 @@ bool FileManagerUtil::ConvertFileToRelativeFileSystemPath(
return true;
}
// static
GURL FileManagerUtil::GetFileBrowserUrlWithParams(
GURL GetFileBrowserUrlWithParams(
SelectFileDialog::Type type,
const string16& title,
const FilePath& default_virtual_path,
......@@ -234,21 +260,19 @@ GURL FileManagerUtil::GetFileBrowserUrlWithParams(
// kChromeUIFileManagerURL could not be used since query parameters are not
// supported for it.
std::string url = FileManagerUtil::GetFileBrowserUrl().spec() +
std::string url = GetFileBrowserUrl().spec() +
'?' + net::EscapeUrlEncodedData(json_args, false);
return GURL(url);
}
// static
void FileManagerUtil::ViewFolder(const FilePath& dir) {
void ViewFolder(const FilePath& dir) {
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return;
FilePath virtual_path;
if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(),
dir,
&virtual_path)) {
if (!ConvertFileToRelativeFileSystemPath(browser->profile(), dir,
&virtual_path)) {
return;
}
......@@ -259,12 +283,11 @@ void FileManagerUtil::ViewFolder(const FilePath& dir) {
browser->ShowSingletonTabRespectRef(GURL(url));
}
// static
void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) {
void ViewItem(const FilePath& full_path, bool enqueue) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
bool result = BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&FileManagerUtil::ViewItem, full_path, enqueue));
base::Bind(&ViewItem, full_path, enqueue));
DCHECK(result);
return;
}
......@@ -321,34 +344,5 @@ void FileManagerUtil::ViewItem(const FilePath& full_path, bool enqueue) {
IDS_FILEBROWSER_ERROR_VIEWING_FILE));
}
// static
std::string FileManagerUtil::GetDialogTypeAsString(
SelectFileDialog::Type dialog_type) {
std::string type_str;
switch (dialog_type) {
case SelectFileDialog::SELECT_NONE:
type_str = "full-page";
break;
case SelectFileDialog::SELECT_FOLDER:
type_str = "folder";
break;
case SelectFileDialog::SELECT_SAVEAS_FILE:
type_str = "saveas-file";
break;
} // namespace file_manager_util
case SelectFileDialog::SELECT_OPEN_FILE:
type_str = "open-file";
break;
case SelectFileDialog::SELECT_OPEN_MULTI_FILE:
type_str = "open-multi-file";
break;
default:
NOTREACHED();
}
return type_str;
}
......@@ -16,47 +16,41 @@ class Profile;
extern const char kFileBrowserDomain[];
// Helper class for wiring file browser component extension with the rest of UI.
class FileManagerUtil {
public:
// Gets base file browser url.
static GURL GetFileBrowserExtensionUrl();
static GURL GetFileBrowserUrl();
static GURL GetMediaPlayerUrl();
static GURL GetMediaPlayerPlaylistUrl();
// Converts |full_file_path| into external filesystem: url. Returns false
// if |full_file_path| is not managed by the external filesystem provider.
static bool ConvertFileToFileSystemUrl(Profile* profile,
const FilePath& full_file_path, const GURL& origin_url, GURL* url);
// Converts |full_file_path| into |relative_path| within the external provider
// in File API. Returns false if |full_file_path| is not managed by the
// external filesystem provider.
static bool ConvertFileToRelativeFileSystemPath(Profile* profile,
const FilePath& full_file_path, FilePath* relative_path);
// Gets base file browser url for.
static GURL GetFileBrowserUrlWithParams(
SelectFileDialog::Type type,
const string16& title,
const FilePath& default_virtual_path,
const SelectFileDialog::FileTypeInfo* file_types,
int file_type_index,
const FilePath::StringType& default_extension);
// Opens file browser UI in its own tab on file system location defined with
// |dir|.
static void ViewFolder(const FilePath& dir);
static void ViewItem(const FilePath& full_path, bool enqueue);
private:
FileManagerUtil() {}
// Helper to convert numeric dialog type to a string.
static std::string GetDialogTypeAsString(SelectFileDialog::Type dialog_type);
DISALLOW_COPY_AND_ASSIGN(FileManagerUtil);
};
// File manager helper methods.
namespace file_manager_util {
// Gets base file browser url.
GURL GetFileBrowserExtensionUrl();
GURL GetFileBrowserUrl();
GURL GetMediaPlayerUrl();
GURL GetMediaPlayerPlaylistUrl();
// Converts |full_file_path| into external filesystem: url. Returns false
// if |full_file_path| is not managed by the external filesystem provider.
bool ConvertFileToFileSystemUrl(Profile* profile,
const FilePath& full_file_path, const GURL& origin_url, GURL* url);
// Converts |full_file_path| into |relative_path| within the external provider
// in File API. Returns false if |full_file_path| is not managed by the
// external filesystem provider.
bool ConvertFileToRelativeFileSystemPath(Profile* profile,
const FilePath& full_file_path, FilePath* relative_path);
// Gets base file browser url for.
GURL GetFileBrowserUrlWithParams(
SelectFileDialog::Type type,
const string16& title,
const FilePath& default_virtual_path,
const SelectFileDialog::FileTypeInfo* file_types,
int file_type_index,
const FilePath::StringType& default_extension);
// Opens file browser UI in its own tab on file system location defined with
// |dir|.
void ViewFolder(const FilePath& dir);
void ViewItem(const FilePath& full_path, bool enqueue);
} // namespace file_manager_util
#endif // CHROME_BROWSER_EXTENSIONS_FILE_MANAGER_UTIL_H_
......@@ -34,13 +34,12 @@ void OpenFileBrowserOnUIThread(const FilePath& dir) {
return;
FilePath virtual_path;
if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(),
dir,
&virtual_path)) {
if (!file_manager_util::ConvertFileToRelativeFileSystemPath(
browser->profile(), dir, &virtual_path)) {
return;
}
GURL url = FileManagerUtil::GetFileBrowserUrlWithParams(
GURL url = file_manager_util::GetFileBrowserUrlWithParams(
SelectFileDialog::SELECT_NONE, string16(), virtual_path, NULL, 0,
FilePath::StringType());
browser->ShowSingletonTab(url);
......@@ -60,9 +59,9 @@ void OpenItemOnFileThread(const FilePath& full_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
base::Closure callback;
if (file_util::DirectoryExists(full_path))
callback = base::Bind(&FileManagerUtil::ViewFolder, full_path);
callback = base::Bind(&file_manager_util::ViewFolder, full_path);
else
callback = base::Bind(&FileManagerUtil::ViewItem, full_path, false);
callback = base::Bind(&file_manager_util::ViewItem, full_path, false);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
}
......
......@@ -215,7 +215,7 @@ void SelectFileDialogExtension::SelectFileImpl(
return;
FilePath virtual_path;
if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(
if (!file_manager_util::ConvertFileToRelativeFileSystemPath(
owner_browser->profile(), default_path, &virtual_path)) {
virtual_path = default_path.BaseName();
}
......@@ -223,7 +223,7 @@ void SelectFileDialogExtension::SelectFileImpl(
hasMultipleFileTypeChoices_ =
file_types ? file_types->extensions.size() > 1 : true;
GURL file_browser_url = FileManagerUtil::GetFileBrowserUrlWithParams(
GURL file_browser_url = file_manager_util::GetFileBrowserUrlWithParams(
type, title, virtual_path, file_types, file_type_index,
default_extension);
......
......@@ -250,7 +250,7 @@ void ActiveDownloadsHandler::HandleCancelDownload(const ListValue* args) {
}
void ActiveDownloadsHandler::HandleShowAllFiles(const ListValue* args) {
FileManagerUtil::ViewFolder(
file_manager_util::ViewFolder(
DownloadPrefs::FromDownloadManager(download_manager_)->download_path());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment