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

Side by Side Diff: chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc

Issue 11659005: Added common function to check for supported syncable file system service names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tzik review #2 Created 7 years, 12 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 sync_file_system::SyncFileSystemService* service = 65 sync_file_system::SyncFileSystemService* service =
66 SyncFileSystemServiceFactory::GetForProfile(profile); 66 SyncFileSystemServiceFactory::GetForProfile(profile);
67 DCHECK(service); 67 DCHECK(service);
68 ExtensionSyncEventObserver* observer = 68 ExtensionSyncEventObserver* observer =
69 ExtensionSyncEventObserverFactory::GetForProfile(profile); 69 ExtensionSyncEventObserverFactory::GetForProfile(profile);
70 DCHECK(observer); 70 DCHECK(observer);
71 observer->InitializeForService(service, kDriveCloudService); 71 observer->InitializeForService(service, kDriveCloudService);
72 return service; 72 return service;
73 } 73 }
74 74
75 bool isValidServiceName(const std::string& service_name, std::string* error) {
kinuko 2013/01/04 10:45:53 naming: please capitalize function names in c++/ch
calvinlo 2013/01/08 03:34:46 Done.
76 DCHECK(error);
77 // TODO(calvinlo): For now only Google Drive cloud service is supported.
78 if (service_name != std::string(kDriveCloudService)) {
79 *error = base::StringPrintf(kNotSupportedService, service_name.c_str());
80 return false;
81 }
82 return true;
83 }
84
75 } // namespace 85 } // namespace
76 86
77 bool SyncFileSystemDeleteFileSystemFunction::RunImpl() { 87 bool SyncFileSystemDeleteFileSystemFunction::RunImpl() {
78 // TODO(calvinlo): Move error code to util function. (http://crbug.com/160496)
79 std::string url; 88 std::string url;
80 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); 89 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
81 fileapi::FileSystemURL file_system_url((GURL(url))); 90 fileapi::FileSystemURL file_system_url((GURL(url)));
91 if (!isValidServiceName(file_system_url.filesystem_id(), &error_)) {
92 return false;
93 }
82 94
83 scoped_refptr<fileapi::FileSystemContext> file_system_context = 95 scoped_refptr<fileapi::FileSystemContext> file_system_context =
84 BrowserContext::GetStoragePartition( 96 BrowserContext::GetStoragePartition(
85 profile(), 97 profile(),
86 render_view_host()->GetSiteInstance())->GetFileSystemContext(); 98 render_view_host()->GetSiteInstance())->GetFileSystemContext();
87 BrowserThread::PostTask( 99 BrowserThread::PostTask(
88 BrowserThread::IO, 100 BrowserThread::IO,
89 FROM_HERE, 101 FROM_HERE,
90 Bind(&fileapi::FileSystemContext::DeleteFileSystem, 102 Bind(&fileapi::FileSystemContext::DeleteFileSystem,
91 file_system_context, 103 file_system_context,
(...skipping 25 matching lines...) Expand all
117 return; 129 return;
118 } 130 }
119 131
120 SetResult(base::Value::CreateBooleanValue(true)); 132 SetResult(base::Value::CreateBooleanValue(true));
121 SendResponse(true); 133 SendResponse(true);
122 } 134 }
123 135
124 bool SyncFileSystemRequestFileSystemFunction::RunImpl() { 136 bool SyncFileSystemRequestFileSystemFunction::RunImpl() {
125 std::string service_name; 137 std::string service_name;
126 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &service_name)); 138 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &service_name));
127 139 if (!isValidServiceName(service_name, &error_)) {
128 // TODO(calvinlo): Move error code to util function. (http://crbug.com/160496)
129 if (service_name != std::string(kDriveCloudService)) {
130 error_ = base::StringPrintf(kNotSupportedService, service_name.c_str());
131 return false; 140 return false;
132 } 141 }
133 142
134 // Initializes sync context for this extension and continue to open 143 // Initializes sync context for this extension and continue to open
135 // a new file system. 144 // a new file system.
136 GetSyncFileSystemService(profile())-> 145 GetSyncFileSystemService(profile())->
137 InitializeForApp( 146 InitializeForApp(
138 GetFileSystemContext(), 147 GetFileSystemContext(),
139 service_name, 148 service_name,
140 source_url().GetOrigin(), 149 source_url().GetOrigin(),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 SetResult(dict); 204 SetResult(dict);
196 dict->SetString("name", file_system_name); 205 dict->SetString("name", file_system_name);
197 dict->SetString("root", root_url.spec()); 206 dict->SetString("root", root_url.spec());
198 SendResponse(true); 207 SendResponse(true);
199 } 208 }
200 209
201 bool SyncFileSystemGetUsageAndQuotaFunction::RunImpl() { 210 bool SyncFileSystemGetUsageAndQuotaFunction::RunImpl() {
202 std::string url; 211 std::string url;
203 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); 212 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
204 fileapi::FileSystemURL file_system_url((GURL(url))); 213 fileapi::FileSystemURL file_system_url((GURL(url)));
205 214 if (!isValidServiceName(file_system_url.filesystem_id(), &error_)) {
206 // TODO(calvinlo): For now only gDrive cloud service is supported.
207 // TODO(calvinlo): Move error code to util function. (http://crbug.com/160496)
208 const std::string service_name = file_system_url.filesystem_id();
209 if (service_name != std::string(kDriveCloudService)) {
210 error_ = base::StringPrintf(kNotSupportedService, service_name.c_str());
211 return false; 215 return false;
212 } 216 }
213 217
214 scoped_refptr<quota::QuotaManager> quota_manager = 218 scoped_refptr<quota::QuotaManager> quota_manager =
215 BrowserContext::GetStoragePartition( 219 BrowserContext::GetStoragePartition(
216 profile(), 220 profile(),
217 render_view_host()->GetSiteInstance())->GetQuotaManager(); 221 render_view_host()->GetSiteInstance())->GetQuotaManager();
218 222
219 BrowserThread::PostTask( 223 BrowserThread::PostTask(
220 BrowserThread::IO, 224 BrowserThread::IO,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 293 }
290 294
291 api::sync_file_system::StorageInfo info; 295 api::sync_file_system::StorageInfo info;
292 info.usage_bytes = usage; 296 info.usage_bytes = usage;
293 info.quota_bytes = quota; 297 info.quota_bytes = quota;
294 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info); 298 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info);
295 SendResponse(true); 299 SendResponse(true);
296 } 300 }
297 301
298 } // namespace extensions 302 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698