OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/chromeos/extensions/file_system_provider/file_system_pr
ovider_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_system_provider/file_system_pr
ovider_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
15 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 15 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
16 #include "chrome/browser/chromeos/file_system_provider/request_value.h" | 16 #include "chrome/browser/chromeos/file_system_provider/request_value.h" |
17 #include "chrome/browser/chromeos/file_system_provider/service.h" | 17 #include "chrome/browser/chromeos/file_system_provider/service.h" |
18 #include "chrome/common/extensions/api/file_system_provider.h" | 18 #include "chrome/common/extensions/api/file_system_provider.h" |
19 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 19 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
20 | 20 |
21 using chromeos::file_system_provider::MountOptions; | 21 using chromeos::file_system_provider::MountOptions; |
22 using chromeos::file_system_provider::ProvidedFileSystemInfo; | 22 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
23 using chromeos::file_system_provider::ProvidedFileSystemInterface; | 23 using chromeos::file_system_provider::ProvidedFileSystemInterface; |
| 24 using chromeos::file_system_provider::ProvidedFileSystemObserver; |
24 using chromeos::file_system_provider::RequestValue; | 25 using chromeos::file_system_provider::RequestValue; |
25 using chromeos::file_system_provider::Service; | 26 using chromeos::file_system_provider::Service; |
26 | 27 |
27 namespace extensions { | 28 namespace extensions { |
28 namespace { | 29 namespace { |
29 | 30 |
| 31 typedef std::vector<linked_ptr<api::file_system_provider::ChildChange>> |
| 32 IDLChildChanges; |
| 33 |
30 const char kNotifyFailedErrorMessage[] = | 34 const char kNotifyFailedErrorMessage[] = |
31 "Sending a response for the request failed."; | 35 "Sending a response for the request failed."; |
32 const char kInvalidNotificationErrorMessage[] = "The notification is invalid."; | 36 const char kInvalidNotificationErrorMessage[] = "The notification is invalid."; |
33 | 37 |
| 38 // Converts the change type from the IDL type to a native type. |changed_type| |
| 39 // must be specified (not CHANGE_TYPE_NONE). |
| 40 ProvidedFileSystemObserver::ChangeType ParseChangeType( |
| 41 const api::file_system_provider::ChangeType& change_type) { |
| 42 switch (change_type) { |
| 43 case api::file_system_provider::CHANGE_TYPE_CHANGED: |
| 44 return ProvidedFileSystemObserver::CHANGED; |
| 45 case api::file_system_provider::CHANGE_TYPE_DELETED: |
| 46 return ProvidedFileSystemObserver::DELETED; |
| 47 default: |
| 48 break; |
| 49 } |
| 50 NOTREACHED(); |
| 51 return ProvidedFileSystemObserver::CHANGED; |
| 52 } |
| 53 |
| 54 // Convert the child change from the IDL type to a native type. The reason IDL |
| 55 // types are not used is since they are imperfect, eg. paths are stored as |
| 56 // strings. |
| 57 ProvidedFileSystemObserver::ChildChange ParseChildChange( |
| 58 const api::file_system_provider::ChildChange& child_change) { |
| 59 ProvidedFileSystemObserver::ChildChange result; |
| 60 result.entry_path = base::FilePath::FromUTF8Unsafe(child_change.entry_path); |
| 61 result.change_type = ParseChangeType(child_change.change_type); |
| 62 return result; |
| 63 } |
| 64 |
| 65 // Converts a list of child changes from the IDL type to a native type. |
| 66 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> ParseChildChanges( |
| 67 const IDLChildChanges& child_changes) { |
| 68 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> results( |
| 69 new ProvidedFileSystemObserver::ChildChanges); |
| 70 for (IDLChildChanges::const_iterator it = child_changes.begin(); |
| 71 it != child_changes.end(); |
| 72 ++it) { |
| 73 results->push_back(ParseChildChange(*it->get())); |
| 74 } |
| 75 return results; |
| 76 } |
| 77 |
34 } // namespace | 78 } // namespace |
35 | 79 |
36 bool FileSystemProviderMountFunction::RunSync() { | 80 bool FileSystemProviderMountFunction::RunSync() { |
37 using api::file_system_provider::Mount::Params; | 81 using api::file_system_provider::Mount::Params; |
38 const scoped_ptr<Params> params(Params::Create(*args_)); | 82 const scoped_ptr<Params> params(Params::Create(*args_)); |
39 EXTENSION_FUNCTION_VALIDATE(params); | 83 EXTENSION_FUNCTION_VALIDATE(params); |
40 | 84 |
41 // It's an error if the file system Id is empty. | 85 // It's an error if the file system Id is empty. |
42 if (params->options.file_system_id.empty()) { | 86 if (params->options.file_system_id.empty()) { |
43 base::ListValue* const result = new base::ListValue(); | 87 base::ListValue* const result = new base::ListValue(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 ProvidedFileSystemInterface* const file_system = | 186 ProvidedFileSystemInterface* const file_system = |
143 service->GetProvidedFileSystem(extension_id(), | 187 service->GetProvidedFileSystem(extension_id(), |
144 params->options.file_system_id); | 188 params->options.file_system_id); |
145 if (!file_system) { | 189 if (!file_system) { |
146 base::ListValue* const result = new base::ListValue(); | 190 base::ListValue* const result = new base::ListValue(); |
147 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); | 191 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); |
148 SetResult(result); | 192 SetResult(result); |
149 return true; | 193 return true; |
150 } | 194 } |
151 | 195 |
152 // TODO(mtomasz): Pass real data to Notify() instead of fake ones. | |
153 if (!file_system->Notify( | 196 if (!file_system->Notify( |
154 base::FilePath::FromUTF8Unsafe(params->options.observed_path), | 197 base::FilePath::FromUTF8Unsafe(params->options.observed_path), |
155 chromeos::file_system_provider::ProvidedFileSystemObserver::CHANGED, | 198 ParseChangeType(params->options.change_type), |
156 chromeos::file_system_provider::ProvidedFileSystemObserver:: | 199 params->options.child_changes.get() |
157 ChildChanges(), | 200 ? ParseChildChanges(*params->options.child_changes.get()) |
158 "todo-tag")) { | 201 : make_scoped_ptr(new ProvidedFileSystemObserver::ChildChanges), |
| 202 params->options.tag.get() ? *params->options.tag.get() : "")) { |
159 base::ListValue* const result = new base::ListValue(); | 203 base::ListValue* const result = new base::ListValue(); |
160 result->Append( | 204 result->Append( |
161 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage)); | 205 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage)); |
162 SetResult(result); | 206 SetResult(result); |
163 return true; | 207 return true; |
164 } | 208 } |
165 | 209 |
166 base::ListValue* const result = new base::ListValue(); | 210 base::ListValue* const result = new base::ListValue(); |
167 SetResult(result); | 211 SetResult(result); |
168 return true; | 212 return true; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 using api::file_system_provider_internal::OperationRequestedError::Params; | 276 using api::file_system_provider_internal::OperationRequestedError::Params; |
233 scoped_ptr<Params> params(Params::Create(*args_)); | 277 scoped_ptr<Params> params(Params::Create(*args_)); |
234 EXTENSION_FUNCTION_VALIDATE(params); | 278 EXTENSION_FUNCTION_VALIDATE(params); |
235 | 279 |
236 const base::File::Error error = ProviderErrorToFileError(params->error); | 280 const base::File::Error error = ProviderErrorToFileError(params->error); |
237 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); | 281 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); |
238 return true; | 282 return true; |
239 } | 283 } |
240 | 284 |
241 } // namespace extensions | 285 } // namespace extensions |
OLD | NEW |