Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc

Issue 625463002: [fsp] Add support for observing entries and notifying about changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More implementation. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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)) {
mtomasz 2014/10/03 04:22:47 If a file system supports_notify_tag is |true|, th
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 item->file_system_id = file_systems[i].file_system_id(); 117 item->file_system_id = file_systems[i].file_system_id();
110 item->display_name = file_systems[i].display_name(); 118 item->display_name = file_systems[i].display_name();
111 item->writable = file_systems[i].writable(); 119 item->writable = file_systems[i].writable();
112 items.push_back(item); 120 items.push_back(item);
113 } 121 }
114 122
115 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); 123 SetResultList(api::file_system_provider::GetAll::Results::Create(items));
116 return true; 124 return true;
117 } 125 }
118 126
127 bool FileSystemProviderNotifyFunction::RunSync() {
128 using api::file_system_provider::Notify::Params;
129 scoped_ptr<Params> params(Params::Create(*args_));
130 EXTENSION_FUNCTION_VALIDATE(params);
131
132 Service* const service = Service::Get(GetProfile());
133 DCHECK(service);
134 if (!service)
135 return false;
136
137 ProvidedFileSystemInterface* const file_system =
138 service->GetProvidedFileSystem(extension_id(),
139 params->options.file_system_id);
140 if (!file_system) {
141 base::ListValue* const result = new base::ListValue();
142 result->Append(CreateError(kNotFoundErrorName, kNotifyFailedErrorMessage));
143 SetResult(result);
144 return true;
145 }
146
147 // TODO(mtomasz): Pass real data to Notify() instead of fake ones.
148 if (!file_system->Notify(
mtomasz 2014/10/03 04:22:47 This is not used yet.
149 base::FilePath::FromUTF8Unsafe(params->options.observed_path),
150 chromeos::file_system_provider::ProvidedFileSystemObserver::
151 CHANGED,
152 chromeos::file_system_provider::ProvidedFileSystemObserver::
153 ChildChanges(),
154 "todo-tag")) {
155 base::ListValue* const result = new base::ListValue();
156 result->Append(
157 CreateError(kSecurityErrorName, kInvalidNotificationErrorMessage));
158 SetResult(result);
159 return true;
160 }
161
162 base::ListValue* const result = new base::ListValue();
163 SetResult(result);
164 return true;
165 }
166
119 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { 167 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() {
120 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; 168 using api::file_system_provider_internal::UnmountRequestedSuccess::Params;
121 scoped_ptr<Params> params(Params::Create(*args_)); 169 scoped_ptr<Params> params(Params::Create(*args_));
122 EXTENSION_FUNCTION_VALIDATE(params); 170 EXTENSION_FUNCTION_VALIDATE(params);
123 171
124 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), 172 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()),
125 false /* has_more */); 173 false /* has_more */);
126 return true; 174 return true;
127 } 175 }
128 176
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 using api::file_system_provider_internal::OperationRequestedError::Params; 228 using api::file_system_provider_internal::OperationRequestedError::Params;
181 scoped_ptr<Params> params(Params::Create(*args_)); 229 scoped_ptr<Params> params(Params::Create(*args_));
182 EXTENSION_FUNCTION_VALIDATE(params); 230 EXTENSION_FUNCTION_VALIDATE(params);
183 231
184 const base::File::Error error = ProviderErrorToFileError(params->error); 232 const base::File::Error error = ProviderErrorToFileError(params->error);
185 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); 233 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error);
186 return true; 234 return true;
187 } 235 }
188 236
189 } // namespace extensions 237 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698