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 |
| 32 } // namespace |
27 | 33 |
28 bool FileSystemProviderMountFunction::RunSync() { | 34 bool FileSystemProviderMountFunction::RunSync() { |
29 using api::file_system_provider::Mount::Params; | 35 using api::file_system_provider::Mount::Params; |
30 const scoped_ptr<Params> params(Params::Create(*args_)); | 36 const scoped_ptr<Params> params(Params::Create(*args_)); |
31 EXTENSION_FUNCTION_VALIDATE(params); | 37 EXTENSION_FUNCTION_VALIDATE(params); |
32 | 38 |
33 // It's an error if the file system Id is empty. | 39 // It's an error if the file system Id is empty. |
34 if (params->options.file_system_id.empty()) { | 40 if (params->options.file_system_id.empty()) { |
35 base::ListValue* const result = new base::ListValue(); | 41 base::ListValue* const result = new base::ListValue(); |
36 result->Append(CreateError(kSecurityErrorName, kEmptyIdErrorMessage)); | 42 result->Append(CreateError(kSecurityErrorName, kEmptyIdErrorMessage)); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 item->file_system_id = file_systems[i].file_system_id(); | 115 item->file_system_id = file_systems[i].file_system_id(); |
110 item->display_name = file_systems[i].display_name(); | 116 item->display_name = file_systems[i].display_name(); |
111 item->writable = file_systems[i].writable(); | 117 item->writable = file_systems[i].writable(); |
112 items.push_back(item); | 118 items.push_back(item); |
113 } | 119 } |
114 | 120 |
115 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); | 121 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); |
116 return true; | 122 return true; |
117 } | 123 } |
118 | 124 |
| 125 bool FileSystemProviderNotifyFunction::RunSync() { |
| 126 using api::file_system_provider::Notify::Params; |
| 127 scoped_ptr<Params> params(Params::Create(*args_)); |
| 128 EXTENSION_FUNCTION_VALIDATE(params); |
| 129 |
| 130 Service* const service = Service::Get(GetProfile()); |
| 131 DCHECK(service); |
| 132 if (!service) |
| 133 return false; |
| 134 |
| 135 ProvidedFileSystemInterface* const file_system = |
| 136 service->GetProvidedFileSystem(extension_id(), |
| 137 params->options.file_system_id); |
| 138 if (!file_system) { |
| 139 base::ListValue* const result = new base::ListValue(); |
| 140 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage)); |
| 141 SetResult(result); |
| 142 return true; |
| 143 } |
| 144 |
| 145 FOR_EACH_OBSERVER( |
| 146 chromeos::file_system_provider::ProvidedFileSystemInterface::Observer, |
| 147 *file_system->GetObservers(), |
| 148 OnEntryChanged( |
| 149 base::FilePath::FromUTF8Unsafe(params->options.observed_path), |
| 150 chromeos::file_system_provider::ProvidedFileSystemInterface:: |
| 151 CHANGED /* TODO(mtomasz) */, |
| 152 chromeos::file_system_provider::ProvidedFileSystemInterface:: |
| 153 ChildChanges())); |
| 154 |
| 155 base::ListValue* const result = new base::ListValue(); |
| 156 SetResult(result); |
| 157 return true; |
| 158 } |
| 159 |
119 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { | 160 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { |
120 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; | 161 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; |
121 scoped_ptr<Params> params(Params::Create(*args_)); | 162 scoped_ptr<Params> params(Params::Create(*args_)); |
122 EXTENSION_FUNCTION_VALIDATE(params); | 163 EXTENSION_FUNCTION_VALIDATE(params); |
123 | 164 |
124 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), | 165 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), |
125 false /* has_more */); | 166 false /* has_more */); |
126 return true; | 167 return true; |
127 } | 168 } |
128 | 169 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 using api::file_system_provider_internal::OperationRequestedError::Params; | 221 using api::file_system_provider_internal::OperationRequestedError::Params; |
181 scoped_ptr<Params> params(Params::Create(*args_)); | 222 scoped_ptr<Params> params(Params::Create(*args_)); |
182 EXTENSION_FUNCTION_VALIDATE(params); | 223 EXTENSION_FUNCTION_VALIDATE(params); |
183 | 224 |
184 const base::File::Error error = ProviderErrorToFileError(params->error); | 225 const base::File::Error error = ProviderErrorToFileError(params->error); |
185 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); | 226 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); |
186 return true; | 227 return true; |
187 } | 228 } |
188 | 229 |
189 } // namespace extensions | 230 } // namespace extensions |
OLD | NEW |