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" |
(...skipping 10 matching lines...) Expand all Loading... |
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::ProvidedFileSystemObserver; |
25 using chromeos::file_system_provider::RequestValue; | 25 using chromeos::file_system_provider::RequestValue; |
26 using chromeos::file_system_provider::Service; | 26 using chromeos::file_system_provider::Service; |
27 | 27 |
28 namespace extensions { | 28 namespace extensions { |
29 namespace { | 29 namespace { |
30 | 30 |
31 typedef std::vector<linked_ptr<api::file_system_provider::ChildChange>> | 31 typedef std::vector<linked_ptr<api::file_system_provider::Change>> IDLChanges; |
32 IDLChildChanges; | |
33 | 32 |
34 const char kNotifyFailedErrorMessage[] = | 33 const char kNotifyFailedErrorMessage[] = |
35 "Sending a response for the request failed."; | 34 "Sending a response for the request failed."; |
36 const char kInvalidNotificationErrorMessage[] = "The notification is invalid."; | 35 const char kInvalidNotificationErrorMessage[] = "The notification is invalid."; |
37 | 36 |
38 // Converts the change type from the IDL type to a native type. |changed_type| | 37 // Converts the change type from the IDL type to a native type. |changed_type| |
39 // must be specified (not CHANGE_TYPE_NONE). | 38 // must be specified (not CHANGE_TYPE_NONE). |
40 ProvidedFileSystemObserver::ChangeType ParseChangeType( | 39 ProvidedFileSystemObserver::ChangeType ParseChangeType( |
41 const api::file_system_provider::ChangeType& change_type) { | 40 const api::file_system_provider::ChangeType& change_type) { |
42 switch (change_type) { | 41 switch (change_type) { |
43 case api::file_system_provider::CHANGE_TYPE_CHANGED: | 42 case api::file_system_provider::CHANGE_TYPE_CHANGED: |
44 return ProvidedFileSystemObserver::CHANGED; | 43 return ProvidedFileSystemObserver::CHANGED; |
45 case api::file_system_provider::CHANGE_TYPE_DELETED: | 44 case api::file_system_provider::CHANGE_TYPE_DELETED: |
46 return ProvidedFileSystemObserver::DELETED; | 45 return ProvidedFileSystemObserver::DELETED; |
47 default: | 46 default: |
48 break; | 47 break; |
49 } | 48 } |
50 NOTREACHED(); | 49 NOTREACHED(); |
51 return ProvidedFileSystemObserver::CHANGED; | 50 return ProvidedFileSystemObserver::CHANGED; |
52 } | 51 } |
53 | 52 |
54 // Convert the child change from the IDL type to a native type. The reason IDL | 53 // Convert the change from the IDL type to a native type. The reason IDL types |
55 // types are not used is since they are imperfect, eg. paths are stored as | 54 // are not used is since they are imperfect, eg. paths are stored as strings. |
56 // strings. | 55 ProvidedFileSystemObserver::Change ParseChange( |
57 ProvidedFileSystemObserver::ChildChange ParseChildChange( | 56 const api::file_system_provider::Change& change) { |
58 const api::file_system_provider::ChildChange& child_change) { | 57 ProvidedFileSystemObserver::Change result; |
59 ProvidedFileSystemObserver::ChildChange result; | 58 result.entry_path = base::FilePath::FromUTF8Unsafe(change.entry_path); |
60 result.entry_path = base::FilePath::FromUTF8Unsafe(child_change.entry_path); | 59 result.change_type = ParseChangeType(change.change_type); |
61 result.change_type = ParseChangeType(child_change.change_type); | |
62 return result; | 60 return result; |
63 } | 61 } |
64 | 62 |
65 // Converts a list of child changes from the IDL type to a native type. | 63 // Converts a list of child changes from the IDL type to a native type. |
66 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> ParseChildChanges( | 64 scoped_ptr<ProvidedFileSystemObserver::Changes> ParseChanges( |
67 const IDLChildChanges& child_changes) { | 65 const IDLChanges& changes) { |
68 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> results( | 66 scoped_ptr<ProvidedFileSystemObserver::Changes> results( |
69 new ProvidedFileSystemObserver::ChildChanges); | 67 new ProvidedFileSystemObserver::Changes); |
70 for (IDLChildChanges::const_iterator it = child_changes.begin(); | 68 for (const auto& change : changes) { |
71 it != child_changes.end(); | 69 results->push_back(ParseChange(*change)); |
72 ++it) { | |
73 results->push_back(ParseChildChange(*it->get())); | |
74 } | 70 } |
75 return results; | 71 return results; |
76 } | 72 } |
77 | 73 |
78 } // namespace | 74 } // namespace |
79 | 75 |
80 bool FileSystemProviderMountFunction::RunSync() { | 76 bool FileSystemProviderMountFunction::RunSync() { |
81 using api::file_system_provider::Mount::Params; | 77 using api::file_system_provider::Mount::Params; |
82 const scoped_ptr<Params> params(Params::Create(*args_)); | 78 const scoped_ptr<Params> params(Params::Create(*args_)); |
83 EXTENSION_FUNCTION_VALIDATE(params); | 79 EXTENSION_FUNCTION_VALIDATE(params); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 params->options.file_system_id); | 184 params->options.file_system_id); |
189 if (!file_system) { | 185 if (!file_system) { |
190 base::ListValue* const result = new base::ListValue(); | 186 base::ListValue* const result = new base::ListValue(); |
191 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); | 187 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); |
192 SetResult(result); | 188 SetResult(result); |
193 return true; | 189 return true; |
194 } | 190 } |
195 | 191 |
196 if (!file_system->Notify( | 192 if (!file_system->Notify( |
197 base::FilePath::FromUTF8Unsafe(params->options.observed_path), | 193 base::FilePath::FromUTF8Unsafe(params->options.observed_path), |
| 194 params->options.recursive, |
198 ParseChangeType(params->options.change_type), | 195 ParseChangeType(params->options.change_type), |
199 params->options.child_changes.get() | 196 params->options.changes.get() |
200 ? ParseChildChanges(*params->options.child_changes.get()) | 197 ? ParseChanges(*params->options.changes.get()) |
201 : make_scoped_ptr(new ProvidedFileSystemObserver::ChildChanges), | 198 : make_scoped_ptr(new ProvidedFileSystemObserver::Changes), |
202 params->options.tag.get() ? *params->options.tag.get() : "")) { | 199 params->options.tag.get() ? *params->options.tag.get() : "")) { |
203 base::ListValue* const result = new base::ListValue(); | 200 base::ListValue* const result = new base::ListValue(); |
204 result->Append( | 201 result->Append( |
205 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage)); | 202 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage)); |
206 SetResult(result); | 203 SetResult(result); |
207 return true; | 204 return true; |
208 } | 205 } |
209 | 206 |
210 base::ListValue* const result = new base::ListValue(); | 207 base::ListValue* const result = new base::ListValue(); |
211 SetResult(result); | 208 SetResult(result); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 using api::file_system_provider_internal::OperationRequestedError::Params; | 273 using api::file_system_provider_internal::OperationRequestedError::Params; |
277 scoped_ptr<Params> params(Params::Create(*args_)); | 274 scoped_ptr<Params> params(Params::Create(*args_)); |
278 EXTENSION_FUNCTION_VALIDATE(params); | 275 EXTENSION_FUNCTION_VALIDATE(params); |
279 | 276 |
280 const base::File::Error error = ProviderErrorToFileError(params->error); | 277 const base::File::Error error = ProviderErrorToFileError(params->error); |
281 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); | 278 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); |
282 return true; | 279 return true; |
283 } | 280 } |
284 | 281 |
285 } // namespace extensions | 282 } // namespace extensions |
OLD | NEW |