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

Side by Side Diff: trunk/src/chrome/browser/chromeos/file_system_provider/service.cc

Issue 242113007: Revert 264780 "[fsp] Add FileSystemURLParser to the file system ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/file_system_provider/service.h" 5 #include "chrome/browser/chromeos/file_system_provider/service.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 9 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
10 #include "chrome/browser/chromeos/file_system_provider/observer.h" 10 #include "chrome/browser/chromeos/file_system_provider/observer.h"
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 34
35 } // namespace 35 } // namespace
36 36
37 Service::Service(Profile* profile) 37 Service::Service(Profile* profile)
38 : profile_(profile), 38 : profile_(profile),
39 file_system_factory_(base::Bind(CreateProvidedFileSystem)), 39 file_system_factory_(base::Bind(CreateProvidedFileSystem)),
40 next_id_(1), 40 next_id_(1),
41 weak_ptr_factory_(this) {} 41 weak_ptr_factory_(this) {}
42 42
43 Service::~Service() { 43 Service::~Service() { STLDeleteValues(&file_system_map_); }
44 ProvidedFileSystemMap::iterator it = file_system_map_.begin();
45 while (it != file_system_map_.end()) {
46 const int file_system_id = it->first;
47 const std::string extension_id =
48 it->second->GetFileSystemInfo().extension_id();
49 ++it;
50 UnmountFileSystem(extension_id, file_system_id);
51 }
52
53 DCHECK_EQ(0u, file_system_map_.size());
54 STLDeleteValues(&file_system_map_);
55 }
56 44
57 // static 45 // static
58 Service* Service::Get(content::BrowserContext* context) { 46 Service* Service::Get(content::BrowserContext* context) {
59 return ServiceFactory::Get(context); 47 return ServiceFactory::Get(context);
60 } 48 }
61 49
62 void Service::AddObserver(Observer* observer) { 50 void Service::AddObserver(Observer* observer) {
63 DCHECK(observer); 51 DCHECK(observer);
64 observers_.AddObserver(observer); 52 observers_.AddObserver(observer);
65 } 53 }
(...skipping 25 matching lines...) Expand all
91 79
92 // The provided file system id is unique per service, so per profile. 80 // The provided file system id is unique per service, so per profile.
93 int file_system_id = next_id_; 81 int file_system_id = next_id_;
94 82
95 fileapi::ExternalMountPoints* const mount_points = 83 fileapi::ExternalMountPoints* const mount_points =
96 fileapi::ExternalMountPoints::GetSystemInstance(); 84 fileapi::ExternalMountPoints::GetSystemInstance();
97 DCHECK(mount_points); 85 DCHECK(mount_points);
98 86
99 // The mount point path and name are unique per system, since they are system 87 // The mount point path and name are unique per system, since they are system
100 // wide. This is necessary for copying between profiles. 88 // wide. This is necessary for copying between profiles.
101 const base::FilePath& mount_path = 89 const base::FilePath& mount_point_path =
102 util::GetMountPath(profile_, extension_id, file_system_id); 90 util::GetMountPointPath(profile_, extension_id, file_system_id);
103 const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); 91 const std::string mount_point_name =
92 mount_point_path.BaseName().AsUTF8Unsafe();
104 93
105 if (!mount_points->RegisterFileSystem(mount_point_name, 94 if (!mount_points->RegisterFileSystem(mount_point_name,
106 fileapi::kFileSystemTypeProvided, 95 fileapi::kFileSystemTypeProvided,
107 fileapi::FileSystemMountOption(), 96 fileapi::FileSystemMountOption(),
108 mount_path)) { 97 mount_point_path)) {
109 FOR_EACH_OBSERVER( 98 FOR_EACH_OBSERVER(
110 Observer, 99 Observer,
111 observers_, 100 observers_,
112 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), 101 OnProvidedFileSystemMount(ProvidedFileSystemInfo(),
113 base::File::FILE_ERROR_INVALID_OPERATION)); 102 base::File::FILE_ERROR_INVALID_OPERATION));
114 return 0; 103 return 0;
115 } 104 }
116 105
117 // Store the file system descriptor. Use the mount point name as the file 106 // Store the file system descriptor. Use the mount point name as the file
118 // system provider file system id. 107 // system provider file system id.
119 // Examples: 108 // Examples:
120 // file_system_id = 41 109 // file_system_id = 41
121 // mount_point_name = b33f1337-41-5aa5 110 // mount_point_name = file_system_id = b33f1337-41-5aa5
122 // mount_path = /provided/b33f1337-41-5aa5 111 // mount_point_path = /provided/b33f1337-41-5aa5
123 ProvidedFileSystemInfo file_system_info( 112 ProvidedFileSystemInfo file_system_info(
124 extension_id, file_system_id, file_system_name, mount_path); 113 extension_id, file_system_id, file_system_name, mount_point_path);
125 114
126 // The event router may be NULL for unit tests. 115 // The event router may be NULL for unit tests.
127 extensions::EventRouter* router = extensions::EventRouter::Get(profile_); 116 extensions::EventRouter* router = extensions::EventRouter::Get(profile_);
128 117
129 ProvidedFileSystemInterface* file_system = 118 ProvidedFileSystemInterface* file_system =
130 file_system_factory_.Run(router, file_system_info); 119 file_system_factory_.Run(router, file_system_info);
131 DCHECK(file_system); 120 DCHECK(file_system);
132 file_system_map_[file_system_id] = file_system; 121 file_system_map_[file_system_id] = file_system;
133 mount_point_name_to_id_map_[mount_point_name] = file_system_id;
134 122
135 FOR_EACH_OBSERVER( 123 FOR_EACH_OBSERVER(
136 Observer, 124 Observer,
137 observers_, 125 observers_,
138 OnProvidedFileSystemMount(file_system_info, base::File::FILE_OK)); 126 OnProvidedFileSystemMount(file_system_info, base::File::FILE_OK));
139 127
140 next_id_++; 128 next_id_++;
141 return file_system_id; 129 return file_system_id;
142 } 130 }
143 131
144 bool Service::UnmountFileSystem(const std::string& extension_id, 132 bool Service::UnmountFileSystem(const std::string& extension_id,
145 int file_system_id) { 133 int file_system_id) {
146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 134 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
147 135
148 const ProvidedFileSystemMap::iterator file_system_it = 136 ProvidedFileSystemMap::iterator file_system_it =
149 file_system_map_.find(file_system_id); 137 file_system_map_.find(file_system_id);
150 if (file_system_it == file_system_map_.end() || 138 if (file_system_it == file_system_map_.end() ||
151 file_system_it->second->GetFileSystemInfo().extension_id() != 139 file_system_it->second->GetFileSystemInfo().extension_id() !=
152 extension_id) { 140 extension_id) {
153 const ProvidedFileSystemInfo empty_file_system_info; 141 const ProvidedFileSystemInfo empty_file_system_info;
154 FOR_EACH_OBSERVER( 142 FOR_EACH_OBSERVER(
155 Observer, 143 Observer,
156 observers_, 144 observers_,
157 OnProvidedFileSystemUnmount(empty_file_system_info, 145 OnProvidedFileSystemUnmount(empty_file_system_info,
158 base::File::FILE_ERROR_NOT_FOUND)); 146 base::File::FILE_ERROR_NOT_FOUND));
(...skipping 16 matching lines...) Expand all
175 OnProvidedFileSystemUnmount(file_system_info, 163 OnProvidedFileSystemUnmount(file_system_info,
176 base::File::FILE_ERROR_INVALID_OPERATION)); 164 base::File::FILE_ERROR_INVALID_OPERATION));
177 return false; 165 return false;
178 } 166 }
179 167
180 FOR_EACH_OBSERVER( 168 FOR_EACH_OBSERVER(
181 Observer, 169 Observer,
182 observers_, 170 observers_,
183 OnProvidedFileSystemUnmount(file_system_info, base::File::FILE_OK)); 171 OnProvidedFileSystemUnmount(file_system_info, base::File::FILE_OK));
184 172
185 mount_point_name_to_id_map_.erase(mount_point_name);
186
187 delete file_system_it->second; 173 delete file_system_it->second;
188 file_system_map_.erase(file_system_it); 174 file_system_map_.erase(file_system_it);
189
190 return true; 175 return true;
191 } 176 }
192 177
193 bool Service::RequestUnmount(int file_system_id) { 178 bool Service::RequestUnmount(int file_system_id) {
194 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
195 180
196 ProvidedFileSystemMap::iterator file_system_it = 181 ProvidedFileSystemMap::iterator file_system_it =
197 file_system_map_.find(file_system_id); 182 file_system_map_.find(file_system_id);
198 if (file_system_it == file_system_map_.end()) 183 if (file_system_it == file_system_map_.end())
199 return false; 184 return false;
(...skipping 14 matching lines...) Expand all
214 result.push_back(it->second->GetFileSystemInfo()); 199 result.push_back(it->second->GetFileSystemInfo());
215 } 200 }
216 return result; 201 return result;
217 } 202 }
218 203
219 ProvidedFileSystemInterface* Service::GetProvidedFileSystem( 204 ProvidedFileSystemInterface* Service::GetProvidedFileSystem(
220 const std::string& extension_id, 205 const std::string& extension_id,
221 int file_system_id) { 206 int file_system_id) {
222 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 207 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
223 208
224 const ProvidedFileSystemMap::const_iterator file_system_it = 209 ProvidedFileSystemMap::iterator file_system_it =
225 file_system_map_.find(file_system_id); 210 file_system_map_.find(file_system_id);
226 if (file_system_it == file_system_map_.end() || 211 if (file_system_it == file_system_map_.end() ||
227 file_system_it->second->GetFileSystemInfo().extension_id() != 212 file_system_it->second->GetFileSystemInfo().extension_id() !=
228 extension_id) { 213 extension_id) {
229 return NULL; 214 return NULL;
230 } 215 }
231 216
232 return file_system_it->second; 217 return file_system_it->second;
233 } 218 }
234 219
235 ProvidedFileSystemInterface* Service::GetProvidedFileSystem(
236 const std::string& mount_point_name) {
237 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
238
239 const MountPointNameToIdMap::const_iterator mapping_it =
240 mount_point_name_to_id_map_.find(mount_point_name);
241 if (mapping_it == mount_point_name_to_id_map_.end())
242 return NULL;
243
244 const ProvidedFileSystemMap::const_iterator file_system_it =
245 file_system_map_.find(mapping_it->second);
246 if (file_system_it == file_system_map_.end())
247 return NULL;
248
249 return file_system_it->second;
250 }
251
252 void Service::Shutdown() {} 220 void Service::Shutdown() {}
253 221
254 void Service::OnRequestUnmountStatus( 222 void Service::OnRequestUnmountStatus(
255 const ProvidedFileSystemInfo& file_system_info, 223 const ProvidedFileSystemInfo& file_system_info,
256 base::File::Error error) { 224 base::File::Error error) {
257 // Notify observers about failure in unmounting, since mount() will not be 225 // Notify observers about failure in unmounting, since mount() will not be
258 // called by the provided file system. In case of success mount() will be 226 // called by the provided file system. In case of success mount() will be
259 // invoked, and observers notified, so there is no need to call them now. 227 // invoked, and observers notified, so there is no need to call them now.
260 if (error != base::File::FILE_OK) { 228 if (error != base::File::FILE_OK) {
261 FOR_EACH_OBSERVER(Observer, 229 FOR_EACH_OBSERVER(Observer,
262 observers_, 230 observers_,
263 OnProvidedFileSystemUnmount(file_system_info, error)); 231 OnProvidedFileSystemUnmount(file_system_info, error));
264 } 232 }
265 } 233 }
266 234
267 } // namespace file_system_provider 235 } // namespace file_system_provider
268 } // namespace chromeos 236 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698