Chromium Code Reviews| Index: chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc |
| diff --git a/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc b/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc |
| index 45c8eb03c845f64a20097f8cd82ba4d7d9541f34..36f939a36ba889cac4e47512f56d5e68daaeb923 100644 |
| --- a/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc |
| +++ b/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc |
| @@ -11,12 +11,14 @@ |
| #include "base/stringprintf.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
| +#include "chrome/common/extensions/api/sync_file_system.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/storage_partition.h" |
| #include "content/public/common/content_client.h" |
| #include "webkit/fileapi/file_system_context.h" |
| #include "webkit/fileapi/file_system_types.h" |
| +#include "webkit/quota/quota_manager.h" |
| using content::BrowserContext; |
| using content::BrowserThread; |
| @@ -32,8 +34,7 @@ const char kDriveCloudService[] = "drive"; |
| // Error messages. |
| const char kNotSupportedService[] = "Cloud service %s not supported."; |
| const char kFileError[] = "File error %d."; |
| - |
| -const BrowserThread::ID kControlThread = BrowserThread::UI; |
| +const char kQuotaError[] = "Quota error %d."; |
| } // namespace |
| @@ -89,7 +90,7 @@ void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( |
| base::PlatformFileError error, |
| const std::string& file_system_name, |
| const GURL& root_url) { |
| - DCHECK(BrowserThread::CurrentlyOn(kControlThread)); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (error != base::PLATFORM_FILE_OK) { |
| error_ = base::StringPrintf(kFileError, static_cast<int>(error)); |
| SendResponse(false); |
| @@ -103,4 +104,59 @@ void SyncFileSystemRequestFileSystemFunction::DidOpenFileSystem( |
| SendResponse(true); |
| } |
| +bool SyncFileSystemGetUsageAndQuotaFunction::RunImpl() { |
| + std::string service_name; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &service_name)); |
| + |
| + // TODO(calvinlo): For now only gDrive cloud service is supported. |
| + if (service_name != std::string(kDriveCloudService)) { |
| + error_ = base::StringPrintf(kNotSupportedService, service_name.c_str()); |
| + return false; |
| + } |
| + |
| + scoped_refptr<quota::QuotaManager> quota_manager = |
| + BrowserContext::GetStoragePartition( |
| + profile(), |
| + render_view_host()->GetSiteInstance())->GetQuotaManager(); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + Bind("a::QuotaManager::GetUsageAndQuota, |
| + quota_manager, |
| + source_url(), |
| + quota::kStorageTypeSyncable, |
| + Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, |
| + this))); |
| + |
| + return true; |
| +} |
| + |
| +void SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota( |
| + quota::QuotaStatusCode status, int64 usage, int64 quota) { |
| + // Repost to switch from IO thread to UI thread for SendResponse(). |
| + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| + BrowserThread::PostTask( |
|
Mihai Parparita -not on Chrome
2012/10/19 22:20:55
Add a DCHECK(BrowserThread::CurrentlyOn(BrowserThr
calvinlo
2012/10/22 03:53:30
Done.
|
| + BrowserThread::UI, |
| + FROM_HERE, |
| + Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, this, |
| + status, usage, quota)); |
| + return; |
| + } |
| + |
|
Mihai Parparita -not on Chrome
2012/10/19 22:20:55
And a DCHECK(BrowserThread::CurrentlyOn(BrowserThr
calvinlo
2012/10/22 03:53:30
Done.
|
| + // TODO(calvinlo): Convert QuotaStatusCode to error string |
| + // (http://crbug.com/156791). |
| + if (status != quota::kQuotaStatusOk) { |
| + error_ = base::StringPrintf(kQuotaError, static_cast<int>(status)); |
| + SendResponse(false); |
| + return; |
| + } |
| + |
| + api::sync_file_system::StorageInfo info; |
| + info.usage_bytes = usage; |
| + info.quota_bytes = quota; |
| + results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info); |
| + SendResponse(true); |
| +} |
| + |
| } // namespace extensions |