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

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

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

Powered by Google App Engine
This is Rietveld 408576698