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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.cc

Issue 7457001: Adding support for mount point different from removable devices to MountLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_browser_event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 DictionaryValue* result = new DictionaryValue(); 48 DictionaryValue* result = new DictionaryValue();
49 result->SetString("mountPath", disk->mount_path()); 49 result->SetString("mountPath", disk->mount_path());
50 result->SetString("devicePath", disk->device_path()); 50 result->SetString("devicePath", disk->device_path());
51 result->SetString("label", disk->device_label()); 51 result->SetString("label", disk->device_label());
52 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); 52 result->SetString("deviceType", DeviceTypeToString(disk->device_type()));
53 result->SetInteger("totalSizeKB", disk->total_size() / 1024); 53 result->SetInteger("totalSizeKB", disk->total_size() / 1024);
54 result->SetBoolean("readOnly", disk->is_read_only()); 54 result->SetBoolean("readOnly", disk->is_read_only());
55 return result; 55 return result;
56 } 56 }
57 57
58 const char* MountErrorToString(chromeos::MountError error) {
59 switch (error) {
60 case chromeos::MOUNT_ERROR_NONE:
61 return "success";
62 case chromeos::MOUNT_ERROR_UNKNOWN:
63 return "unknown";
zel 2011/07/22 22:09:38 prefix error events with error_*
tbarzic 2011/07/22 22:15:14 Done.
64 case chromeos::MOUNT_ERROR_INTERNAL:
65 return "internal";
66 case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM:
67 return "unknown_filesystem";
68 case chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM:
69 return "unsuported_filesystem";
70 case chromeos::MOUNT_ERROR_INVALID_ARCHIVE:
71 return "invalid_archive";
72 case chromeos::MOUNT_ERROR_LIBRARY_NOT_LOADED:
73 return "libcros_missing";
74 default:
75 NOTREACHED();
76 }
77 return "";
78 }
79
58 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter() 80 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter()
59 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate()), 81 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate()),
60 profile_(NULL) { 82 profile_(NULL) {
61 } 83 }
62 84
63 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { 85 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() {
64 DCHECK(file_watchers_.empty()); 86 DCHECK(file_watchers_.empty());
65 STLDeleteValues(&file_watchers_); 87 STLDeleteValues(&file_watchers_);
66 88
67 if (!profile_) 89 if (!profile_)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 const std::string& device_path) { 183 const std::string& device_path) {
162 if (event == chromeos::MOUNT_DEVICE_ADDED) { 184 if (event == chromeos::MOUNT_DEVICE_ADDED) {
163 OnDeviceAdded(device_path); 185 OnDeviceAdded(device_path);
164 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) { 186 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) {
165 OnDeviceRemoved(device_path); 187 OnDeviceRemoved(device_path);
166 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) { 188 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) {
167 OnDeviceScanned(device_path); 189 OnDeviceScanned(device_path);
168 } 190 }
169 } 191 }
170 192
193 void ExtensionFileBrowserEventRouter::MountCompleted(
194 chromeos::MountLibrary::MountEvent event_type,
195 chromeos::MountError error_code,
196 const std::string& source_path,
197 chromeos::MountType type,
198 const std::string& mount_path) {
199 DispatchMountCompletedEvent(event_type, error_code, source_path, type,
200 mount_path);
201 }
202
171 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification( 203 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification(
172 const FilePath& local_path, bool got_error) { 204 const FilePath& local_path, bool got_error) {
173 base::AutoLock lock(lock_); 205 base::AutoLock lock(lock_);
174 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 206 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
175 if (iter == file_watchers_.end()) { 207 if (iter == file_watchers_.end()) {
176 NOTREACHED(); 208 NOTREACHED();
177 return; 209 return;
178 } 210 }
179 DispatchFolderChangeEvent(iter->second->virtual_path, got_error, 211 DispatchFolderChangeEvent(iter->second->virtual_path, got_error,
180 iter->second->extensions); 212 iter->second->extensions);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 DictionaryValue* disk_info = DiskToDictionaryValue(disk); 258 DictionaryValue* disk_info = DiskToDictionaryValue(disk);
227 mount_info->Set("volumeInfo", disk_info); 259 mount_info->Set("volumeInfo", disk_info);
228 260
229 std::string args_json; 261 std::string args_json;
230 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 262 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
231 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( 263 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
232 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL, 264 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL,
233 GURL()); 265 GURL());
234 } 266 }
235 267
268 void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent(
269 chromeos::MountLibrary::MountEvent event,
270 chromeos::MountError error_code, const std::string& source_path,
271 chromeos::MountType type, const std::string& mount_path ) {
272 if (!profile_ || type == chromeos::MOUNT_TYPE_INVALID) {
273 NOTREACHED();
274 return;
275 }
276
277 ListValue args;
278 DictionaryValue* mount_info = new DictionaryValue();
279 args.Append(mount_info);
280 mount_info->SetString("sourcePath", source_path);
281 if (event == chromeos::MountLibrary::MOUNTING) {
282 mount_info->SetString("eventType", "mounting");
283 } else {
284 mount_info->SetString("eventType", "unmounting");
285 }
286 mount_info->SetString("status", MountErrorToString(error_code));
287 chromeos::MountLibrary* lib = chromeos::CrosLibrary::Get()->GetMountLibrary();
288 mount_info->SetString("mountType", lib->MountTypeToString(type));
289 mount_info->SetString("mountPath", mount_path);
290
291 std::string args_json;
292 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
293 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
294 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL,
295 GURL());
296 }
297
236 void ExtensionFileBrowserEventRouter::OnDiskAdded( 298 void ExtensionFileBrowserEventRouter::OnDiskAdded(
237 const chromeos::MountLibrary::Disk* disk) { 299 const chromeos::MountLibrary::Disk* disk) {
238 VLOG(1) << "Disk added: " << disk->device_path(); 300 VLOG(1) << "Disk added: " << disk->device_path();
239 if (disk->device_path().empty()) { 301 if (disk->device_path().empty()) {
240 VLOG(1) << "Empty system path for " << disk->device_path(); 302 VLOG(1) << "Empty system path for " << disk->device_path();
241 return; 303 return;
242 } 304 }
243 if (disk->is_parent()) { 305 if (disk->is_parent()) {
244 if (!disk->has_media()) { 306 if (!disk->has_media()) {
245 HideDeviceNotification(disk->system_path()); 307 HideDeviceNotification(disk->system_path());
246 return; 308 return;
247 } 309 }
248 } 310 }
249 311
250 // If disk is not mounted yet, give it a try. 312 // If disk is not mounted yet, give it a try.
251 if (disk->mount_path().empty()) { 313 if (disk->mount_path().empty()) {
252 // Initiate disk mount operation. 314 // Initiate disk mount operation.
253 chromeos::MountLibrary* lib = 315 chromeos::MountLibrary* lib =
254 chromeos::CrosLibrary::Get()->GetMountLibrary(); 316 chromeos::CrosLibrary::Get()->GetMountLibrary();
255 lib->MountPath(disk->device_path().c_str()); 317 lib->MountPath(disk->device_path().c_str(),
318 chromeos::MOUNT_TYPE_DEVICE,
319 chromeos::MountPathOptions()); // Unused.
256 } 320 }
257 } 321 }
258 322
259 void ExtensionFileBrowserEventRouter::OnDiskRemoved( 323 void ExtensionFileBrowserEventRouter::OnDiskRemoved(
260 const chromeos::MountLibrary::Disk* disk) { 324 const chromeos::MountLibrary::Disk* disk) {
261 VLOG(1) << "Disk removed: " << disk->device_path(); 325 VLOG(1) << "Disk removed: " << disk->device_path();
262 HideDeviceNotification(disk->system_path()); 326 HideDeviceNotification(disk->system_path());
263 MountPointMap::iterator iter = mounted_devices_.find(disk->device_path()); 327 MountPointMap::iterator iter = mounted_devices_.find(disk->device_path());
264 if (iter == mounted_devices_.end()) 328 if (iter == mounted_devices_.end())
265 return; 329 return;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 local_path, 447 local_path,
384 true)); // got_error 448 true)); // got_error
385 } 449 }
386 450
387 void 451 void
388 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( 452 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread(
389 const FilePath& local_path, bool got_error) { 453 const FilePath& local_path, bool got_error) {
390 ExtensionFileBrowserEventRouter::GetInstance()->HandleFileWatchNotification( 454 ExtensionFileBrowserEventRouter::GetInstance()->HandleFileWatchNotification(
391 local_path, got_error); 455 local_path, got_error);
392 } 456 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698