Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_browser_private_a pi.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a pi.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/statvfs.h> | 8 #include <sys/statvfs.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <utime.h> | 10 #include <utime.h> |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 VLOG(1) << " " << suffixes_str; | 356 VLOG(1) << " " << suffixes_str; |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 | 359 |
| 360 // Does nothing with a bool parameter. Used as a placeholder for calling | 360 // Does nothing with a bool parameter. Used as a placeholder for calling |
| 361 // ClearCacheAndRemountFileSystem(). TODO(yoshiki): Handle an error from | 361 // ClearCacheAndRemountFileSystem(). TODO(yoshiki): Handle an error from |
| 362 // ClearCacheAndRemountFileSystem() properly: http://crbug.com/140511. | 362 // ClearCacheAndRemountFileSystem() properly: http://crbug.com/140511. |
| 363 void DoNothingWithBool(bool /* success */) { | 363 void DoNothingWithBool(bool /* success */) { |
| 364 } | 364 } |
| 365 | 365 |
| 366 void FillDriveFilePropertiesValue( | 366 void FillDriveEntryPropertiesValue( |
| 367 const drive::DriveEntryProto& entry_proto, | 367 const drive::DriveEntryProto& entry_proto, |
| 368 DictionaryValue* property_dict) { | 368 DictionaryValue* property_dict) { |
| 369 property_dict->SetBoolean("sharedWithMe", entry_proto.shared_with_me()); | |
| 370 | |
| 371 if (!entry_proto.has_file_specific_info()) | |
| 372 return; | |
| 373 | |
| 369 const drive::DriveFileSpecificInfo& file_specific_info = | 374 const drive::DriveFileSpecificInfo& file_specific_info = |
| 370 entry_proto.file_specific_info(); | 375 entry_proto.file_specific_info(); |
| 371 | 376 |
| 372 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); | 377 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); |
| 373 | 378 |
| 374 if (!file_specific_info.alternate_url().empty()) | 379 if (!file_specific_info.alternate_url().empty()) |
| 375 property_dict->SetString("editUrl", file_specific_info.alternate_url()); | 380 property_dict->SetString("editUrl", file_specific_info.alternate_url()); |
| 376 | 381 |
| 377 if (!file_specific_info.share_url().empty()) | 382 if (!file_specific_info.share_url().empty()) |
| 378 property_dict->SetString("shareUrl", file_specific_info.share_url()); | 383 property_dict->SetString("shareUrl", file_specific_info.share_url()); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 registry->RegisterFunction<AddFileWatchBrowserFunction>(); | 563 registry->RegisterFunction<AddFileWatchBrowserFunction>(); |
| 559 registry->RegisterFunction<RemoveFileWatchBrowserFunction>(); | 564 registry->RegisterFunction<RemoveFileWatchBrowserFunction>(); |
| 560 registry->RegisterFunction<SelectFileFunction>(); | 565 registry->RegisterFunction<SelectFileFunction>(); |
| 561 registry->RegisterFunction<SelectFilesFunction>(); | 566 registry->RegisterFunction<SelectFilesFunction>(); |
| 562 registry->RegisterFunction<AddMountFunction>(); | 567 registry->RegisterFunction<AddMountFunction>(); |
| 563 registry->RegisterFunction<RemoveMountFunction>(); | 568 registry->RegisterFunction<RemoveMountFunction>(); |
| 564 registry->RegisterFunction<GetMountPointsFunction>(); | 569 registry->RegisterFunction<GetMountPointsFunction>(); |
| 565 registry->RegisterFunction<GetSizeStatsFunction>(); | 570 registry->RegisterFunction<GetSizeStatsFunction>(); |
| 566 registry->RegisterFunction<FormatDeviceFunction>(); | 571 registry->RegisterFunction<FormatDeviceFunction>(); |
| 567 registry->RegisterFunction<ViewFilesFunction>(); | 572 registry->RegisterFunction<ViewFilesFunction>(); |
| 568 registry->RegisterFunction<GetDriveFilePropertiesFunction>(); | 573 registry->RegisterFunction<GetDriveEntryPropertiesFunction>(); |
| 569 registry->RegisterFunction<PinDriveFileFunction>(); | 574 registry->RegisterFunction<PinDriveFileFunction>(); |
| 570 registry->RegisterFunction<GetFileLocationsFunction>(); | 575 registry->RegisterFunction<GetFileLocationsFunction>(); |
| 571 registry->RegisterFunction<GetDriveFilesFunction>(); | 576 registry->RegisterFunction<GetDriveFilesFunction>(); |
| 572 registry->RegisterFunction<CancelFileTransfersFunction>(); | 577 registry->RegisterFunction<CancelFileTransfersFunction>(); |
| 573 registry->RegisterFunction<TransferFileFunction>(); | 578 registry->RegisterFunction<TransferFileFunction>(); |
| 574 registry->RegisterFunction<GetPreferencesFunction>(); | 579 registry->RegisterFunction<GetPreferencesFunction>(); |
| 575 registry->RegisterFunction<SetPreferencesFunction>(); | 580 registry->RegisterFunction<SetPreferencesFunction>(); |
| 576 registry->RegisterFunction<SearchDriveFunction>(); | 581 registry->RegisterFunction<SearchDriveFunction>(); |
| 577 registry->RegisterFunction<SearchDriveMetadataFunction>(); | 582 registry->RegisterFunction<SearchDriveMetadataFunction>(); |
| 578 registry->RegisterFunction<ClearDriveCacheFunction>(); | 583 registry->RegisterFunction<ClearDriveCacheFunction>(); |
| (...skipping 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2298 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; | 2303 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; |
| 2299 chromeos::system::StatisticsProvider* provider = | 2304 chromeos::system::StatisticsProvider* provider = |
| 2300 chromeos::system::StatisticsProvider::GetInstance(); | 2305 chromeos::system::StatisticsProvider::GetInstance(); |
| 2301 if (!provider->GetMachineStatistic(kMachineInfoBoard, &board)) | 2306 if (!provider->GetMachineStatistic(kMachineInfoBoard, &board)) |
| 2302 board = "unknown"; | 2307 board = "unknown"; |
| 2303 dict->SetString(kMachineInfoBoard, board); | 2308 dict->SetString(kMachineInfoBoard, board); |
| 2304 | 2309 |
| 2305 return true; | 2310 return true; |
| 2306 } | 2311 } |
| 2307 | 2312 |
| 2308 GetDriveFilePropertiesFunction::GetDriveFilePropertiesFunction() { | 2313 GetDriveEntryPropertiesFunction::GetDriveEntryPropertiesFunction() { |
| 2309 } | 2314 } |
| 2310 | 2315 |
| 2311 GetDriveFilePropertiesFunction::~GetDriveFilePropertiesFunction() { | 2316 GetDriveEntryPropertiesFunction::~GetDriveEntryPropertiesFunction() { |
| 2312 } | 2317 } |
| 2313 | 2318 |
| 2314 bool GetDriveFilePropertiesFunction::RunImpl() { | 2319 bool GetDriveEntryPropertiesFunction::RunImpl() { |
| 2315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2316 | 2321 |
| 2317 std::string file_url_str; | 2322 std::string file_url_str; |
| 2318 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) | 2323 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) |
| 2319 return false; | 2324 return false; |
| 2320 | 2325 |
| 2321 GURL file_url = GURL(file_url_str); | 2326 GURL file_url = GURL(file_url_str); |
| 2322 file_path_ = drive::util::ExtractDrivePath(GetLocalPathFromURL(file_url)); | 2327 file_path_ = drive::util::ExtractDrivePath(GetLocalPathFromURL(file_url)); |
| 2323 | 2328 |
| 2324 properties_.reset(new base::DictionaryValue); | 2329 properties_.reset(new base::DictionaryValue); |
| 2325 properties_->SetString("fileUrl", file_url.spec()); | 2330 properties_->SetString("fileUrl", file_url.spec()); |
| 2326 | 2331 |
| 2327 // Start getting the file info. | 2332 // Start getting the file info. |
| 2328 drive::DriveSystemService* system_service = | 2333 drive::DriveSystemService* system_service = |
| 2329 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2334 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2330 // |system_service| is NULL if Drive is disabled. | 2335 // |system_service| is NULL if Drive is disabled. |
| 2331 if (!system_service) { | 2336 if (!system_service) { |
| 2332 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); | 2337 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); |
| 2333 return true; | 2338 return true; |
| 2334 } | 2339 } |
| 2335 | 2340 |
| 2336 system_service->file_system()->GetEntryInfoByPath( | 2341 system_service->file_system()->GetEntryInfoByPath( |
| 2337 file_path_, | 2342 file_path_, |
| 2338 base::Bind(&GetDriveFilePropertiesFunction::OnGetFileInfo, this)); | 2343 base::Bind(&GetDriveEntryPropertiesFunction::OnGetFileInfo, this)); |
| 2339 return true; | 2344 return true; |
| 2340 } | 2345 } |
| 2341 | 2346 |
| 2342 void GetDriveFilePropertiesFunction::OnGetFileInfo( | 2347 void GetDriveEntryPropertiesFunction::OnGetFileInfo( |
| 2343 drive::FileError error, | 2348 drive::FileError error, |
| 2344 scoped_ptr<drive::DriveEntryProto> entry) { | 2349 scoped_ptr<drive::DriveEntryProto> entry) { |
| 2345 DCHECK(properties_); | 2350 DCHECK(properties_); |
| 2346 | 2351 |
| 2347 if (entry.get() && !entry->has_file_specific_info()) | |
| 2348 error = drive::FILE_ERROR_NOT_FOUND; | |
| 2349 | |
| 2350 if (error != drive::FILE_ERROR_OK) { | 2352 if (error != drive::FILE_ERROR_OK) { |
| 2351 CompleteGetFileProperties(error); | 2353 CompleteGetFileProperties(error); |
| 2352 return; | 2354 return; |
| 2353 } | 2355 } |
| 2354 DCHECK(entry); | 2356 DCHECK(entry); |
| 2355 | 2357 |
| 2356 const drive::DriveFileSpecificInfo& file_specific_info = | 2358 FillDriveEntryPropertiesValue(*entry, properties_.get()); |
| 2357 entry->file_specific_info(); | |
| 2358 | |
| 2359 FillDriveFilePropertiesValue(*entry, properties_.get()); | |
| 2360 | 2359 |
| 2361 drive::DriveSystemService* system_service = | 2360 drive::DriveSystemService* system_service = |
| 2362 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2361 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2363 // |system_service| is NULL if Drive is disabled. | 2362 // |system_service| is NULL if Drive is disabled. |
| 2364 if (!system_service) { | 2363 if (!system_service) { |
| 2365 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); | 2364 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); |
| 2366 return; | 2365 return; |
| 2367 } | 2366 } |
| 2368 | 2367 |
| 2368 // The properties meaningful for directories are already filled. | |
|
satorux1
2013/05/01 06:04:41
please describe where that information was filled,
Haruki Sato
2013/05/01 06:26:31
Done.
| |
| 2369 if (entry.get() && !entry->has_file_specific_info()) { | |
| 2370 CompleteGetFileProperties(error); | |
| 2371 return; | |
| 2372 } | |
| 2373 | |
| 2374 const drive::DriveFileSpecificInfo& file_specific_info = | |
| 2375 entry->file_specific_info(); | |
| 2376 | |
| 2369 // Get drive WebApps that can accept this file. | 2377 // Get drive WebApps that can accept this file. |
| 2370 ScopedVector<drive::DriveWebAppInfo> web_apps; | 2378 ScopedVector<drive::DriveWebAppInfo> web_apps; |
| 2371 system_service->webapps_registry()->GetWebAppsForFile( | 2379 system_service->webapps_registry()->GetWebAppsForFile( |
| 2372 file_path_, file_specific_info.content_mime_type(), &web_apps); | 2380 file_path_, file_specific_info.content_mime_type(), &web_apps); |
| 2373 if (!web_apps.empty()) { | 2381 if (!web_apps.empty()) { |
| 2374 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs( | 2382 std::string default_task_id = file_handler_util::GetDefaultTaskIdFromPrefs( |
| 2375 profile_, | 2383 profile_, |
| 2376 file_specific_info.content_mime_type(), | 2384 file_specific_info.content_mime_type(), |
| 2377 file_path_.Extension()); | 2385 file_path_.Extension()); |
| 2378 std::string default_app_id; | 2386 std::string default_app_id; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2398 app->SetString("docIcon", doc_icon.spec()); | 2406 app->SetString("docIcon", doc_icon.spec()); |
| 2399 app->SetString("objectType", webapp_info->object_type); | 2407 app->SetString("objectType", webapp_info->object_type); |
| 2400 app->SetBoolean("isPrimary", default_app_id == webapp_info->app_id); | 2408 app->SetBoolean("isPrimary", default_app_id == webapp_info->app_id); |
| 2401 apps->Append(app); | 2409 apps->Append(app); |
| 2402 } | 2410 } |
| 2403 } | 2411 } |
| 2404 | 2412 |
| 2405 system_service->file_system()->GetCacheEntryByResourceId( | 2413 system_service->file_system()->GetCacheEntryByResourceId( |
| 2406 entry->resource_id(), | 2414 entry->resource_id(), |
| 2407 file_specific_info.file_md5(), | 2415 file_specific_info.file_md5(), |
| 2408 base::Bind(&GetDriveFilePropertiesFunction::CacheStateReceived, this)); | 2416 base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this)); |
| 2409 } | 2417 } |
| 2410 | 2418 |
| 2411 void GetDriveFilePropertiesFunction::CacheStateReceived( | 2419 void GetDriveEntryPropertiesFunction::CacheStateReceived( |
| 2412 bool /* success */, | 2420 bool /* success */, |
| 2413 const drive::CacheEntry& cache_entry) { | 2421 const drive::CacheEntry& cache_entry) { |
| 2414 // In case of an error (i.e. success is false), cache_entry.is_*() all | 2422 // In case of an error (i.e. success is false), cache_entry.is_*() all |
| 2415 // returns false. | 2423 // returns false. |
| 2416 properties_->SetBoolean("isPinned", cache_entry.is_pinned()); | 2424 properties_->SetBoolean("isPinned", cache_entry.is_pinned()); |
| 2417 properties_->SetBoolean("isPresent", cache_entry.is_present()); | 2425 properties_->SetBoolean("isPresent", cache_entry.is_present()); |
| 2418 properties_->SetBoolean("isDirty", cache_entry.is_dirty()); | 2426 properties_->SetBoolean("isDirty", cache_entry.is_dirty()); |
| 2419 | 2427 |
| 2420 CompleteGetFileProperties(drive::FILE_ERROR_OK); | 2428 CompleteGetFileProperties(drive::FILE_ERROR_OK); |
| 2421 } | 2429 } |
| 2422 | 2430 |
| 2423 void GetDriveFilePropertiesFunction::CompleteGetFileProperties( | 2431 void GetDriveEntryPropertiesFunction::CompleteGetFileProperties( |
| 2424 drive::FileError error) { | 2432 drive::FileError error) { |
| 2425 if (error != drive::FILE_ERROR_OK) | 2433 if (error != drive::FILE_ERROR_OK) |
| 2426 properties_->SetInteger("errorCode", error); | 2434 properties_->SetInteger("errorCode", error); |
| 2427 SetResult(properties_.release()); | 2435 SetResult(properties_.release()); |
| 2428 SendResponse(true); | 2436 SendResponse(true); |
| 2429 } | 2437 } |
| 2430 | 2438 |
| 2431 PinDriveFileFunction::PinDriveFileFunction() { | 2439 PinDriveFileFunction::PinDriveFileFunction() { |
| 2432 } | 2440 } |
| 2433 | 2441 |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3150 OpenNewWindowFunction::OpenNewWindowFunction() {} | 3158 OpenNewWindowFunction::OpenNewWindowFunction() {} |
| 3151 | 3159 |
| 3152 OpenNewWindowFunction::~OpenNewWindowFunction() {} | 3160 OpenNewWindowFunction::~OpenNewWindowFunction() {} |
| 3153 | 3161 |
| 3154 bool OpenNewWindowFunction::RunImpl() { | 3162 bool OpenNewWindowFunction::RunImpl() { |
| 3155 std::string url; | 3163 std::string url; |
| 3156 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 3164 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
| 3157 file_manager_util::OpenNewWindow(profile_, GURL(url)); | 3165 file_manager_util::OpenNewWindow(profile_, GURL(url)); |
| 3158 return true; | 3166 return true; |
| 3159 } | 3167 } |
| OLD | NEW |