Commit 767e2de4 authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Replace directly use of DriveIntegrationService to...

Replace directly use of DriveIntegrationService to drive::util::Get{DriveService,FileSystem}ByProfile.

As preparation to start returning DriveIntegrationService instance always by
DriveIntegrationServiceFactory::GetForProfile, this reduces its direct
usage.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221367 0039d316-1c4b-4281-b951-d872f2087c98
parent c04fd3dd
...@@ -215,6 +215,12 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { ...@@ -215,6 +215,12 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
// Returns a DriveIntegrationService. // Returns a DriveIntegrationService.
drive::DriveIntegrationService* GetIntegrationService(); drive::DriveIntegrationService* GetIntegrationService();
// Returns a DriveService instance.
drive::DriveServiceInterface* GetDriveService();
// Returns a FileSystem instance.
drive::FileSystemInterface* GetFileSystem();
// Called when the page is first loaded. // Called when the page is first loaded.
void OnPageLoaded(const base::ListValue* args); void OnPageLoaded(const base::ListValue* args);
...@@ -374,10 +380,26 @@ drive::DriveIntegrationService* ...@@ -374,10 +380,26 @@ drive::DriveIntegrationService*
DriveInternalsWebUIHandler::GetIntegrationService() { DriveInternalsWebUIHandler::GetIntegrationService() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// TODO(hidehiko): GetForProfile will return the instance always even if it
// is disabled. Needs to check the mounting state then. crbug.com/284972.
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
return drive::DriveIntegrationServiceFactory::GetForProfile(profile); return drive::DriveIntegrationServiceFactory::GetForProfile(profile);
} }
drive::DriveServiceInterface* DriveInternalsWebUIHandler::GetDriveService() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Profile* profile = Profile::FromWebUI(web_ui());
return drive::util::GetDriveServiceByProfile(profile);
}
drive::FileSystemInterface* DriveInternalsWebUIHandler::GetFileSystem() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Profile* profile = Profile::FromWebUI(web_ui());
return drive::util::GetFileSystemByProfile(profile);
}
void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) { void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
...@@ -522,22 +544,18 @@ void DriveInternalsWebUIHandler::OnGetFilesystemMetadataForLocal( ...@@ -522,22 +544,18 @@ void DriveInternalsWebUIHandler::OnGetFilesystemMetadataForLocal(
void DriveInternalsWebUIHandler::ClearAccessToken(const base::ListValue* args) { void DriveInternalsWebUIHandler::ClearAccessToken(const base::ListValue* args) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
drive::DriveIntegrationService* integration_service = drive::DriveServiceInterface* drive_service = GetDriveService();
GetIntegrationService(); if (drive_service)
if (!integration_service) drive_service->ClearAccessToken();
return;
integration_service->drive_service()->ClearAccessToken();
} }
void DriveInternalsWebUIHandler::ClearRefreshToken( void DriveInternalsWebUIHandler::ClearRefreshToken(
const base::ListValue* args) { const base::ListValue* args) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
drive::DriveIntegrationService* integration_service = drive::DriveServiceInterface* drive_service = GetDriveService();
GetIntegrationService(); if (drive_service)
if (!integration_service) drive_service->ClearRefreshToken();
return;
integration_service->drive_service()->ClearRefreshToken();
} }
void DriveInternalsWebUIHandler::ListFileEntries(const base::ListValue* args) { void DriveInternalsWebUIHandler::ListFileEntries(const base::ListValue* args) {
...@@ -630,24 +648,25 @@ void DriveInternalsWebUIHandler::UpdateGCacheContentsSection() { ...@@ -630,24 +648,25 @@ void DriveInternalsWebUIHandler::UpdateGCacheContentsSection() {
void DriveInternalsWebUIHandler::UpdateFileSystemContentsSection() { void DriveInternalsWebUIHandler::UpdateFileSystemContentsSection() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
drive::DriveIntegrationService* integration_service = drive::DriveServiceInterface* drive_service = GetDriveService();
GetIntegrationService(); drive::FileSystemInterface* file_system = GetFileSystem();
if (!integration_service) if (!drive_service || !file_system)
return; return;
// Start updating the file system tree section, if we have access token. // Start updating the file system tree section, if we have access token.
if (!integration_service->drive_service()->HasAccessToken()) if (!drive_service->HasAccessToken())
return; return;
// Start rendering the file system tree as text. // Start rendering the file system tree as text.
const base::FilePath root_path = drive::util::GetDriveGrandRootPath(); const base::FilePath root_path = drive::util::GetDriveGrandRootPath();
integration_service->file_system()->GetResourceEntryByPath( file_system->GetResourceEntryByPath(
root_path, root_path,
base::Bind(&DriveInternalsWebUIHandler::OnGetResourceEntryByPath, base::Bind(&DriveInternalsWebUIHandler::OnGetResourceEntryByPath,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
root_path)); root_path));
integration_service->file_system()->ReadDirectoryByPath( file_system->ReadDirectoryByPath(
root_path, root_path,
base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
...@@ -743,6 +762,7 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath( ...@@ -743,6 +762,7 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath(
if (error == drive::FILE_ERROR_OK) { if (error == drive::FILE_ERROR_OK) {
DCHECK(entries.get()); DCHECK(entries.get());
drive::FileSystemInterface* file_system = GetFileSystem();
std::string file_system_as_text; std::string file_system_as_text;
for (size_t i = 0; i < entries->size(); ++i) { for (size_t i = 0; i < entries->size(); ++i) {
const drive::ResourceEntry& entry = (*entries)[i]; const drive::ResourceEntry& entry = (*entries)[i];
...@@ -752,7 +772,7 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath( ...@@ -752,7 +772,7 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath(
file_system_as_text.append(FormatEntry(current_path, entry) + "\n"); file_system_as_text.append(FormatEntry(current_path, entry) + "\n");
if (entry.file_info().is_directory()) { if (entry.file_info().is_directory()) {
GetIntegrationService()->file_system()->ReadDirectoryByPath( file_system->ReadDirectoryByPath(
current_path, current_path,
base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
......
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