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() {
DownloadHandler* DownloadHandler::GetForProfile(Profile* profile) {
DriveIntegrationService* integration_service =
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;
}
......
......@@ -70,12 +70,6 @@ const base::FilePath& GetDriveMyDriveMountPointPath() {
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,
const std::string& key) {
const int64 kMaxGDocSize = 4096;
......@@ -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
const base::FilePath& GetDriveGrandRootPath() {
......@@ -140,6 +143,14 @@ const base::FilePath& GetDriveMountPointPath() {
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) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......@@ -148,7 +159,25 @@ FileSystemInterface* GetFileSystemByProfileId(void* profile_id) {
Profile* profile = reinterpret_cast<Profile*>(profile_id);
if (!g_browser_process->profile_manager()->IsValidProfile(profile))
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) {
......@@ -192,7 +221,7 @@ void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) {
if (!IsUnderDriveMountPoint(path))
return;
FileSystemInterface* file_system = GetFileSystem(profile);
FileSystemInterface* file_system = GetFileSystemByProfile(profile);
if (!file_system)
return;
......@@ -319,7 +348,7 @@ void PrepareWritableFileAndRun(Profile* profile,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
FileSystemInterface* file_system = GetFileSystem(profile);
FileSystemInterface* file_system = GetFileSystemByProfile(profile);
if (!file_system || !IsUnderDriveMountPoint(path)) {
content::BrowserThread::GetBlockingPool()->PostTask(
FROM_HERE, base::Bind(callback, FILE_ERROR_FAILED, base::FilePath()));
......@@ -338,7 +367,7 @@ void EnsureDirectoryExists(Profile* profile,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (IsUnderDriveMountPoint(directory)) {
FileSystemInterface* file_system = GetFileSystem(profile);
FileSystemInterface* file_system = GetFileSystemByProfile(profile);
DCHECK(file_system);
file_system->CreateDirectory(
ExtractDrivePath(directory),
......
......@@ -23,6 +23,8 @@ class FileSystemURL;
namespace drive {
class DriveAppRegistry;
class DriveServiceInterface;
class FileSystemInterface;
class ResourceEntry;
......@@ -71,6 +73,10 @@ const base::FilePath& GetDriveMyDriveRootPath();
// Returns the Drive mount point path, which looks like "/special/drive".
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
// if the Profile for |profile_id| is destructed or Drive File System is
// disabled for the profile.
......@@ -81,6 +87,14 @@ const base::FilePath& GetDriveMountPointPath();
// This function must be called on UI thread.
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
// implementation and is not supposed to be sent to the server.
bool IsSpecialResourceId(const std::string& resource_id);
......
......@@ -88,15 +88,15 @@ bool FileBrowserPrivateGetDriveEntryPropertiesFunction::RunImpl() {
properties_->SetString("fileUrl", file_url.spec());
// Start getting the file info.
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service) {
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile());
if (!file_system) {
// |file_system| is NULL if Drive is disabled or not mounted.
CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
return true;
}
integration_service->file_system()->GetResourceEntryByPath(
file_system->GetResourceEntryByPath(
file_path_,
base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction::
OnGetFileInfo, this));
......@@ -116,10 +116,12 @@ void FileBrowserPrivateGetDriveEntryPropertiesFunction::OnGetFileInfo(
FillDriveEntryPropertiesValue(*entry, properties_.get());
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service) {
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile_);
drive::DriveAppRegistry* app_registry =
drive::util::GetDriveAppRegistryByProfile(profile_);
if (!file_system || !app_registry) {
// |file_system| or |app_registry| is NULL if Drive is disabled.
CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
return;
}
......@@ -137,10 +139,9 @@ void FileBrowserPrivateGetDriveEntryPropertiesFunction::OnGetFileInfo(
// Get drive WebApps that can accept this file. We just need to extract the
// doc icon for the drive app, which is set as default.
ScopedVector<drive::DriveAppInfo> drive_apps;
integration_service->drive_app_registry()->GetAppsForFile(
file_path_.Extension(),
file_specific_info.content_mime_type(),
&drive_apps);
app_registry->GetAppsForFile(file_path_.Extension(),
file_specific_info.content_mime_type(),
&drive_apps);
if (!drive_apps.empty()) {
std::string default_task_id =
file_manager::file_tasks::GetDefaultTaskIdFromPrefs(
......@@ -162,7 +163,7 @@ void FileBrowserPrivateGetDriveEntryPropertiesFunction::OnGetFileInfo(
}
}
integration_service->file_system()->GetCacheEntryByPath(
file_system->GetCacheEntryByPath(
file_path_,
base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction::
CacheStateReceived, this));
......@@ -205,10 +206,8 @@ bool FileBrowserPrivatePinDriveFileFunction::RunImpl() {
!args_->GetBoolean(1, &set_pin))
return false;
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
drive::FileSystemInterface* file_system =
integration_service ? integration_service->file_system() : NULL;
drive::util::GetFileSystemByProfile(profile());
if (!file_system) // |file_system| is NULL if Drive is disabled.
return false;
......@@ -280,16 +279,16 @@ void FileBrowserPrivateGetDriveFilesFunction::GetFileOrSendResponse() {
// Get the file on the top of the queue.
base::FilePath drive_path = remaining_drive_paths_.front();
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service) {
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile());
if (!file_system) {
// |file_system| is NULL if Drive is disabled or not mounted.
OnFileReady(drive::FILE_ERROR_FAILED, drive_path,
scoped_ptr<drive::ResourceEntry>());
return;
}
integration_service->file_system()->GetFileByPath(
file_system->GetFileByPath(
drive_path,
base::Bind(&FileBrowserPrivateGetDriveFilesFunction::OnFileReady, this));
}
......@@ -338,6 +337,8 @@ bool FileBrowserPrivateCancelFileTransfersFunction::RunImpl() {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
// TODO(hidehiko): GetForProfile will return the instance regardless of
// preference. Will need to check the mounting state. crbug.com/284972.
if (!integration_service)
return false;
......@@ -406,13 +407,14 @@ bool FileBrowserPrivateSearchDriveFunction::RunImpl() {
if (!search_params->GetString("nextFeed", &next_feed))
return false;
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service || !integration_service->file_system())
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile());
if (!file_system) {
// |file_system| is NULL if Drive is disabled.
return false;
}
integration_service->file_system()->Search(
file_system->Search(
query, GURL(next_feed),
base::Bind(&FileBrowserPrivateSearchDriveFunction::OnSearch, this));
return true;
......@@ -488,11 +490,12 @@ bool FileBrowserPrivateSearchDriveMetadataFunction::RunImpl() {
max_results);
set_log_on_completion(true);
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service || !integration_service->file_system())
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile());
if (!file_system) {
// |file_system| is NULL if Drive is disabled.
return false;
}
int options = drive::SEARCH_METADATA_ALL;
// TODO(hirono): Switch to the JSON scheme compiler. http://crbug.com/241693
......@@ -505,7 +508,7 @@ bool FileBrowserPrivateSearchDriveMetadataFunction::RunImpl() {
else
DCHECK_EQ("ALL", types);
integration_service->file_system()->SearchMetadata(
file_system->SearchMetadata(
query,
options,
max_results,
......@@ -568,7 +571,8 @@ FileBrowserPrivateClearDriveCacheFunction::
bool FileBrowserPrivateClearDriveCacheFunction::RunImpl() {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
// TODO(hidehiko): GetForProfile will return the instance even if it is
// disabled. Needs to check the mounting state. crbug.com/284972.
if (!integration_service || !integration_service->file_system())
return false;
......@@ -590,26 +594,23 @@ FileBrowserPrivateGetDriveConnectionStateFunction::
}
bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() {
scoped_ptr<DictionaryValue> value(new DictionaryValue());
scoped_ptr<ListValue> reasons(new ListValue());
std::string type_string;
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
drive::DriveServiceInterface* drive_service =
drive::util::GetDriveServiceByProfile(profile());
bool ready = integration_service &&
integration_service->drive_service()->CanSendRequest();
bool ready = drive_service && drive_service->CanSendRequest();
bool is_connection_cellular =
net::NetworkChangeNotifier::IsConnectionCellular(
net::NetworkChangeNotifier::GetConnectionType());
std::string type_string;
scoped_ptr<ListValue> reasons(new ListValue());
if (net::NetworkChangeNotifier::IsOffline() || !ready) {
type_string = kDriveConnectionTypeOffline;
if (net::NetworkChangeNotifier::IsOffline())
reasons->AppendString(kDriveConnectionReasonNoNetwork);
if (!ready)
reasons->AppendString(kDriveConnectionReasonNotReady);
if (!integration_service)
if (!drive_service)
reasons->AppendString(kDriveConnectionReasonNoService);
} else if (
is_connection_cellular &&
......@@ -619,6 +620,7 @@ bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() {
type_string = kDriveConnectionTypeOnline;
}
scoped_ptr<DictionaryValue> value(new DictionaryValue());
value->SetString("type", type_string);
value->Set("reasons", reasons.release());
SetResult(value.release());
......@@ -636,12 +638,15 @@ FileBrowserPrivateRequestAccessTokenFunction::
}
bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
bool refresh;
args_->GetBoolean(0, &refresh);
if (!args_->GetBoolean(0, &refresh))
return false;
if (!integration_service) {
drive::DriveServiceInterface* drive_service =
drive::util::GetDriveServiceByProfile(profile());
if (!drive_service) {
// DriveService is not available.
SetResult(new base::StringValue(""));
SendResponse(true);
return true;
......@@ -649,11 +654,11 @@ bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() {
// If refreshing is requested, then clear the token to refetch it.
if (refresh)
integration_service->drive_service()->ClearAccessToken();
drive_service->ClearAccessToken();
// Retrieve the cached auth token (if available), otherwise the AuthService
// instance will try to refetch it.
integration_service->drive_service()->RequestAccessToken(
drive_service->RequestAccessToken(
base::Bind(&FileBrowserPrivateRequestAccessTokenFunction::
OnAccessTokenFetched, this));
return true;
......@@ -684,20 +689,20 @@ bool FileBrowserPrivateGetShareUrlFunction::RunImpl() {
base::FilePath drive_path = drive::util::ExtractDrivePath(path);
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service)
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile());
if (!file_system) {
// |file_system| is NULL if Drive is disabled.
return false;
}
integration_service->file_system()->GetShareUrl(
file_system->GetShareUrl(
drive_path,
file_manager::util::GetFileManagerBaseUrl(), // embed origin
base::Bind(&FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl, this));
return true;
}
void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl(
drive::FileError error,
const GURL& share_url) {
......
......@@ -15,7 +15,6 @@
#include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.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_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/event_router.h"
......@@ -441,24 +440,20 @@ bool FileBrowserPrivateGetSizeStatsFunction::RunImpl() {
return false;
if (file_path == drive::util::GetDriveMountPointPath()) {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service) {
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile());
if (!file_system) {
// |file_system| is NULL if Drive is disabled.
// If stats couldn't be gotten for drive, result should be left
// undefined. See comments in GetDriveAvailableSpaceCallback().
SendResponse(true);
return true;
}
drive::FileSystemInterface* file_system =
integration_service->file_system();
file_system->GetAvailableSpace(
base::Bind(&FileBrowserPrivateGetSizeStatsFunction::
GetDriveAvailableSpaceCallback,
this));
} else {
uint64* total_size = new uint64(0);
uint64* remaining_size = new uint64(0);
......
......@@ -6,7 +6,6 @@
#include "base/format_macros.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_util.h"
#include "chrome/browser/chromeos/drive/logging.h"
......@@ -141,10 +140,8 @@ bool FileBrowserPrivateAddMountFunction::RunImpl() {
// Check if the source path is under Drive cache directory.
if (drive::util::IsUnderDriveMountPoint(path)) {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
drive::FileSystemInterface* file_system =
integration_service ? integration_service->file_system() : NULL;
drive::util::GetFileSystemByProfile(profile());
if (!file_system) {
SendResponse(false);
break;
......
......@@ -6,8 +6,8 @@
#include "base/files/file_path.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_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
......@@ -48,8 +48,8 @@ void ContinueGetSelectedFileInfo(Profile* profile,
void GetSelectedFileInfoInternal(Profile* profile,
scoped_ptr<GetSelectedFileInfoParams> params) {
DCHECK(profile);
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile);
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile);
for (size_t i = params->selected_files.size();
i < params->file_paths.size(); ++i) {
......@@ -59,8 +59,8 @@ void GetSelectedFileInfoInternal(Profile* profile,
params->selected_files.push_back(
ui::SelectedFileInfo(file_path, base::FilePath()));
} else {
// |integration_service| is NULL if Drive is disabled.
if (!integration_service) {
// |file_system| is NULL if Drive is disabled.
if (!file_system) {
ContinueGetSelectedFileInfo(profile,
params.Pass(),
drive::FILE_ERROR_FAILED,
......@@ -76,14 +76,14 @@ void GetSelectedFileInfoInternal(Profile* profile,
ui::SelectedFileInfo(file_path, base::FilePath()));
break;
case NEED_LOCAL_PATH_FOR_OPENING:
integration_service->file_system()->GetFileByPath(
file_system->GetFileByPath(
drive::util::ExtractDrivePath(file_path),
base::Bind(&ContinueGetSelectedFileInfo,
profile,
base::Passed(&params)));
return; // Remaining work is done in ContinueGetSelectedFileInfo.
case NEED_LOCAL_PATH_FOR_SAVING:
integration_service->file_system()->GetFileByPathForSaving(
file_system->GetFileByPathForSaving(
drive::util::ExtractDrivePath(file_path),
base::Bind(&ContinueGetSelectedFileInfo,
profile,
......
......@@ -9,7 +9,6 @@
#include "base/prefs/pref_service.h"
#include "base/strings/stringprintf.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_task_executor.h"
#include "chrome/browser/chromeos/file_manager/file_browser_handlers.h"
......@@ -487,15 +486,14 @@ void FindAllTypesOfTasks(
// Google document are not opened by drive apps but file manager.
if (!has_google_document) {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile);
// |integration_service| is NULL if Drive is disabled.
if (!integration_service || !integration_service->drive_app_registry())
drive::DriveAppRegistry* app_registry =
drive::util::GetDriveAppRegistryByProfile(profile);
if (!app_registry) {
// |app_registry| is NULL if Drive is disabled.
return;
}
FindDriveAppTasks(*integration_service->drive_app_registry(),
path_mime_set,
result_list);
FindDriveAppTasks(*app_registry, path_mime_set, result_list);
}
// Find and append file handler tasks. We know there aren't duplicates
......
......@@ -10,7 +10,6 @@
#include "base/path_service.h"
#include "base/threading/sequenced_worker_pool.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_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) {
if (file_path.MatchesExtension(kCRXExtension)) {
if (drive::util::IsUnderDriveMountPoint(file_path)) {
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile);
if (!integration_service)
drive::FileSystemInterface* file_system =
drive::util::GetFileSystemByProfile(profile);
if (!file_system)
return false;
integration_service->file_system()->GetFileByPath(
file_system->GetFileByPath(
drive::util::ExtractDrivePath(file_path),
base::Bind(&OnCRXDownloadCallback, profile));
} 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