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/extensions/api/sync_file_system/sync_file_system_api.h" | 5 #include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sync_file_system/sync_file_system_service.h" | 13 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
| 17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 18 #include "webkit/fileapi/file_system_context.h" | 18 #include "webkit/fileapi/file_system_context.h" |
| 19 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
| 20 #include "webkit/quota/quota_manager.h" | |
| 20 | 21 |
| 21 using content::BrowserContext; | 22 using content::BrowserContext; |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 using sync_file_system::SyncFileSystemServiceFactory; | 24 using sync_file_system::SyncFileSystemServiceFactory; |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // This is the only supported cloud backend service for now. | 30 // This is the only supported cloud backend service for now. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 return; | 97 return; |
| 97 } | 98 } |
| 98 | 99 |
| 99 DictionaryValue* dict = new DictionaryValue(); | 100 DictionaryValue* dict = new DictionaryValue(); |
| 100 SetResult(dict); | 101 SetResult(dict); |
| 101 dict->SetString("name", file_system_name); | 102 dict->SetString("name", file_system_name); |
| 102 dict->SetString("root", root_url.spec()); | 103 dict->SetString("root", root_url.spec()); |
| 103 SendResponse(true); | 104 SendResponse(true); |
| 104 } | 105 } |
| 105 | 106 |
| 107 bool SyncFileSystemGetUsageAndQuotaFunction::RunImpl() { | |
| 108 std::string service_name; | |
| 109 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &service_name)); | |
| 110 | |
| 111 // 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.
| |
| 112 if (service_name != std::string(kDriveCloudService)) { | |
| 113 error_ = base::StringPrintf(kNotSupportedService, service_name.c_str()); | |
| 114 return false; | |
| 115 } | |
| 116 | |
| 117 scoped_refptr<quota::QuotaManager> quota_manager = | |
| 118 BrowserContext::GetStoragePartition( | |
| 119 profile(), | |
| 120 render_view_host()->GetSiteInstance())->GetQuotaManager(); | |
| 121 | |
| 122 BrowserThread::PostTask( | |
| 123 BrowserThread::IO, | |
| 124 FROM_HERE, | |
| 125 Bind("a::QuotaManager::GetUsageAndQuota, | |
| 126 quota_manager, | |
| 127 source_url(), | |
| 128 quota::kStorageTypeSyncable, | |
| 129 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, | |
| 130 this))); | |
| 131 | |
| 132 return true; | |
| 133 } | |
| 134 | |
| 135 void SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota( | |
| 136 quota::QuotaStatusCode status, int64 usage, int64 quota) { | |
| 137 // 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
| |
| 138 if (!BrowserThread::CurrentlyOn(kControlThread)) { | |
| 139 BrowserThread::PostTask( | |
| 140 kControlThread, | |
| 141 FROM_HERE, | |
| 142 Bind(&SyncFileSystemGetUsageAndQuotaFunction::DidGetUsageAndQuota, this, | |
| 143 status, usage, quota)); | |
| 144 return; | |
| 145 } | |
| 146 | |
| 147 DCHECK(BrowserThread::CurrentlyOn(kControlThread)); | |
| 148 if (status != quota::kQuotaStatusOk) { | |
| 149 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."
| |
| 150 SendResponse(false); | |
| 151 return; | |
| 152 } | |
| 153 | |
| 154 DictionaryValue* dict = new DictionaryValue(); | |
| 155 SetResult(dict); | |
| 156 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.
| |
| 157 dict->SetInteger("quota", quota); | |
| 158 SendResponse(true); | |
| 159 } | |
| 160 | |
| 106 } // namespace extensions | 161 } // namespace extensions |
| OLD | NEW |