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

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: Removed TODO Created 7 years, 11 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) {
76 DCHECK(error);
77 if (service_name != std::string(kDriveCloudService)) {
78 *error = base::StringPrintf(kNotSupportedService, service_name.c_str());
79 return false;
80 }
81 return true;
82 }
83
75 } // namespace 84 } // namespace
76 85
77 bool SyncFileSystemDeleteFileSystemFunction::RunImpl() { 86 bool SyncFileSystemDeleteFileSystemFunction::RunImpl() {
78 // TODO(calvinlo): Move error code to util function. (http://crbug.com/160496)
79 std::string url; 87 std::string url;
80 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); 88 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
81 fileapi::FileSystemURL file_system_url((GURL(url))); 89 fileapi::FileSystemURL file_system_url((GURL(url)));
90 if (!IsValidServiceName(file_system_url.filesystem_id(), &error_)) {
91 return false;
92 }
82 93
83 scoped_refptr<fileapi::FileSystemContext> file_system_context = 94 scoped_refptr<fileapi::FileSystemContext> file_system_context =
84 BrowserContext::GetStoragePartition( 95 BrowserContext::GetStoragePartition(
85 profile(), 96 profile(),
86 render_view_host()->GetSiteInstance())->GetFileSystemContext(); 97 render_view_host()->GetSiteInstance())->GetFileSystemContext();
87 BrowserThread::PostTask( 98 BrowserThread::PostTask(
88 BrowserThread::IO, 99 BrowserThread::IO,
89 FROM_HERE, 100 FROM_HERE,
90 Bind(&fileapi::FileSystemContext::DeleteFileSystem, 101 Bind(&fileapi::FileSystemContext::DeleteFileSystem,
91 file_system_context, 102 file_system_context,
(...skipping 25 matching lines...) Expand all
117 return; 128 return;
118 } 129 }
119 130
120 SetResult(base::Value::CreateBooleanValue(true)); 131 SetResult(base::Value::CreateBooleanValue(true));
121 SendResponse(true); 132 SendResponse(true);
122 } 133 }
123 134
124 bool SyncFileSystemRequestFileSystemFunction::RunImpl() { 135 bool SyncFileSystemRequestFileSystemFunction::RunImpl() {
125 std::string service_name; 136 std::string service_name;
126 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &service_name)); 137 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &service_name));
127 138 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; 139 return false;
132 } 140 }
133 141
134 // Initializes sync context for this extension and continue to open 142 // Initializes sync context for this extension and continue to open
135 // a new file system. 143 // a new file system.
136 GetSyncFileSystemService(profile())-> 144 GetSyncFileSystemService(profile())->
137 InitializeForApp( 145 InitializeForApp(
138 GetFileSystemContext(), 146 GetFileSystemContext(),
139 service_name, 147 service_name,
140 source_url().GetOrigin(), 148 source_url().GetOrigin(),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 SetResult(dict); 203 SetResult(dict);
196 dict->SetString("name", file_system_name); 204 dict->SetString("name", file_system_name);
197 dict->SetString("root", root_url.spec()); 205 dict->SetString("root", root_url.spec());
198 SendResponse(true); 206 SendResponse(true);
199 } 207 }
200 208
201 bool SyncFileSystemGetUsageAndQuotaFunction::RunImpl() { 209 bool SyncFileSystemGetUsageAndQuotaFunction::RunImpl() {
202 std::string url; 210 std::string url;
203 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); 211 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
204 fileapi::FileSystemURL file_system_url((GURL(url))); 212 fileapi::FileSystemURL file_system_url((GURL(url)));
205 213 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; 214 return false;
212 } 215 }
213 216
214 scoped_refptr<quota::QuotaManager> quota_manager = 217 scoped_refptr<quota::QuotaManager> quota_manager =
215 BrowserContext::GetStoragePartition( 218 BrowserContext::GetStoragePartition(
216 profile(), 219 profile(),
217 render_view_host()->GetSiteInstance())->GetQuotaManager(); 220 render_view_host()->GetSiteInstance())->GetQuotaManager();
218 221
219 BrowserThread::PostTask( 222 BrowserThread::PostTask(
220 BrowserThread::IO, 223 BrowserThread::IO,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 292 }
290 293
291 api::sync_file_system::StorageInfo info; 294 api::sync_file_system::StorageInfo info;
292 info.usage_bytes = usage; 295 info.usage_bytes = usage;
293 info.quota_bytes = quota; 296 info.quota_bytes = quota;
294 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info); 297 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info);
295 SendResponse(true); 298 SendResponse(true);
296 } 299 }
297 300
298 } // namespace extensions 301 } // 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