| 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 <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 namespace extensions { | 39 namespace extensions { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // Error messages. | 43 // Error messages. |
| 44 const char kErrorMessage[] = "%s (error code: %d)."; | 44 const char kErrorMessage[] = "%s (error code: %d)."; |
| 45 const char kUnsupportedConflictResolutionPolicy[] = | 45 const char kUnsupportedConflictResolutionPolicy[] = |
| 46 "Policy %s is not supported."; | 46 "Policy %s is not supported."; |
| 47 | 47 |
| 48 sync_file_system::SyncFileSystemService* GetSyncFileSystemService( | 48 sync_file_system::SyncFileSystemService* GetSyncFileSystemService( |
| 49 Profile* profile) { | 49 content::BrowserContext* browser_context) { |
| 50 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 50 sync_file_system::SyncFileSystemService* service = | 51 sync_file_system::SyncFileSystemService* service = |
| 51 SyncFileSystemServiceFactory::GetForProfile(profile); | 52 SyncFileSystemServiceFactory::GetForProfile(profile); |
| 52 if (!service) | 53 if (!service) |
| 53 return nullptr; | 54 return nullptr; |
| 54 ExtensionSyncEventObserver* observer = | 55 ExtensionSyncEventObserver* observer = |
| 55 ExtensionSyncEventObserver::GetFactoryInstance()->Get(profile); | 56 ExtensionSyncEventObserver::GetFactoryInstance()->Get(profile); |
| 56 if (!observer) | 57 if (!observer) |
| 57 return nullptr; | 58 return nullptr; |
| 58 observer->InitializeForService(service); | 59 observer->InitializeForService(service); |
| 59 return service; | 60 return service; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 return; | 349 return; |
| 349 } | 350 } |
| 350 | 351 |
| 351 api::sync_file_system::StorageInfo info; | 352 api::sync_file_system::StorageInfo info; |
| 352 info.usage_bytes = usage; | 353 info.usage_bytes = usage; |
| 353 info.quota_bytes = quota; | 354 info.quota_bytes = quota; |
| 354 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info); | 355 results_ = api::sync_file_system::GetUsageAndQuota::Results::Create(info); |
| 355 SendResponse(true); | 356 SendResponse(true); |
| 356 } | 357 } |
| 357 | 358 |
| 358 bool SyncFileSystemSetConflictResolutionPolicyFunction::RunSync() { | 359 ExtensionFunction::ResponseAction |
| 360 SyncFileSystemSetConflictResolutionPolicyFunction::Run() { |
| 359 std::string policy_string; | 361 std::string policy_string; |
| 360 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &policy_string)); | 362 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &policy_string)); |
| 361 ConflictResolutionPolicy policy = ExtensionEnumToConflictResolutionPolicy( | 363 ConflictResolutionPolicy policy = ExtensionEnumToConflictResolutionPolicy( |
| 362 api::sync_file_system::ParseConflictResolutionPolicy(policy_string)); | 364 api::sync_file_system::ParseConflictResolutionPolicy(policy_string)); |
| 363 if (policy != sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN) { | 365 if (policy != sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN) { |
| 364 SetError(base::StringPrintf(kUnsupportedConflictResolutionPolicy, | 366 return RespondNow(Error(base::StringPrintf( |
| 365 policy_string.c_str())); | 367 kUnsupportedConflictResolutionPolicy, policy_string.c_str()))); |
| 366 return false; | |
| 367 } | 368 } |
| 368 return true; | 369 return RespondNow(NoArguments()); |
| 369 } | 370 } |
| 370 | 371 |
| 371 bool SyncFileSystemGetConflictResolutionPolicyFunction::RunSync() { | 372 ExtensionFunction::ResponseAction |
| 372 SetResult(base::MakeUnique<base::StringValue>(api::sync_file_system::ToString( | 373 SyncFileSystemGetConflictResolutionPolicyFunction::Run() { |
| 373 api::sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN))); | 374 return RespondNow(OneArgument( |
| 374 return true; | 375 base::MakeUnique<base::StringValue>(api::sync_file_system::ToString( |
| 376 api::sync_file_system::CONFLICT_RESOLUTION_POLICY_LAST_WRITE_WIN)))); |
| 375 } | 377 } |
| 376 | 378 |
| 377 bool SyncFileSystemGetServiceStatusFunction::RunSync() { | 379 ExtensionFunction::ResponseAction |
| 380 SyncFileSystemGetServiceStatusFunction::Run() { |
| 378 sync_file_system::SyncFileSystemService* service = | 381 sync_file_system::SyncFileSystemService* service = |
| 379 GetSyncFileSystemService(GetProfile()); | 382 GetSyncFileSystemService(browser_context()); |
| 380 if (!service) | 383 if (!service) |
| 381 return false; | 384 return RespondNow(Error(kUnknownErrorDoNotUse)); |
| 382 results_ = api::sync_file_system::GetServiceStatus::Results::Create( | 385 return RespondNow( |
| 383 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())); | 386 ArgumentList(api::sync_file_system::GetServiceStatus::Results::Create( |
| 384 return true; | 387 SyncServiceStateToExtensionEnum(service->GetSyncServiceState())))); |
| 385 } | 388 } |
| 386 | 389 |
| 387 } // namespace extensions | 390 } // namespace extensions |
| OLD | NEW |