| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" | 9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" |
| 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 GURL file_url = GURL(file_url_str); | 82 GURL file_url = GURL(file_url_str); |
| 83 file_path_ = drive::util::ExtractDrivePath( | 83 file_path_ = drive::util::ExtractDrivePath( |
| 84 file_manager::util::GetLocalPathFromURL( | 84 file_manager::util::GetLocalPathFromURL( |
| 85 render_view_host(), profile(), file_url)); | 85 render_view_host(), profile(), file_url)); |
| 86 | 86 |
| 87 properties_.reset(new base::DictionaryValue); | 87 properties_.reset(new base::DictionaryValue); |
| 88 properties_->SetString("fileUrl", file_url.spec()); | 88 properties_->SetString("fileUrl", file_url.spec()); |
| 89 | 89 |
| 90 // Start getting the file info. | 90 // Start getting the file info. |
| 91 drive::DriveIntegrationService* integration_service = | 91 drive::FileSystemInterface* file_system = |
| 92 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 92 drive::util::GetFileSystemByProfile(profile()); |
| 93 // |integration_service| is NULL if Drive is disabled. | 93 if (!file_system) { |
| 94 if (!integration_service) { | 94 // |file_system| is NULL if Drive is disabled or not mounted. |
| 95 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); | 95 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 integration_service->file_system()->GetResourceEntryByPath( | 99 file_system->GetResourceEntryByPath( |
| 100 file_path_, | 100 file_path_, |
| 101 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction:: | 101 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction:: |
| 102 OnGetFileInfo, this)); | 102 OnGetFileInfo, this)); |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void FileBrowserPrivateGetDriveEntryPropertiesFunction::OnGetFileInfo( | 106 void FileBrowserPrivateGetDriveEntryPropertiesFunction::OnGetFileInfo( |
| 107 drive::FileError error, | 107 drive::FileError error, |
| 108 scoped_ptr<drive::ResourceEntry> entry) { | 108 scoped_ptr<drive::ResourceEntry> entry) { |
| 109 DCHECK(properties_); | 109 DCHECK(properties_); |
| 110 | 110 |
| 111 if (error != drive::FILE_ERROR_OK) { | 111 if (error != drive::FILE_ERROR_OK) { |
| 112 CompleteGetFileProperties(error); | 112 CompleteGetFileProperties(error); |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 DCHECK(entry); | 115 DCHECK(entry); |
| 116 | 116 |
| 117 FillDriveEntryPropertiesValue(*entry, properties_.get()); | 117 FillDriveEntryPropertiesValue(*entry, properties_.get()); |
| 118 | 118 |
| 119 drive::DriveIntegrationService* integration_service = | 119 drive::FileSystemInterface* file_system = |
| 120 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 120 drive::util::GetFileSystemByProfile(profile_); |
| 121 // |integration_service| is NULL if Drive is disabled. | 121 drive::DriveAppRegistry* app_registry = |
| 122 if (!integration_service) { | 122 drive::util::GetDriveAppRegistryByProfile(profile_); |
| 123 if (!file_system || !app_registry) { |
| 124 // |file_system| or |app_registry| is NULL if Drive is disabled. |
| 123 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); | 125 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); |
| 124 return; | 126 return; |
| 125 } | 127 } |
| 126 | 128 |
| 127 // The properties meaningful for directories are already filled in | 129 // The properties meaningful for directories are already filled in |
| 128 // FillDriveEntryPropertiesValue(). | 130 // FillDriveEntryPropertiesValue(). |
| 129 if (entry.get() && !entry->has_file_specific_info()) { | 131 if (entry.get() && !entry->has_file_specific_info()) { |
| 130 CompleteGetFileProperties(error); | 132 CompleteGetFileProperties(error); |
| 131 return; | 133 return; |
| 132 } | 134 } |
| 133 | 135 |
| 134 const drive::FileSpecificInfo& file_specific_info = | 136 const drive::FileSpecificInfo& file_specific_info = |
| 135 entry->file_specific_info(); | 137 entry->file_specific_info(); |
| 136 | 138 |
| 137 // Get drive WebApps that can accept this file. We just need to extract the | 139 // Get drive WebApps that can accept this file. We just need to extract the |
| 138 // doc icon for the drive app, which is set as default. | 140 // doc icon for the drive app, which is set as default. |
| 139 ScopedVector<drive::DriveAppInfo> drive_apps; | 141 ScopedVector<drive::DriveAppInfo> drive_apps; |
| 140 integration_service->drive_app_registry()->GetAppsForFile( | 142 app_registry->GetAppsForFile(file_path_.Extension(), |
| 141 file_path_.Extension(), | 143 file_specific_info.content_mime_type(), |
| 142 file_specific_info.content_mime_type(), | 144 &drive_apps); |
| 143 &drive_apps); | |
| 144 if (!drive_apps.empty()) { | 145 if (!drive_apps.empty()) { |
| 145 std::string default_task_id = | 146 std::string default_task_id = |
| 146 file_manager::file_tasks::GetDefaultTaskIdFromPrefs( | 147 file_manager::file_tasks::GetDefaultTaskIdFromPrefs( |
| 147 *profile_->GetPrefs(), | 148 *profile_->GetPrefs(), |
| 148 file_specific_info.content_mime_type(), | 149 file_specific_info.content_mime_type(), |
| 149 file_path_.Extension()); | 150 file_path_.Extension()); |
| 150 file_manager::file_tasks::TaskDescriptor default_task; | 151 file_manager::file_tasks::TaskDescriptor default_task; |
| 151 file_manager::file_tasks::ParseTaskID(default_task_id, &default_task); | 152 file_manager::file_tasks::ParseTaskID(default_task_id, &default_task); |
| 152 DCHECK(default_task_id.empty() || !default_task.app_id.empty()); | 153 DCHECK(default_task_id.empty() || !default_task.app_id.empty()); |
| 153 for (size_t i = 0; i < drive_apps.size(); ++i) { | 154 for (size_t i = 0; i < drive_apps.size(); ++i) { |
| 154 const drive::DriveAppInfo* app_info = drive_apps[i]; | 155 const drive::DriveAppInfo* app_info = drive_apps[i]; |
| 155 if (default_task.app_id == app_info->app_id) { | 156 if (default_task.app_id == app_info->app_id) { |
| 156 // The drive app is set as default. Files.app should use the doc icon. | 157 // The drive app is set as default. Files.app should use the doc icon. |
| 157 const GURL doc_icon = | 158 const GURL doc_icon = |
| 158 drive::util::FindPreferredIcon(app_info->document_icons, | 159 drive::util::FindPreferredIcon(app_info->document_icons, |
| 159 drive::util::kPreferredIconSize); | 160 drive::util::kPreferredIconSize); |
| 160 properties_->SetString("customIconUrl", doc_icon.spec()); | 161 properties_->SetString("customIconUrl", doc_icon.spec()); |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 } | 164 } |
| 164 | 165 |
| 165 integration_service->file_system()->GetCacheEntryByPath( | 166 file_system->GetCacheEntryByPath( |
| 166 file_path_, | 167 file_path_, |
| 167 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction:: | 168 base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction:: |
| 168 CacheStateReceived, this)); | 169 CacheStateReceived, this)); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void FileBrowserPrivateGetDriveEntryPropertiesFunction::CacheStateReceived( | 172 void FileBrowserPrivateGetDriveEntryPropertiesFunction::CacheStateReceived( |
| 172 bool /* success */, | 173 bool /* success */, |
| 173 const drive::FileCacheEntry& cache_entry) { | 174 const drive::FileCacheEntry& cache_entry) { |
| 174 // In case of an error (i.e. success is false), cache_entry.is_*() all | 175 // In case of an error (i.e. success is false), cache_entry.is_*() all |
| 175 // returns false. | 176 // returns false. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 198 | 199 |
| 199 bool FileBrowserPrivatePinDriveFileFunction::RunImpl() { | 200 bool FileBrowserPrivatePinDriveFileFunction::RunImpl() { |
| 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 201 std::string url; | 202 std::string url; |
| 202 bool set_pin = false; | 203 bool set_pin = false; |
| 203 if (args_->GetSize() != 2 || | 204 if (args_->GetSize() != 2 || |
| 204 !args_->GetString(0, &url) || | 205 !args_->GetString(0, &url) || |
| 205 !args_->GetBoolean(1, &set_pin)) | 206 !args_->GetBoolean(1, &set_pin)) |
| 206 return false; | 207 return false; |
| 207 | 208 |
| 208 drive::DriveIntegrationService* integration_service = | |
| 209 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | |
| 210 drive::FileSystemInterface* file_system = | 209 drive::FileSystemInterface* file_system = |
| 211 integration_service ? integration_service->file_system() : NULL; | 210 drive::util::GetFileSystemByProfile(profile()); |
| 212 if (!file_system) // |file_system| is NULL if Drive is disabled. | 211 if (!file_system) // |file_system| is NULL if Drive is disabled. |
| 213 return false; | 212 return false; |
| 214 | 213 |
| 215 base::FilePath drive_path = | 214 base::FilePath drive_path = |
| 216 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( | 215 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( |
| 217 render_view_host(), profile(), GURL(url))); | 216 render_view_host(), profile(), GURL(url))); |
| 218 if (set_pin) { | 217 if (set_pin) { |
| 219 file_system->Pin(drive_path, | 218 file_system->Pin(drive_path, |
| 220 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: | 219 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: |
| 221 OnPinStateSet, this)); | 220 OnPinStateSet, this)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // Send the response if all files are obtained. | 272 // Send the response if all files are obtained. |
| 274 if (remaining_drive_paths_.empty()) { | 273 if (remaining_drive_paths_.empty()) { |
| 275 SetResult(local_paths_); | 274 SetResult(local_paths_); |
| 276 SendResponse(true); | 275 SendResponse(true); |
| 277 return; | 276 return; |
| 278 } | 277 } |
| 279 | 278 |
| 280 // Get the file on the top of the queue. | 279 // Get the file on the top of the queue. |
| 281 base::FilePath drive_path = remaining_drive_paths_.front(); | 280 base::FilePath drive_path = remaining_drive_paths_.front(); |
| 282 | 281 |
| 283 drive::DriveIntegrationService* integration_service = | 282 drive::FileSystemInterface* file_system = |
| 284 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 283 drive::util::GetFileSystemByProfile(profile()); |
| 285 // |integration_service| is NULL if Drive is disabled. | 284 if (!file_system) { |
| 286 if (!integration_service) { | 285 // |file_system| is NULL if Drive is disabled or not mounted. |
| 287 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, | 286 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, |
| 288 scoped_ptr<drive::ResourceEntry>()); | 287 scoped_ptr<drive::ResourceEntry>()); |
| 289 return; | 288 return; |
| 290 } | 289 } |
| 291 | 290 |
| 292 integration_service->file_system()->GetFileByPath( | 291 file_system->GetFileByPath( |
| 293 drive_path, | 292 drive_path, |
| 294 base::Bind(&FileBrowserPrivateGetDriveFilesFunction::OnFileReady, this)); | 293 base::Bind(&FileBrowserPrivateGetDriveFilesFunction::OnFileReady, this)); |
| 295 } | 294 } |
| 296 | 295 |
| 297 | 296 |
| 298 void FileBrowserPrivateGetDriveFilesFunction::OnFileReady( | 297 void FileBrowserPrivateGetDriveFilesFunction::OnFileReady( |
| 299 drive::FileError error, | 298 drive::FileError error, |
| 300 const base::FilePath& local_path, | 299 const base::FilePath& local_path, |
| 301 scoped_ptr<drive::ResourceEntry> entry) { | 300 scoped_ptr<drive::ResourceEntry> entry) { |
| 302 base::FilePath drive_path = remaining_drive_paths_.front(); | 301 base::FilePath drive_path = remaining_drive_paths_.front(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 331 } | 330 } |
| 332 | 331 |
| 333 bool FileBrowserPrivateCancelFileTransfersFunction::RunImpl() { | 332 bool FileBrowserPrivateCancelFileTransfersFunction::RunImpl() { |
| 334 ListValue* url_list = NULL; | 333 ListValue* url_list = NULL; |
| 335 if (!args_->GetList(0, &url_list)) | 334 if (!args_->GetList(0, &url_list)) |
| 336 return false; | 335 return false; |
| 337 | 336 |
| 338 drive::DriveIntegrationService* integration_service = | 337 drive::DriveIntegrationService* integration_service = |
| 339 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 338 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
| 340 // |integration_service| is NULL if Drive is disabled. | 339 // |integration_service| is NULL if Drive is disabled. |
| 340 // TODO(hidehiko): GetForProfile will return the instance regardless of |
| 341 // preference. Will need to check the mounting state. crbug.com/284972. |
| 341 if (!integration_service) | 342 if (!integration_service) |
| 342 return false; | 343 return false; |
| 343 | 344 |
| 344 // Create the mapping from file path to job ID. | 345 // Create the mapping from file path to job ID. |
| 345 drive::JobListInterface* job_list = integration_service->job_list(); | 346 drive::JobListInterface* job_list = integration_service->job_list(); |
| 346 DCHECK(job_list); | 347 DCHECK(job_list); |
| 347 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); | 348 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); |
| 348 | 349 |
| 349 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap; | 350 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap; |
| 350 PathToIdMap path_to_id_map; | 351 PathToIdMap path_to_id_map; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 return false; | 400 return false; |
| 400 | 401 |
| 401 std::string query; | 402 std::string query; |
| 402 if (!search_params->GetString("query", &query)) | 403 if (!search_params->GetString("query", &query)) |
| 403 return false; | 404 return false; |
| 404 | 405 |
| 405 std::string next_feed; | 406 std::string next_feed; |
| 406 if (!search_params->GetString("nextFeed", &next_feed)) | 407 if (!search_params->GetString("nextFeed", &next_feed)) |
| 407 return false; | 408 return false; |
| 408 | 409 |
| 409 drive::DriveIntegrationService* integration_service = | 410 drive::FileSystemInterface* file_system = |
| 410 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 411 drive::util::GetFileSystemByProfile(profile()); |
| 411 // |integration_service| is NULL if Drive is disabled. | 412 if (!file_system) { |
| 412 if (!integration_service || !integration_service->file_system()) | 413 // |file_system| is NULL if Drive is disabled. |
| 413 return false; | 414 return false; |
| 415 } |
| 414 | 416 |
| 415 integration_service->file_system()->Search( | 417 file_system->Search( |
| 416 query, GURL(next_feed), | 418 query, GURL(next_feed), |
| 417 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnSearch, this)); | 419 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnSearch, this)); |
| 418 return true; | 420 return true; |
| 419 } | 421 } |
| 420 | 422 |
| 421 void FileBrowserPrivateSearchDriveFunction::OnSearch( | 423 void FileBrowserPrivateSearchDriveFunction::OnSearch( |
| 422 drive::FileError error, | 424 drive::FileError error, |
| 423 const GURL& next_link, | 425 const GURL& next_link, |
| 424 scoped_ptr<std::vector<drive::SearchResultInfo> > results) { | 426 scoped_ptr<std::vector<drive::SearchResultInfo> > results) { |
| 425 if (error != drive::FILE_ERROR_OK) { | 427 if (error != drive::FILE_ERROR_OK) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 return false; | 483 return false; |
| 482 | 484 |
| 483 drive::util::Log(logging::LOG_INFO, | 485 drive::util::Log(logging::LOG_INFO, |
| 484 "%s[%d] called. (types: '%s', maxResults: '%d')", | 486 "%s[%d] called. (types: '%s', maxResults: '%d')", |
| 485 name().c_str(), | 487 name().c_str(), |
| 486 request_id(), | 488 request_id(), |
| 487 types.c_str(), | 489 types.c_str(), |
| 488 max_results); | 490 max_results); |
| 489 set_log_on_completion(true); | 491 set_log_on_completion(true); |
| 490 | 492 |
| 491 drive::DriveIntegrationService* integration_service = | 493 drive::FileSystemInterface* file_system = |
| 492 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 494 drive::util::GetFileSystemByProfile(profile()); |
| 493 // |integration_service| is NULL if Drive is disabled. | 495 if (!file_system) { |
| 494 if (!integration_service || !integration_service->file_system()) | 496 // |file_system| is NULL if Drive is disabled. |
| 495 return false; | 497 return false; |
| 498 } |
| 496 | 499 |
| 497 int options = drive::SEARCH_METADATA_ALL; | 500 int options = drive::SEARCH_METADATA_ALL; |
| 498 // TODO(hirono): Switch to the JSON scheme compiler. http://crbug.com/241693 | 501 // TODO(hirono): Switch to the JSON scheme compiler. http://crbug.com/241693 |
| 499 if (types == "EXCLUDE_DIRECTORIES") | 502 if (types == "EXCLUDE_DIRECTORIES") |
| 500 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES; | 503 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES; |
| 501 else if (types == "SHARED_WITH_ME") | 504 else if (types == "SHARED_WITH_ME") |
| 502 options = drive::SEARCH_METADATA_SHARED_WITH_ME; | 505 options = drive::SEARCH_METADATA_SHARED_WITH_ME; |
| 503 else if (types == "OFFLINE") | 506 else if (types == "OFFLINE") |
| 504 options = drive::SEARCH_METADATA_OFFLINE; | 507 options = drive::SEARCH_METADATA_OFFLINE; |
| 505 else | 508 else |
| 506 DCHECK_EQ("ALL", types); | 509 DCHECK_EQ("ALL", types); |
| 507 | 510 |
| 508 integration_service->file_system()->SearchMetadata( | 511 file_system->SearchMetadata( |
| 509 query, | 512 query, |
| 510 options, | 513 options, |
| 511 max_results, | 514 max_results, |
| 512 base::Bind(&FileBrowserPrivateSearchDriveMetadataFunction:: | 515 base::Bind(&FileBrowserPrivateSearchDriveMetadataFunction:: |
| 513 OnSearchMetadata, this)); | 516 OnSearchMetadata, this)); |
| 514 return true; | 517 return true; |
| 515 } | 518 } |
| 516 | 519 |
| 517 void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata( | 520 void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata( |
| 518 drive::FileError error, | 521 drive::FileError error, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 FileBrowserPrivateClearDriveCacheFunction() { | 564 FileBrowserPrivateClearDriveCacheFunction() { |
| 562 } | 565 } |
| 563 | 566 |
| 564 FileBrowserPrivateClearDriveCacheFunction:: | 567 FileBrowserPrivateClearDriveCacheFunction:: |
| 565 ~FileBrowserPrivateClearDriveCacheFunction() { | 568 ~FileBrowserPrivateClearDriveCacheFunction() { |
| 566 } | 569 } |
| 567 | 570 |
| 568 bool FileBrowserPrivateClearDriveCacheFunction::RunImpl() { | 571 bool FileBrowserPrivateClearDriveCacheFunction::RunImpl() { |
| 569 drive::DriveIntegrationService* integration_service = | 572 drive::DriveIntegrationService* integration_service = |
| 570 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 573 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
| 571 // |integration_service| is NULL if Drive is disabled. | 574 // TODO(hidehiko): GetForProfile will return the instance even if it is |
| 575 // disabled. Needs to check the mounting state. crbug.com/284972. |
| 572 if (!integration_service || !integration_service->file_system()) | 576 if (!integration_service || !integration_service->file_system()) |
| 573 return false; | 577 return false; |
| 574 | 578 |
| 575 // TODO(yoshiki): Receive a callback from JS-side and pass it to | 579 // TODO(yoshiki): Receive a callback from JS-side and pass it to |
| 576 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511 | 580 // ClearCacheAndRemountFileSystem(). http://crbug.com/140511 |
| 577 integration_service->ClearCacheAndRemountFileSystem( | 581 integration_service->ClearCacheAndRemountFileSystem( |
| 578 base::Bind(&DoNothingWithBool)); | 582 base::Bind(&DoNothingWithBool)); |
| 579 | 583 |
| 580 SendResponse(true); | 584 SendResponse(true); |
| 581 return true; | 585 return true; |
| 582 } | 586 } |
| 583 | 587 |
| 584 FileBrowserPrivateGetDriveConnectionStateFunction:: | 588 FileBrowserPrivateGetDriveConnectionStateFunction:: |
| 585 FileBrowserPrivateGetDriveConnectionStateFunction() { | 589 FileBrowserPrivateGetDriveConnectionStateFunction() { |
| 586 } | 590 } |
| 587 | 591 |
| 588 FileBrowserPrivateGetDriveConnectionStateFunction:: | 592 FileBrowserPrivateGetDriveConnectionStateFunction:: |
| 589 ~FileBrowserPrivateGetDriveConnectionStateFunction() { | 593 ~FileBrowserPrivateGetDriveConnectionStateFunction() { |
| 590 } | 594 } |
| 591 | 595 |
| 592 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() { | 596 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunImpl() { |
| 593 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 597 drive::DriveServiceInterface* drive_service = |
| 594 scoped_ptr<ListValue> reasons(new ListValue()); | 598 drive::util::GetDriveServiceByProfile(profile()); |
| 595 | 599 |
| 596 std::string type_string; | 600 bool ready = drive_service && drive_service->CanSendRequest(); |
| 597 drive::DriveIntegrationService* integration_service = | |
| 598 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | |
| 599 | |
| 600 bool ready = integration_service && | |
| 601 integration_service->drive_service()->CanSendRequest(); | |
| 602 bool is_connection_cellular = | 601 bool is_connection_cellular = |
| 603 net::NetworkChangeNotifier::IsConnectionCellular( | 602 net::NetworkChangeNotifier::IsConnectionCellular( |
| 604 net::NetworkChangeNotifier::GetConnectionType()); | 603 net::NetworkChangeNotifier::GetConnectionType()); |
| 605 | 604 |
| 605 std::string type_string; |
| 606 scoped_ptr<ListValue> reasons(new ListValue()); |
| 606 if (net::NetworkChangeNotifier::IsOffline() || !ready) { | 607 if (net::NetworkChangeNotifier::IsOffline() || !ready) { |
| 607 type_string = kDriveConnectionTypeOffline; | 608 type_string = kDriveConnectionTypeOffline; |
| 608 if (net::NetworkChangeNotifier::IsOffline()) | 609 if (net::NetworkChangeNotifier::IsOffline()) |
| 609 reasons->AppendString(kDriveConnectionReasonNoNetwork); | 610 reasons->AppendString(kDriveConnectionReasonNoNetwork); |
| 610 if (!ready) | 611 if (!ready) |
| 611 reasons->AppendString(kDriveConnectionReasonNotReady); | 612 reasons->AppendString(kDriveConnectionReasonNotReady); |
| 612 if (!integration_service) | 613 if (!drive_service) |
| 613 reasons->AppendString(kDriveConnectionReasonNoService); | 614 reasons->AppendString(kDriveConnectionReasonNoService); |
| 614 } else if ( | 615 } else if ( |
| 615 is_connection_cellular && | 616 is_connection_cellular && |
| 616 profile_->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular)) { | 617 profile_->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular)) { |
| 617 type_string = kDriveConnectionTypeMetered; | 618 type_string = kDriveConnectionTypeMetered; |
| 618 } else { | 619 } else { |
| 619 type_string = kDriveConnectionTypeOnline; | 620 type_string = kDriveConnectionTypeOnline; |
| 620 } | 621 } |
| 621 | 622 |
| 623 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 622 value->SetString("type", type_string); | 624 value->SetString("type", type_string); |
| 623 value->Set("reasons", reasons.release()); | 625 value->Set("reasons", reasons.release()); |
| 624 SetResult(value.release()); | 626 SetResult(value.release()); |
| 625 | 627 |
| 626 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); | 628 drive::util::Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); |
| 627 return true; | 629 return true; |
| 628 } | 630 } |
| 629 | 631 |
| 630 FileBrowserPrivateRequestAccessTokenFunction:: | 632 FileBrowserPrivateRequestAccessTokenFunction:: |
| 631 FileBrowserPrivateRequestAccessTokenFunction() { | 633 FileBrowserPrivateRequestAccessTokenFunction() { |
| 632 } | 634 } |
| 633 | 635 |
| 634 FileBrowserPrivateRequestAccessTokenFunction:: | 636 FileBrowserPrivateRequestAccessTokenFunction:: |
| 635 ~FileBrowserPrivateRequestAccessTokenFunction() { | 637 ~FileBrowserPrivateRequestAccessTokenFunction() { |
| 636 } | 638 } |
| 637 | 639 |
| 638 bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() { | 640 bool FileBrowserPrivateRequestAccessTokenFunction::RunImpl() { |
| 639 drive::DriveIntegrationService* integration_service = | |
| 640 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | |
| 641 bool refresh; | 641 bool refresh; |
| 642 args_->GetBoolean(0, &refresh); | 642 if (!args_->GetBoolean(0, &refresh)) |
| 643 return false; |
| 643 | 644 |
| 644 if (!integration_service) { | 645 drive::DriveServiceInterface* drive_service = |
| 646 drive::util::GetDriveServiceByProfile(profile()); |
| 647 |
| 648 if (!drive_service) { |
| 649 // DriveService is not available. |
| 645 SetResult(new base::StringValue("")); | 650 SetResult(new base::StringValue("")); |
| 646 SendResponse(true); | 651 SendResponse(true); |
| 647 return true; | 652 return true; |
| 648 } | 653 } |
| 649 | 654 |
| 650 // If refreshing is requested, then clear the token to refetch it. | 655 // If refreshing is requested, then clear the token to refetch it. |
| 651 if (refresh) | 656 if (refresh) |
| 652 integration_service->drive_service()->ClearAccessToken(); | 657 drive_service->ClearAccessToken(); |
| 653 | 658 |
| 654 // Retrieve the cached auth token (if available), otherwise the AuthService | 659 // Retrieve the cached auth token (if available), otherwise the AuthService |
| 655 // instance will try to refetch it. | 660 // instance will try to refetch it. |
| 656 integration_service->drive_service()->RequestAccessToken( | 661 drive_service->RequestAccessToken( |
| 657 base::Bind(&FileBrowserPrivateRequestAccessTokenFunction:: | 662 base::Bind(&FileBrowserPrivateRequestAccessTokenFunction:: |
| 658 OnAccessTokenFetched, this)); | 663 OnAccessTokenFetched, this)); |
| 659 return true; | 664 return true; |
| 660 } | 665 } |
| 661 | 666 |
| 662 void FileBrowserPrivateRequestAccessTokenFunction::OnAccessTokenFetched( | 667 void FileBrowserPrivateRequestAccessTokenFunction::OnAccessTokenFetched( |
| 663 google_apis::GDataErrorCode code, | 668 google_apis::GDataErrorCode code, |
| 664 const std::string& access_token) { | 669 const std::string& access_token) { |
| 665 SetResult(new base::StringValue(access_token)); | 670 SetResult(new base::StringValue(access_token)); |
| 666 SendResponse(true); | 671 SendResponse(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 677 std::string file_url; | 682 std::string file_url; |
| 678 if (!args_->GetString(0, &file_url)) | 683 if (!args_->GetString(0, &file_url)) |
| 679 return false; | 684 return false; |
| 680 | 685 |
| 681 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 686 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 682 render_view_host(), profile(), GURL(file_url)); | 687 render_view_host(), profile(), GURL(file_url)); |
| 683 DCHECK(drive::util::IsUnderDriveMountPoint(path)); | 688 DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
| 684 | 689 |
| 685 base::FilePath drive_path = drive::util::ExtractDrivePath(path); | 690 base::FilePath drive_path = drive::util::ExtractDrivePath(path); |
| 686 | 691 |
| 687 drive::DriveIntegrationService* integration_service = | 692 drive::FileSystemInterface* file_system = |
| 688 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 693 drive::util::GetFileSystemByProfile(profile()); |
| 689 // |integration_service| is NULL if Drive is disabled. | 694 if (!file_system) { |
| 690 if (!integration_service) | 695 // |file_system| is NULL if Drive is disabled. |
| 691 return false; | 696 return false; |
| 697 } |
| 692 | 698 |
| 693 integration_service->file_system()->GetShareUrl( | 699 file_system->GetShareUrl( |
| 694 drive_path, | 700 drive_path, |
| 695 file_manager::util::GetFileManagerBaseUrl(), // embed origin | 701 file_manager::util::GetFileManagerBaseUrl(), // embed origin |
| 696 base::Bind(&FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl, this)); | 702 base::Bind(&FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl, this)); |
| 697 return true; | 703 return true; |
| 698 } | 704 } |
| 699 | 705 |
| 700 | |
| 701 void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl( | 706 void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl( |
| 702 drive::FileError error, | 707 drive::FileError error, |
| 703 const GURL& share_url) { | 708 const GURL& share_url) { |
| 704 if (error != drive::FILE_ERROR_OK) { | 709 if (error != drive::FILE_ERROR_OK) { |
| 705 error_ = "Share Url for this item is not available."; | 710 error_ = "Share Url for this item is not available."; |
| 706 SendResponse(false); | 711 SendResponse(false); |
| 707 return; | 712 return; |
| 708 } | 713 } |
| 709 | 714 |
| 710 SetResult(new base::StringValue(share_url.spec())); | 715 SetResult(new base::StringValue(share_url.spec())); |
| 711 SendResponse(true); | 716 SendResponse(true); |
| 712 } | 717 } |
| 713 | 718 |
| 714 } // namespace extensions | 719 } // namespace extensions |
| OLD | NEW |