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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return; | 164 return; |
165 } | 165 } |
166 | 166 |
167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
168 if (error != base::PLATFORM_FILE_OK) { | 168 if (error != base::PLATFORM_FILE_OK) { |
169 error_ = base::StringPrintf(kFileError, static_cast<int>(error)); | 169 error_ = base::StringPrintf(kFileError, static_cast<int>(error)); |
170 SendResponse(false); | 170 SendResponse(false); |
171 return; | 171 return; |
172 } | 172 } |
173 | 173 |
174 DictionaryValue* dict = new DictionaryValue(); | 174 base::DictionaryValue* dict = new base::DictionaryValue(); |
175 SetResult(dict); | 175 SetResult(dict); |
176 dict->SetString("name", file_system_name); | 176 dict->SetString("name", file_system_name); |
177 dict->SetString("root", root_url.spec()); | 177 dict->SetString("root", root_url.spec()); |
178 SendResponse(true); | 178 SendResponse(true); |
179 } | 179 } |
180 | 180 |
181 bool SyncFileSystemGetFileStatusFunction::RunImpl() { | 181 bool SyncFileSystemGetFileStatusFunction::RunImpl() { |
182 std::string url; | 182 std::string url; |
183 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 183 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
184 | 184 |
(...skipping 28 matching lines...) Expand all Loading... |
213 } | 213 } |
214 | 214 |
215 SyncFileSystemGetFileStatusesFunction::SyncFileSystemGetFileStatusesFunction() { | 215 SyncFileSystemGetFileStatusesFunction::SyncFileSystemGetFileStatusesFunction() { |
216 } | 216 } |
217 | 217 |
218 SyncFileSystemGetFileStatusesFunction::~SyncFileSystemGetFileStatusesFunction( | 218 SyncFileSystemGetFileStatusesFunction::~SyncFileSystemGetFileStatusesFunction( |
219 ) {} | 219 ) {} |
220 | 220 |
221 bool SyncFileSystemGetFileStatusesFunction::RunImpl() { | 221 bool SyncFileSystemGetFileStatusesFunction::RunImpl() { |
222 // All FileEntries converted into array of URL Strings in JS custom bindings. | 222 // All FileEntries converted into array of URL Strings in JS custom bindings. |
223 ListValue* file_entry_urls = NULL; | 223 base::ListValue* file_entry_urls = NULL; |
224 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &file_entry_urls)); | 224 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &file_entry_urls)); |
225 | 225 |
226 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 226 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
227 BrowserContext::GetStoragePartition( | 227 BrowserContext::GetStoragePartition( |
228 profile(), | 228 profile(), |
229 render_view_host()->GetSiteInstance())->GetFileSystemContext(); | 229 render_view_host()->GetSiteInstance())->GetFileSystemContext(); |
230 | 230 |
231 // Map each file path->SyncFileStatus in the callback map. | 231 // Map each file path->SyncFileStatus in the callback map. |
232 // TODO(calvinlo): Overload GetFileSyncStatus to take in URL array. | 232 // TODO(calvinlo): Overload GetFileSyncStatus to take in URL array. |
233 num_expected_results_ = file_entry_urls->GetSize(); | 233 num_expected_results_ = file_entry_urls->GetSize(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 if (num_results_received_ < num_expected_results_) | 267 if (num_results_received_ < num_expected_results_) |
268 return; | 268 return; |
269 | 269 |
270 // All results received. Dump array of statuses into extension enum values. | 270 // All results received. Dump array of statuses into extension enum values. |
271 // Note that the enum types need to be set as strings manually as the | 271 // Note that the enum types need to be set as strings manually as the |
272 // autogenerated Results::Create function thinks the enum values should be | 272 // autogenerated Results::Create function thinks the enum values should be |
273 // returned as int values. | 273 // returned as int values. |
274 base::ListValue* status_array = new base::ListValue(); | 274 base::ListValue* status_array = new base::ListValue(); |
275 for (URLToStatusMap::iterator it = file_sync_statuses_.begin(); | 275 for (URLToStatusMap::iterator it = file_sync_statuses_.begin(); |
276 it != file_sync_statuses_.end(); ++it) { | 276 it != file_sync_statuses_.end(); ++it) { |
277 DictionaryValue* dict = new DictionaryValue(); | 277 base::DictionaryValue* dict = new base::DictionaryValue(); |
278 status_array->Append(dict); | 278 status_array->Append(dict); |
279 | 279 |
280 fileapi::FileSystemURL url = it->first; | 280 fileapi::FileSystemURL url = it->first; |
281 SyncStatusCode file_error = it->second.first; | 281 SyncStatusCode file_error = it->second.first; |
282 api::sync_file_system::FileStatus file_status = | 282 api::sync_file_system::FileStatus file_status = |
283 SyncFileStatusToExtensionEnum(it->second.second); | 283 SyncFileStatusToExtensionEnum(it->second.second); |
284 | 284 |
285 dict->Set("entry", CreateDictionaryValueForFileSystemEntry( | 285 dict->Set("entry", CreateDictionaryValueForFileSystemEntry( |
286 url, sync_file_system::SYNC_FILE_TYPE_FILE)); | 286 url, sync_file_system::SYNC_FILE_TYPE_FILE)); |
287 dict->SetString("status", ToString(file_status)); | 287 dict->SetString("status", ToString(file_status)); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 DCHECK(service); | 379 DCHECK(service); |
380 api::sync_file_system::ConflictResolutionPolicy policy = | 380 api::sync_file_system::ConflictResolutionPolicy policy = |
381 ConflictResolutionPolicyToExtensionEnum( | 381 ConflictResolutionPolicyToExtensionEnum( |
382 service->GetConflictResolutionPolicy()); | 382 service->GetConflictResolutionPolicy()); |
383 SetResult(Value::CreateStringValue( | 383 SetResult(Value::CreateStringValue( |
384 api::sync_file_system::ToString(policy))); | 384 api::sync_file_system::ToString(policy))); |
385 return true; | 385 return true; |
386 } | 386 } |
387 | 387 |
388 } // namespace extensions | 388 } // namespace extensions |
OLD | NEW |