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..8b8fd7082f06501be9b44eb4425daeaa1afbef75 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 |
| @@ -17,6 +17,7 @@ |
| #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; |
| @@ -103,4 +104,58 @@ 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 |
|
kinuko
2012/10/18 13:00:59
nit: please end the comment with '.'.
calvinlo
2012/10/19 06:59:43
Done.
|
| + 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) { |
| + // SendResponse must run on UI thread. Repost if coming from another thread. |
|
Mihai Parparita -not on Chrome
2012/10/18 20:10:56
When does this happen? Seems like you'd want to al
kinuko
2012/10/19 04:10:49
I think probably the comment is a bit misleading.
calvinlo
2012/10/19 06:59:43
Updated comment, please double check. Also removed
|
| + if (!BrowserThread::CurrentlyOn(kControlThread)) { |
| + BrowserThread::PostTask( |
| + kControlThread, |
| + FROM_HERE, |
| + Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, this, |
| + status, usage, quota)); |
| + return; |
| + } |
| + |
| + DCHECK(BrowserThread::CurrentlyOn(kControlThread)); |
| + if (status != quota::kQuotaStatusOk) { |
| + error_ = base::StringPrintf(kFileError, static_cast<int>(status)); |
|
kinuko
2012/10/18 13:00:59
Since the error code we get here is not a file err
calvinlo
2012/10/19 06:59:43
Added const char kQuotaError[] = "Quota error %d."
|
| + SendResponse(false); |
| + return; |
| + } |
| + |
| + DictionaryValue* dict = new DictionaryValue(); |
| + SetResult(dict); |
| + dict->SetInteger("usage", usage); |
|
Mihai Parparita -not on Chrome
2012/10/18 20:12:38
Instead of repeating the field names as strings, y
kinuko
2012/10/19 04:10:49
Nice! I expected we should have something like tha
calvinlo
2012/10/19 06:59:43
I think I got this right now.
|
| + dict->SetInteger("quota", quota); |
| + SendResponse(true); |
| +} |
| + |
| } // namespace extensions |