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::ProvidedFileSystemInfo; | 21 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
22 using chromeos::file_system_provider::ProvidedFileSystemInterface; | 22 using chromeos::file_system_provider::ProvidedFileSystemInterface; |
23 using chromeos::file_system_provider::RequestValue; | 23 using chromeos::file_system_provider::RequestValue; |
24 using chromeos::file_system_provider::Service; | 24 using chromeos::file_system_provider::Service; |
25 | 25 |
26 namespace extensions { | 26 namespace extensions { |
| 27 namespace { |
| 28 |
| 29 const char kNotifyFailedErrorMessage[] = |
| 30 "Sending a response for the request failed."; |
| 31 const char kInvalidNotificationErrorMessage[] = "The notification is invalid."; |
| 32 |
| 33 } // namespace |
27 | 34 |
28 bool FileSystemProviderMountFunction::RunSync() { | 35 bool FileSystemProviderMountFunction::RunSync() { |
29 using api::file_system_provider::Mount::Params; | 36 using api::file_system_provider::Mount::Params; |
30 const scoped_ptr<Params> params(Params::Create(*args_)); | 37 const scoped_ptr<Params> params(Params::Create(*args_)); |
31 EXTENSION_FUNCTION_VALIDATE(params); | 38 EXTENSION_FUNCTION_VALIDATE(params); |
32 | 39 |
33 // It's an error if the file system Id is empty. | 40 // It's an error if the file system Id is empty. |
34 if (params->options.file_system_id.empty()) { | 41 if (params->options.file_system_id.empty()) { |
35 base::ListValue* const result = new base::ListValue(); | 42 base::ListValue* const result = new base::ListValue(); |
36 result->Append(CreateError(kSecurityErrorName, kEmptyIdErrorMessage)); | 43 result->Append(CreateError(kSecurityErrorName, kEmptyIdErrorMessage)); |
(...skipping 12 matching lines...) Expand all Loading... |
49 | 56 |
50 Service* const service = Service::Get(GetProfile()); | 57 Service* const service = Service::Get(GetProfile()); |
51 DCHECK(service); | 58 DCHECK(service); |
52 if (!service) | 59 if (!service) |
53 return false; | 60 return false; |
54 | 61 |
55 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 62 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
56 if (!service->MountFileSystem(extension_id(), | 63 if (!service->MountFileSystem(extension_id(), |
57 params->options.file_system_id, | 64 params->options.file_system_id, |
58 params->options.display_name, | 65 params->options.display_name, |
59 params->options.writable)) { | 66 params->options.writable, |
| 67 params->options.supports_notify_tag)) { |
60 base::ListValue* const result = new base::ListValue(); | 68 base::ListValue* const result = new base::ListValue(); |
61 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); | 69 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); |
62 SetResult(result); | 70 SetResult(result); |
63 return true; | 71 return true; |
64 } | 72 } |
65 | 73 |
66 base::ListValue* result = new base::ListValue(); | 74 base::ListValue* result = new base::ListValue(); |
67 SetResult(result); | 75 SetResult(result); |
68 return true; | 76 return true; |
69 } | 77 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 item->display_name = file_systems[i].display_name(); | 119 item->display_name = file_systems[i].display_name(); |
112 item->writable = file_systems[i].writable(); | 120 item->writable = file_systems[i].writable(); |
113 items.push_back(item); | 121 items.push_back(item); |
114 } | 122 } |
115 } | 123 } |
116 | 124 |
117 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); | 125 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); |
118 return true; | 126 return true; |
119 } | 127 } |
120 | 128 |
| 129 bool FileSystemProviderNotifyFunction::RunSync() { |
| 130 using api::file_system_provider::Notify::Params; |
| 131 scoped_ptr<Params> params(Params::Create(*args_)); |
| 132 EXTENSION_FUNCTION_VALIDATE(params); |
| 133 |
| 134 Service* const service = Service::Get(GetProfile()); |
| 135 DCHECK(service); |
| 136 if (!service) |
| 137 return false; |
| 138 |
| 139 ProvidedFileSystemInterface* const file_system = |
| 140 service->GetProvidedFileSystem(extension_id(), |
| 141 params->options.file_system_id); |
| 142 if (!file_system) { |
| 143 base::ListValue* const result = new base::ListValue(); |
| 144 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); |
| 145 SetResult(result); |
| 146 return true; |
| 147 } |
| 148 |
| 149 // TODO(mtomasz): Pass real data to Notify() instead of fake ones. |
| 150 if (!file_system->Notify( |
| 151 base::FilePath::FromUTF8Unsafe(params->options.observed_path), |
| 152 chromeos::file_system_provider::ProvidedFileSystemObserver::CHANGED, |
| 153 chromeos::file_system_provider::ProvidedFileSystemObserver:: |
| 154 ChildChanges(), |
| 155 "todo-tag")) { |
| 156 base::ListValue* const result = new base::ListValue(); |
| 157 result->Append( |
| 158 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage)); |
| 159 SetResult(result); |
| 160 return true; |
| 161 } |
| 162 |
| 163 base::ListValue* const result = new base::ListValue(); |
| 164 SetResult(result); |
| 165 return true; |
| 166 } |
| 167 |
121 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { | 168 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { |
122 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; | 169 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; |
123 scoped_ptr<Params> params(Params::Create(*args_)); | 170 scoped_ptr<Params> params(Params::Create(*args_)); |
124 EXTENSION_FUNCTION_VALIDATE(params); | 171 EXTENSION_FUNCTION_VALIDATE(params); |
125 | 172 |
126 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), | 173 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), |
127 false /* has_more */); | 174 false /* has_more */); |
128 return true; | 175 return true; |
129 } | 176 } |
130 | 177 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 using api::file_system_provider_internal::OperationRequestedError::Params; | 229 using api::file_system_provider_internal::OperationRequestedError::Params; |
183 scoped_ptr<Params> params(Params::Create(*args_)); | 230 scoped_ptr<Params> params(Params::Create(*args_)); |
184 EXTENSION_FUNCTION_VALIDATE(params); | 231 EXTENSION_FUNCTION_VALIDATE(params); |
185 | 232 |
186 const base::File::Error error = ProviderErrorToFileError(params->error); | 233 const base::File::Error error = ProviderErrorToFileError(params->error); |
187 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); | 234 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); |
188 return true; | 235 return true; |
189 } | 236 } |
190 | 237 |
191 } // namespace extensions | 238 } // namespace extensions |
OLD | NEW |