Commit cb7287aa authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Replace GetForProfile by Get{FileSystem,DriveAppRegistry,DriveService)ByProfile.

This is preparation to start returning DriveIntegrationService always from
DriveIntegrationServiceFactory::{Get,Find}ForProfile.

BUG=284972
TEST=Ran unit_tests
R=kinaba@chromium.org, satorux@chromium.org

Review URL: https://codereview.chromium.org/23523022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221356 0039d316-1c4b-4281-b951-d872f2087c98
parent 997e87d1
...@@ -107,6 +107,8 @@ DownloadHandler::~DownloadHandler() { ...@@ -107,6 +107,8 @@ DownloadHandler::~DownloadHandler() {
DownloadHandler* DownloadHandler::GetForProfile(Profile* profile) { DownloadHandler* DownloadHandler::GetForProfile(Profile* profile) {
DriveIntegrationService* integration_service = DriveIntegrationService* integration_service =
DriveIntegrationServiceFactory::FindForProfile(profile); DriveIntegrationServiceFactory::FindForProfile(profile);
// TODO(hidehiko): FindForProfile will return the instance even if Drive is
// disabled. Needs to check the state. crbug.com/284972.
return integration_service ? integration_service->download_handler() : NULL; return integration_service ? integration_service->download_handler() : NULL;
} }
......
...@@ -70,12 +70,6 @@ const base::FilePath& GetDriveMyDriveMountPointPath() { ...@@ -70,12 +70,6 @@ const base::FilePath& GetDriveMyDriveMountPointPath() {
return drive_mydrive_mount_path; return drive_mydrive_mount_path;
} }
FileSystemInterface* GetFileSystem(Profile* profile) {
DriveIntegrationService* integration_service =
DriveIntegrationServiceFactory::GetForProfile(profile);
return integration_service ? integration_service->file_system() : NULL;
}
std::string ReadStringFromGDocFile(const base::FilePath& file_path, std::string ReadStringFromGDocFile(const base::FilePath& file_path,
const std::string& key) { const std::string& key) {
const int64 kMaxGDocSize = 4096; const int64 kMaxGDocSize = 4096;
...@@ -120,6 +114,15 @@ void MoveAllFilesFromDirectory(const base::FilePath& directory_from, ...@@ -120,6 +114,15 @@ void MoveAllFilesFromDirectory(const base::FilePath& directory_from,
} }
} }
// Returns DriveIntegrationService instance, if Drive is enabled.
// Otherwise, NULL.
DriveIntegrationService* GetIntegrationServiceByProfile(Profile* profile) {
// TODO(hidehiko): GetForProfile will return DriveIntegrationService
// regardless of mounting state. Needs to check the mounting state
// later. crbug.com/284972.
return DriveIntegrationServiceFactory::GetForProfile(profile);
}
} // namespace } // namespace
const base::FilePath& GetDriveGrandRootPath() { const base::FilePath& GetDriveGrandRootPath() {
...@@ -140,6 +143,14 @@ const base::FilePath& GetDriveMountPointPath() { ...@@ -140,6 +143,14 @@ const base::FilePath& GetDriveMountPointPath() {
return drive_mount_path; return drive_mount_path;
} }
FileSystemInterface* GetFileSystemByProfile(Profile* profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DriveIntegrationService* integration_service =
GetIntegrationServiceByProfile(profile);
return integration_service ? integration_service->file_system() : NULL;
}
FileSystemInterface* GetFileSystemByProfileId(void* profile_id) { FileSystemInterface* GetFileSystemByProfileId(void* profile_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
...@@ -148,7 +159,25 @@ FileSystemInterface* GetFileSystemByProfileId(void* profile_id) { ...@@ -148,7 +159,25 @@ FileSystemInterface* GetFileSystemByProfileId(void* profile_id) {
Profile* profile = reinterpret_cast<Profile*>(profile_id); Profile* profile = reinterpret_cast<Profile*>(profile_id);
if (!g_browser_process->profile_manager()->IsValidProfile(profile)) if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return NULL; return NULL;
return GetFileSystem(profile); return GetFileSystemByProfile(profile);
}
DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DriveIntegrationService* integration_service =
GetIntegrationServiceByProfile(profile);
return integration_service ?
integration_service->drive_app_registry() :
NULL;
}
DriveServiceInterface* GetDriveServiceByProfile(Profile* profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DriveIntegrationService* integration_service =
GetIntegrationServiceByProfile(profile);
return integration_service ? integration_service->drive_service() : NULL;
} }
bool IsSpecialResourceId(const std::string& resource_id) { bool IsSpecialResourceId(const std::string& resource_id) {
...@@ -192,7 +221,7 @@ void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) { ...@@ -192,7 +221,7 @@ void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) {
if (!IsUnderDriveMountPoint(path)) if (!IsUnderDriveMountPoint(path))
return; return;
FileSystemInterface* file_system = GetFileSystem(profile); FileSystemInterface* file_system = GetFileSystemByProfile(profile);
if (!file_system) if (!file_system)
return; return;
...@@ -319,7 +348,7 @@ void PrepareWritableFileAndRun(Profile* profile, ...@@ -319,7 +348,7 @@ void PrepareWritableFileAndRun(Profile* profile,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
FileSystemInterface* file_system = GetFileSystem(profile); FileSystemInterface* file_system = GetFileSystemByProfile(profile);
if (!file_system || !IsUnderDriveMountPoint(path)) { if (!file_system || !IsUnderDriveMountPoint(path)) {
content::BrowserThread::GetBlockingPool()->PostTask( content::BrowserThread::GetBlockingPool()->PostTask(
FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath())); FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath()));
...@@ -338,7 +367,7 @@ void EnsureDirectoryExists(Profile* profile, ...@@ -338,7 +367,7 @@ void EnsureDirectoryExists(Profile* profile,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
if (IsUnderDriveMountPoint(directory)) { if (IsUnderDriveMountPoint(directory)) {
FileSystemInterface* file_system = GetFileSystem(profile); FileSystemInterface* file_system = GetFileSystemByProfile(profile);
DCHECK(file_system); DCHECK(file_system);
file_system->CreateDirectory( file_system->CreateDirectory(
ExtractDrivePath(directory), ExtractDrivePath(directory),
......
...@@ -23,6 +23,8 @@ class FileSystemURL; ...@@ -23,6 +23,8 @@ class FileSystemURL;
namespace drive { namespace drive {
class DriveAppRegistry;
class DriveServiceInterface;
class FileSystemInterface; class FileSystemInterface;
class ResourceEntry; class ResourceEntry;
...@@ -71,6 +73,10 @@ const base::FilePath& GetDriveMyDriveRootPath(); ...@@ -71,6 +73,10 @@ const base::FilePath& GetDriveMyDriveRootPath();
// Returns the Drive mount point path, which looks like "/special/drive". // Returns the Drive mount point path, which looks like "/special/drive".
const base::FilePath& GetDriveMountPointPath(); const base::FilePath& GetDriveMountPointPath();
// Returns the FileSystem for the |profile|. If not available (not mounted
// or disabled), returns NULL.
FileSystemInterface* GetFileSystemByProfile(Profile* profile);
// Returns a FileSystemInterface instance for the |profile_id|, or NULL // Returns a FileSystemInterface instance for the |profile_id|, or NULL
// if the Profile for |profile_id| is destructed or Drive File System is // if the Profile for |profile_id| is destructed or Drive File System is
// disabled for the profile. // disabled for the profile.
...@@ -81,6 +87,14 @@ const base::FilePath& GetDriveMountPointPath(); ...@@ -81,6 +87,14 @@ const base::FilePath& GetDriveMountPointPath();
// This function must be called on UI thread. // This function must be called on UI thread.
FileSystemInterface* GetFileSystemByProfileId(void* profile_id); FileSystemInterface* GetFileSystemByProfileId(void* profile_id);
// Returns the DriveAppRegistry for the |profile|. If not available (not
// mounted or disabled), returns NULL.
DriveAppRegistry* GetDriveAppRegistryByProfile(Profile* profile);
// Returns the DriveService for the |profile|. If not available (not mounted
// or disabled), returns NULL.
DriveServiceInterface* GetDriveServiceByProfile(Profile* profile);
// Checks if the resource ID is a special one, which is effective only in our // Checks if the resource ID is a special one, which is effective only in our
// implementation and is not supposed to be sent to the server. // implementation and is not supposed to be sent to the server.
bool IsSpecialResourceId(const std::string& resource_id); bool IsSpecialResourceId(const std::string& resource_id);
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/drive/drive.pb.h" #include "chrome/browser/chromeos/drive/drive.pb.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h" #include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/event_router.h" #include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
...@@ -441,24 +440,20 @@ bool FileBrowserPrivateGetSizeStatsFunction::RunImpl() { ...@@ -441,24 +440,20 @@ bool FileBrowserPrivateGetSizeStatsFunction::RunImpl() {
return false; return false;
if (file_path == drive::util::GetDriveMountPointPath()) { if (file_path == drive::util::GetDriveMountPointPath()) {
drive::DriveIntegrationService* integration_service = drive::FileSystemInterface* file_system =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_); drive::util::GetFileSystemByProfile(profile());
// |integration_service| is NULL if Drive is disabled. if (!file_system) {
if (!integration_service) { // |file_system| is NULL if Drive is disabled.
// If stats couldn't be gotten for drive, result should be left // If stats couldn't be gotten for drive, result should be left
// undefined. See comments in GetDriveAvailableSpaceCallback(). // undefined. See comments in GetDriveAvailableSpaceCallback().
SendResponse(true); SendResponse(true);
return true; return true;
} }
drive::FileSystemInterface* file_system =
integration_service->file_system();
file_system->GetAvailableSpace( file_system->GetAvailableSpace(
base::Bind(&FileBrowserPrivateGetSizeStatsFunction:: base::Bind(&FileBrowserPrivateGetSizeStatsFunction::
GetDriveAvailableSpaceCallback, GetDriveAvailableSpaceCallback,
this)); this));
} else { } else {
uint64* total_size = new uint64(0); uint64* total_size = new uint64(0);
uint64* remaining_size = new uint64(0); uint64* remaining_size = new uint64(0);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h" #include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/logging.h" #include "chrome/browser/chromeos/drive/logging.h"
...@@ -141,10 +140,8 @@ bool FileBrowserPrivateAddMountFunction::RunImpl() { ...@@ -141,10 +140,8 @@ bool FileBrowserPrivateAddMountFunction::RunImpl() {
// Check if the source path is under Drive cache directory. // Check if the source path is under Drive cache directory.
if (drive::util::IsUnderDriveMountPoint(path)) { if (drive::util::IsUnderDriveMountPoint(path)) {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
drive::FileSystemInterface* file_system = drive::FileSystemInterface* file_system =
integration_service ? integration_service->file_system() : NULL; drive::util::GetFileSystemByProfile(profile());
if (!file_system) { if (!file_system) {
SendResponse(false); SendResponse(false);
break; break;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chrome/browser/chromeos/drive/drive.pb.h" #include "chrome/browser/chromeos/drive/drive.pb.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_errors.h" #include "chrome/browser/chromeos/drive/file_errors.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/fileapi/file_system_backend.h" #include "chrome/browser/chromeos/fileapi/file_system_backend.h"
...@@ -48,8 +48,8 @@ void ContinueGetSelectedFileInfo(Profile* profile, ...@@ -48,8 +48,8 @@ void ContinueGetSelectedFileInfo(Profile* profile,
void GetSelectedFileInfoInternal(Profile* profile, void GetSelectedFileInfoInternal(Profile* profile,
scoped_ptr<GetSelectedFileInfoParams> params) { scoped_ptr<GetSelectedFileInfoParams> params) {
DCHECK(profile); DCHECK(profile);
drive::DriveIntegrationService* integration_service = drive::FileSystemInterface* file_system =
drive::DriveIntegrationServiceFactory::GetForProfile(profile); drive::util::GetFileSystemByProfile(profile);
for (size_t i = params->selected_files.size(); for (size_t i = params->selected_files.size();
i < params->file_paths.size(); ++i) { i < params->file_paths.size(); ++i) {
...@@ -59,8 +59,8 @@ void GetSelectedFileInfoInternal(Profile* profile, ...@@ -59,8 +59,8 @@ void GetSelectedFileInfoInternal(Profile* profile,
params->selected_files.push_back( params->selected_files.push_back(
ui::SelectedFileInfo(file_path, base::FilePath())); ui::SelectedFileInfo(file_path, base::FilePath()));
} else { } else {
// |integration_service| is NULL if Drive is disabled. // |file_system| is NULL if Drive is disabled.
if (!integration_service) { if (!file_system) {
ContinueGetSelectedFileInfo(profile, ContinueGetSelectedFileInfo(profile,
params.Pass(), params.Pass(),
drive::FILE_ERROR_FAILED, drive::FILE_ERROR_FAILED,
...@@ -76,14 +76,14 @@ void GetSelectedFileInfoInternal(Profile* profile, ...@@ -76,14 +76,14 @@ void GetSelectedFileInfoInternal(Profile* profile,
ui::SelectedFileInfo(file_path, base::FilePath())); ui::SelectedFileInfo(file_path, base::FilePath()));
break; break;
case NEED_LOCAL_PATH_FOR_OPENING: case NEED_LOCAL_PATH_FOR_OPENING:
integration_service->file_system()->GetFileByPath( file_system->GetFileByPath(
drive::util::ExtractDrivePath(file_path), drive::util::ExtractDrivePath(file_path),
base::Bind(&ContinueGetSelectedFileInfo, base::Bind(&ContinueGetSelectedFileInfo,
profile, profile,
base::Passed(&params))); base::Passed(&params)));
return; // Remaining work is done in ContinueGetSelectedFileInfo. return; // Remaining work is done in ContinueGetSelectedFileInfo.
case NEED_LOCAL_PATH_FOR_SAVING: case NEED_LOCAL_PATH_FOR_SAVING:
integration_service->file_system()->GetFileByPathForSaving( file_system->GetFileByPathForSaving(
drive::util::ExtractDrivePath(file_path), drive::util::ExtractDrivePath(file_path),
base::Bind(&ContinueGetSelectedFileInfo, base::Bind(&ContinueGetSelectedFileInfo,
profile, profile,
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/chromeos/drive/drive_app_registry.h" #include "chrome/browser/chromeos/drive/drive_app_registry.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/file_task_executor.h" #include "chrome/browser/chromeos/drive/file_task_executor.h"
#include "chrome/browser/chromeos/file_manager/file_browser_handlers.h" #include "chrome/browser/chromeos/file_manager/file_browser_handlers.h"
...@@ -487,15 +486,14 @@ void FindAllTypesOfTasks( ...@@ -487,15 +486,14 @@ void FindAllTypesOfTasks(
// Google document are not opened by drive apps but file manager. // Google document are not opened by drive apps but file manager.
if (!has_google_document) { if (!has_google_document) {
drive::DriveIntegrationService* integration_service = drive::DriveAppRegistry* app_registry =
drive::DriveIntegrationServiceFactory::GetForProfile(profile); drive::util::GetDriveAppRegistryByProfile(profile);
// |integration_service| is NULL if Drive is disabled. if (!app_registry) {
if (!integration_service || !integration_service->drive_app_registry()) // |app_registry| is NULL if Drive is disabled.
return; return;
}
FindDriveAppTasks(*integration_service->drive_app_registry(), FindDriveAppTasks(*app_registry, path_mime_set, result_list);
path_mime_set,
result_list);
} }
// Find and append file handler tasks. We know there aren't duplicates // Find and append file handler tasks. We know there aren't duplicates
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/drive/drive.pb.h" #include "chrome/browser/chromeos/drive/drive.pb.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system.h" #include "chrome/browser/chromeos/drive/file_system.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
...@@ -202,11 +201,11 @@ bool OpenFileWithBrowser(Profile* profile, const base::FilePath& file_path) { ...@@ -202,11 +201,11 @@ bool OpenFileWithBrowser(Profile* profile, const base::FilePath& file_path) {
if (file_path.MatchesExtension(kCRXExtension)) { if (file_path.MatchesExtension(kCRXExtension)) {
if (drive::util::IsUnderDriveMountPoint(file_path)) { if (drive::util::IsUnderDriveMountPoint(file_path)) {
drive::DriveIntegrationService* integration_service = drive::FileSystemInterface* file_system =
drive::DriveIntegrationServiceFactory::GetForProfile(profile); drive::util::GetFileSystemByProfile(profile);
if (!integration_service) if (!file_system)
return false; return false;
integration_service->file_system()->GetFileByPath( file_system->GetFileByPath(
drive::util::ExtractDrivePath(file_path), drive::util::ExtractDrivePath(file_path),
base::Bind(&OnCRXDownloadCallback, profile)); base::Bind(&OnCRXDownloadCallback, profile));
} else { } else {
......
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