OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_he
lpers.h" | 5 #include "chrome/browser/extensions/api/sync_file_system/sync_file_system_api_he
lpers.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/values.h" |
8 #include "storage/browser/fileapi/file_system_url.h" | 10 #include "storage/browser/fileapi/file_system_url.h" |
9 #include "storage/common/fileapi/file_system_util.h" | 11 #include "storage/common/fileapi/file_system_util.h" |
10 | 12 |
11 namespace extensions { | 13 namespace extensions { |
12 | 14 |
13 api::sync_file_system::ServiceStatus SyncServiceStateToExtensionEnum( | 15 api::sync_file_system::ServiceStatus SyncServiceStateToExtensionEnum( |
14 sync_file_system::SyncServiceState state) { | 16 sync_file_system::SyncServiceState state) { |
15 switch (state) { | 17 switch (state) { |
16 case sync_file_system::SYNC_SERVICE_RUNNING: | 18 case sync_file_system::SYNC_SERVICE_RUNNING: |
17 return api::sync_file_system::SERVICE_STATUS_RUNNING; | 19 return api::sync_file_system::SERVICE_STATUS_RUNNING; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 case sync_file_system::CONFLICT_RESOLUTION_POLICY_MANUAL: | 100 case sync_file_system::CONFLICT_RESOLUTION_POLICY_MANUAL: |
99 return api::sync_file_system::CONFLICT_RESOLUTION_POLICY_MANUAL; | 101 return api::sync_file_system::CONFLICT_RESOLUTION_POLICY_MANUAL; |
100 case sync_file_system::CONFLICT_RESOLUTION_POLICY_MAX: | 102 case sync_file_system::CONFLICT_RESOLUTION_POLICY_MAX: |
101 NOTREACHED(); | 103 NOTREACHED(); |
102 return api::sync_file_system::CONFLICT_RESOLUTION_POLICY_NONE; | 104 return api::sync_file_system::CONFLICT_RESOLUTION_POLICY_NONE; |
103 } | 105 } |
104 NOTREACHED() << "Invalid conflict resolution policy: " << policy; | 106 NOTREACHED() << "Invalid conflict resolution policy: " << policy; |
105 return api::sync_file_system::CONFLICT_RESOLUTION_POLICY_NONE; | 107 return api::sync_file_system::CONFLICT_RESOLUTION_POLICY_NONE; |
106 } | 108 } |
107 | 109 |
108 base::DictionaryValue* CreateDictionaryValueForFileSystemEntry( | 110 std::unique_ptr<base::DictionaryValue> CreateDictionaryValueForFileSystemEntry( |
109 const storage::FileSystemURL& url, | 111 const storage::FileSystemURL& url, |
110 sync_file_system::SyncFileType file_type) { | 112 sync_file_system::SyncFileType file_type) { |
111 if (!url.is_valid() || file_type == sync_file_system::SYNC_FILE_TYPE_UNKNOWN) | 113 if (!url.is_valid() || file_type == sync_file_system::SYNC_FILE_TYPE_UNKNOWN) |
112 return NULL; | 114 return nullptr; |
113 | 115 |
114 std::string file_path = | 116 std::string file_path = |
115 base::FilePath(storage::VirtualPath::GetNormalizedFilePath(url.path())) | 117 base::FilePath(storage::VirtualPath::GetNormalizedFilePath(url.path())) |
116 .AsUTF8Unsafe(); | 118 .AsUTF8Unsafe(); |
117 | 119 |
118 std::string root_url = | 120 std::string root_url = |
119 storage::GetFileSystemRootURI(url.origin(), url.mount_type()).spec(); | 121 storage::GetFileSystemRootURI(url.origin(), url.mount_type()).spec(); |
120 if (!url.filesystem_id().empty()) { | 122 if (!url.filesystem_id().empty()) { |
121 root_url.append(url.filesystem_id()); | 123 root_url.append(url.filesystem_id()); |
122 root_url.append("/"); | 124 root_url.append("/"); |
123 } | 125 } |
124 | 126 |
125 base::DictionaryValue* dict = new base::DictionaryValue; | 127 auto dict = base::MakeUnique<base::DictionaryValue>(); |
126 dict->SetString("fileSystemType", | 128 dict->SetString("fileSystemType", |
127 storage::GetFileSystemTypeString(url.mount_type())); | 129 storage::GetFileSystemTypeString(url.mount_type())); |
128 dict->SetString("fileSystemName", | 130 dict->SetString("fileSystemName", |
129 storage::GetFileSystemName(url.origin(), url.type())); | 131 storage::GetFileSystemName(url.origin(), url.type())); |
130 dict->SetString("rootUrl", root_url); | 132 dict->SetString("rootUrl", root_url); |
131 dict->SetString("filePath", file_path); | 133 dict->SetString("filePath", file_path); |
132 dict->SetBoolean("isDirectory", | 134 dict->SetBoolean("isDirectory", |
133 (file_type == sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); | 135 (file_type == sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); |
134 | 136 |
135 return dict; | 137 return dict; |
136 } | 138 } |
137 | 139 |
138 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |