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 <memory> |
7 #include <string> | 8 #include <string> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" |
12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
13 #include "chrome/browser/extensions/api/sync_file_system/extension_sync_event_ob
server.h" | 15 #include "chrome/browser/extensions/api/sync_file_system/extension_sync_event_ob
server.h" |
14 #include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api_he
lpers.h" | 16 #include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api_he
lpers.h" |
15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync_file_system/sync_file_status.h" | 18 #include "chrome/browser/sync_file_system/sync_file_status.h" |
17 #include "chrome/browser/sync_file_system/sync_file_system_service.h" | 19 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
18 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" | 20 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" |
19 #include "chrome/common/extensions/api/sync_file_system.h" | 21 #include "chrome/common/extensions/api/sync_file_system.h" |
20 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 BrowserThread::UI, | 100 BrowserThread::UI, |
99 FROM_HERE, | 101 FROM_HERE, |
100 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, this, | 102 Bind(&SyncFileSystemDeleteFileSystemFunction::DidDeleteFileSystem, this, |
101 error)); | 103 error)); |
102 return; | 104 return; |
103 } | 105 } |
104 | 106 |
105 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 107 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
106 if (error != base::File::FILE_OK) { | 108 if (error != base::File::FILE_OK) { |
107 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); | 109 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); |
108 SetResult(new base::FundamentalValue(false)); | 110 SetResult(base::MakeUnique<base::FundamentalValue>(false)); |
109 SendResponse(false); | 111 SendResponse(false); |
110 return; | 112 return; |
111 } | 113 } |
112 | 114 |
113 SetResult(new base::FundamentalValue(true)); | 115 SetResult(base::MakeUnique<base::FundamentalValue>(true)); |
114 SendResponse(true); | 116 SendResponse(true); |
115 } | 117 } |
116 | 118 |
117 bool SyncFileSystemRequestFileSystemFunction::RunAsync() { | 119 bool SyncFileSystemRequestFileSystemFunction::RunAsync() { |
118 // SyncFileSystem initialization is done in OpenFileSystem below, but we call | 120 // SyncFileSystem initialization is done in OpenFileSystem below, but we call |
119 // GetSyncFileSystemService here too to initialize sync event observer for | 121 // GetSyncFileSystemService here too to initialize sync event observer for |
120 // extensions API. | 122 // extensions API. |
121 if (!GetSyncFileSystemService(GetProfile())) | 123 if (!GetSyncFileSystemService(GetProfile())) |
122 return false; | 124 return false; |
123 | 125 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return; | 158 return; |
157 } | 159 } |
158 | 160 |
159 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 161 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
160 if (error != base::File::FILE_OK) { | 162 if (error != base::File::FILE_OK) { |
161 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); | 163 error_ = ErrorToString(sync_file_system::FileErrorToSyncStatusCode(error)); |
162 SendResponse(false); | 164 SendResponse(false); |
163 return; | 165 return; |
164 } | 166 } |
165 | 167 |
166 base::DictionaryValue* dict = new base::DictionaryValue(); | 168 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
167 SetResult(dict); | |
168 dict->SetString("name", file_system_name); | 169 dict->SetString("name", file_system_name); |
169 dict->SetString("root", root_url.spec()); | 170 dict->SetString("root", root_url.spec()); |
| 171 SetResult(std::move(dict)); |
170 SendResponse(true); | 172 SendResponse(true); |
171 } | 173 } |
172 | 174 |
173 bool SyncFileSystemGetFileStatusFunction::RunAsync() { | 175 bool SyncFileSystemGetFileStatusFunction::RunAsync() { |
174 std::string url; | 176 std::string url; |
175 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 177 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
176 | 178 |
177 scoped_refptr<storage::FileSystemContext> file_system_context = | 179 scoped_refptr<storage::FileSystemContext> file_system_context = |
178 BrowserContext::GetStoragePartition( | 180 BrowserContext::GetStoragePartition( |
179 GetProfile(), render_frame_host()->GetSiteInstance()) | 181 GetProfile(), render_frame_host()->GetSiteInstance()) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // Keep mapping file statuses until all of them have been received. | 265 // Keep mapping file statuses until all of them have been received. |
264 // TODO(calvinlo): Get rid of this check when batch version of | 266 // TODO(calvinlo): Get rid of this check when batch version of |
265 // GetFileSyncStatus(GURL urls[]); is added. | 267 // GetFileSyncStatus(GURL urls[]); is added. |
266 if (num_results_received_ < num_expected_results_) | 268 if (num_results_received_ < num_expected_results_) |
267 return; | 269 return; |
268 | 270 |
269 // All results received. Dump array of statuses into extension enum values. | 271 // All results received. Dump array of statuses into extension enum values. |
270 // Note that the enum types need to be set as strings manually as the | 272 // Note that the enum types need to be set as strings manually as the |
271 // autogenerated Results::Create function thinks the enum values should be | 273 // autogenerated Results::Create function thinks the enum values should be |
272 // returned as int values. | 274 // returned as int values. |
273 base::ListValue* status_array = new base::ListValue(); | 275 std::unique_ptr<base::ListValue> status_array(new base::ListValue()); |
274 for (URLToStatusMap::iterator it = file_sync_statuses_.begin(); | 276 for (URLToStatusMap::iterator it = file_sync_statuses_.begin(); |
275 it != file_sync_statuses_.end(); ++it) { | 277 it != file_sync_statuses_.end(); ++it) { |
276 base::DictionaryValue* dict = new base::DictionaryValue(); | 278 base::DictionaryValue* dict = new base::DictionaryValue(); |
277 status_array->Append(dict); | 279 status_array->Append(dict); |
278 | 280 |
279 storage::FileSystemURL url = it->first; | 281 storage::FileSystemURL url = it->first; |
280 SyncStatusCode file_error = it->second.first; | 282 SyncStatusCode file_error = it->second.first; |
281 api::sync_file_system::FileStatus file_status = | 283 api::sync_file_system::FileStatus file_status = |
282 SyncFileStatusToExtensionEnum(it->second.second); | 284 SyncFileStatusToExtensionEnum(it->second.second); |
283 | 285 |
284 dict->Set("entry", CreateDictionaryValueForFileSystemEntry( | 286 dict->Set("entry", CreateDictionaryValueForFileSystemEntry( |
285 url, sync_file_system::SYNC_FILE_TYPE_FILE)); | 287 url, sync_file_system::SYNC_FILE_TYPE_FILE)); |
286 dict->SetString("status", ToString(file_status)); | 288 dict->SetString("status", ToString(file_status)); |
287 | 289 |
288 if (file_error == sync_file_system::SYNC_STATUS_OK) | 290 if (file_error == sync_file_system::SYNC_STATUS_OK) |
289 continue; | 291 continue; |
290 dict->SetString("error", ErrorToString(file_error)); | 292 dict->SetString("error", ErrorToString(file_error)); |
291 } | 293 } |
292 SetResult(status_array); | 294 SetResult(std::move(status_array)); |
293 | 295 |
294 SendResponse(true); | 296 SendResponse(true); |
295 } | 297 } |
296 | 298 |
297 bool SyncFileSystemGetUsageAndQuotaFunction::RunAsync() { | 299 bool SyncFileSystemGetUsageAndQuotaFunction::RunAsync() { |
298 std::string url; | 300 std::string url; |
299 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 301 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
300 | 302 |
301 scoped_refptr<storage::FileSystemContext> file_system_context = | 303 scoped_refptr<storage::FileSystemContext> file_system_context = |
302 BrowserContext::GetStoragePartition( | 304 BrowserContext::GetStoragePartition( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 api::sync_file_system::ParseConflictResolutionPolicy(policy_string)); | 361 api::sync_file_system::ParseConflictResolutionPolicy(policy_string)); |
360 if (policy != sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN) { | 362 if (policy != sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN) { |
361 SetError(base::StringPrintf(kUnsupportedConflictResolutionPolicy, | 363 SetError(base::StringPrintf(kUnsupportedConflictResolutionPolicy, |
362 policy_string.c_str())); | 364 policy_string.c_str())); |
363 return false; | 365 return false; |
364 } | 366 } |
365 return true; | 367 return true; |
366 } | 368 } |
367 | 369 |
368 bool SyncFileSystemGetConflictResolutionPolicyFunction::RunSync() { | 370 bool SyncFileSystemGetConflictResolutionPolicyFunction::RunSync() { |
369 SetResult(new base::StringValue( | 371 SetResult(base::MakeUnique<base::StringValue>(api::sync_file_system::ToString( |
370 api::sync_file_system::ToString( | 372 api::sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN))); |
371 api::sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN))); | |
372 return true; | 373 return true; |
373 } | 374 } |
374 | 375 |
375 bool SyncFileSystemGetServiceStatusFunction::RunSync() { | 376 bool SyncFileSystemGetServiceStatusFunction::RunSync() { |
376 sync_file_system::SyncFileSystemService* service = | 377 sync_file_system::SyncFileSystemService* service = |
377 GetSyncFileSystemService(GetProfile()); | 378 GetSyncFileSystemService(GetProfile()); |
378 if (!service) | 379 if (!service) |
379 return false; | 380 return false; |
380 results_ = api::sync_file_system::GetServiceStatus::Results::Create( | 381 results_ = api::sync_file_system::GetServiceStatus::Results::Create( |
381 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())); | 382 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())); |
382 return true; | 383 return true; |
383 } | 384 } |
384 | 385 |
385 } // namespace extensions | 386 } // namespace extensions |
OLD | NEW |