Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc

Issue 11146034: Add GetUsageAndQuota() to Syncable API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mihai Review #2 Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..18d51986b424986d398a211bae2e9ab451270586 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,61 @@ 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(&quota::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)) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, this,
+ status, usage, quota));
+ return;
+ }
+
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // 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

Powered by Google App Engine
This is Rietveld 408576698