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& child_change) { |
hirono
2014/10/24 06:58:43
nit: child_change -> change
mtomasz
2014/10/24 09:50:24
Done.
| |
58 const api::file_system_provider::ChildChange& child_change) { | 57 ProvidedFileSystemObserver::Change result; |
59 ProvidedFileSystemObserver::ChildChange result; | |
60 result.entry_path = base::FilePath::FromUTF8Unsafe(child_change.entry_path); | 58 result.entry_path = base::FilePath::FromUTF8Unsafe(child_change.entry_path); |
61 result.change_type = ParseChangeType(child_change.change_type); | 59 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& child_changes) { |
hirono
2014/10/24 06:58:42
nit: child_changes -> changes
mtomasz
2014/10/24 09:50:24
Done.
| |
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 (IDLChanges::const_iterator it = child_changes.begin(); |
hirono
2014/10/24 06:58:43
nit:
You can use "for (auto it : changes)".
But u
mtomasz
2014/10/24 09:50:24
Right! Done.
| |
71 it != child_changes.end(); | 69 it != child_changes.end(); |
72 ++it) { | 70 ++it) { |
73 results->push_back(ParseChildChange(*it->get())); | 71 results->push_back(ParseChange(*it->get())); |
74 } | 72 } |
75 return results; | 73 return results; |
76 } | 74 } |
77 | 75 |
78 } // namespace | 76 } // namespace |
79 | 77 |
80 bool FileSystemProviderMountFunction::RunSync() { | 78 bool FileSystemProviderMountFunction::RunSync() { |
81 using api::file_system_provider::Mount::Params; | 79 using api::file_system_provider::Mount::Params; |
82 const scoped_ptr<Params> params(Params::Create(*args_)); | 80 const scoped_ptr<Params> params(Params::Create(*args_)); |
83 EXTENSION_FUNCTION_VALIDATE(params); | 81 EXTENSION_FUNCTION_VALIDATE(params); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 params->options.file_system_id); | 186 params->options.file_system_id); |
189 if (!file_system) { | 187 if (!file_system) { |
190 base::ListValue* const result = new base::ListValue(); | 188 base::ListValue* const result = new base::ListValue(); |
191 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); | 189 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); |
192 SetResult(result); | 190 SetResult(result); |
193 return true; | 191 return true; |
194 } | 192 } |
195 | 193 |
196 if (!file_system->Notify( | 194 if (!file_system->Notify( |
197 base::FilePath::FromUTF8Unsafe(params->options.observed_path), | 195 base::FilePath::FromUTF8Unsafe(params->options.observed_path), |
196 params->options.recursive, | |
198 ParseChangeType(params->options.change_type), | 197 ParseChangeType(params->options.change_type), |
199 params->options.child_changes.get() | 198 params->options.changes.get() |
200 ? ParseChildChanges(*params->options.child_changes.get()) | 199 ? ParseChanges(*params->options.changes.get()) |
201 : make_scoped_ptr(new ProvidedFileSystemObserver::ChildChanges), | 200 : make_scoped_ptr(new ProvidedFileSystemObserver::Changes), |
202 params->options.tag.get() ? *params->options.tag.get() : "")) { | 201 params->options.tag.get() ? *params->options.tag.get() : "")) { |
203 base::ListValue* const result = new base::ListValue(); | 202 base::ListValue* const result = new base::ListValue(); |
204 result->Append( | 203 result->Append( |
205 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage)); | 204 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage)); |
206 SetResult(result); | 205 SetResult(result); |
207 return true; | 206 return true; |
208 } | 207 } |
209 | 208 |
210 base::ListValue* const result = new base::ListValue(); | 209 base::ListValue* const result = new base::ListValue(); |
211 SetResult(result); | 210 SetResult(result); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 using api::file_system_provider_internal::OperationRequestedError::Params; | 275 using api::file_system_provider_internal::OperationRequestedError::Params; |
277 scoped_ptr<Params> params(Params::Create(*args_)); | 276 scoped_ptr<Params> params(Params::Create(*args_)); |
278 EXTENSION_FUNCTION_VALIDATE(params); | 277 EXTENSION_FUNCTION_VALIDATE(params); |
279 | 278 |
280 const base::File::Error error = ProviderErrorToFileError(params->error); | 279 const base::File::Error error = ProviderErrorToFileError(params->error); |
281 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); | 280 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); |
282 return true; | 281 return true; |
283 } | 282 } |
284 | 283 |
285 } // namespace extensions | 284 } // namespace extensions |
OLD | NEW |