OLD | NEW |
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/bind.h" |
7 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/memory/singleton.h" |
| 10 #include "base/message_loop.h" |
8 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
9 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 13 #include "base/values.h" |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
12 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
13 #include "chrome/browser/chromeos/notifications/system_notification.h" | 16 #include "chrome/browser/chromeos/notifications/system_notification.h" |
14 #include "chrome/browser/extensions/extension_event_names.h" | 17 #include "chrome/browser/extensions/extension_event_names.h" |
15 #include "chrome/browser/extensions/extension_event_router.h" | 18 #include "chrome/browser/extensions/extension_event_router.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/file_manager_util.h" | 20 #include "chrome/browser/extensions/file_manager_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
19 #include "content/browser/browser_thread.h" | 22 #include "content/browser/browser_thread.h" |
20 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
21 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
23 #include "webkit/fileapi/file_system_types.h" | 26 #include "webkit/fileapi/file_system_types.h" |
24 #include "webkit/fileapi/file_system_util.h" | 27 #include "webkit/fileapi/file_system_util.h" |
25 | 28 |
26 const char kDiskAddedEventType[] = "added"; | 29 namespace { |
27 const char kDiskRemovedEventType[] = "removed"; | 30 const char kDiskAddedEventType[] = "added"; |
| 31 const char kDiskRemovedEventType[] = "removed"; |
28 | 32 |
29 const char kPathChanged[] = "changed"; | 33 const char kPathChanged[] = "changed"; |
30 const char kPathWatchError[] = "error"; | 34 const char kPathWatchError[] = "error"; |
31 | 35 |
32 const char* DeviceTypeToString(chromeos::DeviceType type) { | 36 const char* DeviceTypeToString(chromeos::DeviceType type) { |
33 switch (type) { | 37 switch (type) { |
34 case chromeos::FLASH: | 38 case chromeos::FLASH: |
35 return "flash"; | 39 return "flash"; |
36 case chromeos::HDD: | 40 case chromeos::HDD: |
37 return "hdd"; | 41 return "hdd"; |
38 case chromeos::OPTICAL: | 42 case chromeos::OPTICAL: |
39 return "optical"; | 43 return "optical"; |
40 default: | 44 default: |
41 break; | 45 break; |
| 46 } |
| 47 return "undefined"; |
42 } | 48 } |
43 return "undefined"; | 49 |
| 50 DictionaryValue* DiskToDictionaryValue( |
| 51 const chromeos::MountLibrary::Disk* disk) { |
| 52 DictionaryValue* result = new DictionaryValue(); |
| 53 result->SetString("mountPath", disk->mount_path()); |
| 54 result->SetString("devicePath", disk->device_path()); |
| 55 result->SetString("label", disk->device_label()); |
| 56 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); |
| 57 result->SetInteger("totalSizeKB", disk->total_size() / 1024); |
| 58 result->SetBoolean("readOnly", disk->is_read_only()); |
| 59 return result; |
| 60 } |
44 } | 61 } |
45 | 62 |
46 const char* MountErrorToString(chromeos::MountError error) { | 63 const char* MountErrorToString(chromeos::MountError error) { |
47 switch (error) { | 64 switch (error) { |
48 case chromeos::MOUNT_ERROR_NONE: | 65 case chromeos::MOUNT_ERROR_NONE: |
49 return "success"; | 66 return "success"; |
50 case chromeos::MOUNT_ERROR_UNKNOWN: | 67 case chromeos::MOUNT_ERROR_UNKNOWN: |
51 return "error_unknown"; | 68 return "error_unknown"; |
52 case chromeos::MOUNT_ERROR_INTERNAL: | 69 case chromeos::MOUNT_ERROR_INTERNAL: |
53 return "error_internal"; | 70 return "error_internal"; |
54 case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM: | 71 case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM: |
55 return "error_unknown_filesystem"; | 72 return "error_unknown_filesystem"; |
56 case chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM: | 73 case chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM: |
57 return "error_unsuported_filesystem"; | 74 return "error_unsuported_filesystem"; |
58 case chromeos::MOUNT_ERROR_INVALID_ARCHIVE: | 75 case chromeos::MOUNT_ERROR_INVALID_ARCHIVE: |
59 return "error_invalid_archive"; | 76 return "error_invalid_archive"; |
60 case chromeos::MOUNT_ERROR_LIBRARY_NOT_LOADED: | 77 case chromeos::MOUNT_ERROR_LIBRARY_NOT_LOADED: |
61 return "error_libcros_missing"; | 78 return "error_libcros_missing"; |
62 default: | 79 default: |
63 NOTREACHED(); | 80 NOTREACHED(); |
64 } | 81 } |
65 return ""; | 82 return ""; |
66 } | 83 } |
67 | 84 |
68 DictionaryValue* DiskToDictionaryValue( | 85 void HideFileBrowserNotificationExternally(const std::string& category, |
69 const chromeos::MountLibrary::Disk* disk) { | 86 const std::string& system_path, ExtensionFileBrowserEventRouter* that) { |
70 DictionaryValue* result = new DictionaryValue(); | 87 that->HideFileBrowserNotification(category, system_path); |
71 result->SetString("mountPath", disk->mount_path()); | |
72 result->SetString("devicePath", disk->device_path()); | |
73 result->SetString("label", disk->device_label()); | |
74 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); | |
75 result->SetInteger("totalSizeKB", disk->total_size() / 1024); | |
76 result->SetBoolean("readOnly", disk->is_read_only()); | |
77 return result; | |
78 } | 88 } |
79 | 89 |
80 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter( | 90 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter( |
81 Profile* profile) | 91 Profile* profile) |
82 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate(this)), | 92 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate(this)), |
83 profile_(profile) { | 93 profile_(profile) { |
84 } | 94 } |
85 | 95 |
86 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { | 96 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { |
87 DCHECK(file_watchers_.empty()); | 97 DCHECK(file_watchers_.empty()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 174 |
165 void ExtensionFileBrowserEventRouter::DeviceChanged( | 175 void ExtensionFileBrowserEventRouter::DeviceChanged( |
166 chromeos::MountLibraryEventType event, | 176 chromeos::MountLibraryEventType event, |
167 const std::string& device_path) { | 177 const std::string& device_path) { |
168 if (event == chromeos::MOUNT_DEVICE_ADDED) { | 178 if (event == chromeos::MOUNT_DEVICE_ADDED) { |
169 OnDeviceAdded(device_path); | 179 OnDeviceAdded(device_path); |
170 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) { | 180 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) { |
171 OnDeviceRemoved(device_path); | 181 OnDeviceRemoved(device_path); |
172 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) { | 182 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) { |
173 OnDeviceScanned(device_path); | 183 OnDeviceScanned(device_path); |
| 184 } else if (event == chromeos::MOUNT_FORMATTING_STARTED) { |
| 185 OnFormattingStarted(device_path); |
| 186 } else if (event == chromeos::MOUNT_FORMATTING_FINISHED) { |
| 187 OnFormattingFinished(device_path); |
174 } | 188 } |
175 } | 189 } |
176 void ExtensionFileBrowserEventRouter::MountCompleted( | 190 void ExtensionFileBrowserEventRouter::MountCompleted( |
177 chromeos::MountLibrary::MountEvent event_type, | 191 chromeos::MountLibrary::MountEvent event_type, |
178 chromeos::MountError error_code, | 192 chromeos::MountError error_code, |
179 const chromeos::MountLibrary::MountPointInfo& mount_info) { | 193 const chromeos::MountLibrary::MountPointInfo& mount_info) { |
180 if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 194 if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
181 event_type == chromeos::MountLibrary::MOUNTING) { | 195 event_type == chromeos::MountLibrary::MOUNTING) { |
182 chromeos::MountLibrary* mount_lib = | 196 chromeos::MountLibrary* mount_lib = |
183 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 197 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 198 if (mount_lib->disks().find(mount_info.source_path) == |
| 199 mount_lib->disks().end()) { |
| 200 return; |
| 201 } |
184 chromeos::MountLibrary::Disk* disk = | 202 chromeos::MountLibrary::Disk* disk = |
185 mount_lib->disks().find(mount_info.source_path)->second; | 203 mount_lib->disks().find(mount_info.source_path)->second; |
186 | 204 |
187 if (!error_code) { | 205 if (!error_code) { |
188 HideDeviceNotification(disk->system_path()); | 206 HideFileBrowserNotification("MOUNT", disk->system_path()); |
189 } else { | 207 } else { |
190 HideDeviceNotification(disk->system_path()); | 208 HideFileBrowserNotification("MOUNT", disk->system_path()); |
191 if (!disk->drive_label().empty()) { | 209 if (!disk->drive_label().empty()) { |
192 ShowDeviceNotification(disk->system_path(), | 210 ShowFileBrowserNotification("MOUNT", disk->system_path(), |
193 IDR_PAGEINFO_INFO, | 211 IDR_PAGEINFO_INFO, |
| 212 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_DETECTION_TITLE), |
194 // TODO(tbarzic): Find more suitable message. | 213 // TODO(tbarzic): Find more suitable message. |
195 l10n_util::GetStringFUTF16( | 214 l10n_util::GetStringFUTF16( |
196 IDS_FILE_BROWSER_ARCHIVE_MOUNT_FAILED, | 215 IDS_FILE_BROWSER_ARCHIVE_MOUNT_FAILED, |
197 ASCIIToUTF16(disk->drive_label()), | 216 ASCIIToUTF16(disk->drive_label()), |
198 ASCIIToUTF16(MountErrorToString(error_code)))); | 217 ASCIIToUTF16(MountErrorToString(error_code)))); |
199 } else { | 218 } else { |
200 ShowDeviceNotification(disk->system_path(), | 219 ShowFileBrowserNotification("MOUNT", disk->system_path(), |
201 IDR_PAGEINFO_INFO, | 220 IDR_PAGEINFO_INFO, |
| 221 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_DETECTION_TITLE), |
202 // TODO(tbarzic): Find more suitable message. | 222 // TODO(tbarzic): Find more suitable message. |
203 l10n_util::GetStringFUTF16( | 223 l10n_util::GetStringFUTF16( |
204 IDS_FILE_BROWSER_ARCHIVE_MOUNT_FAILED, | 224 IDS_FILE_BROWSER_ARCHIVE_MOUNT_FAILED, |
205 l10n_util::GetStringUTF16( | 225 l10n_util::GetStringUTF16( |
206 IDS_FILE_BROWSER_DEVICE_TYPE_UNDEFINED), | 226 IDS_FILE_BROWSER_DEVICE_TYPE_UNDEFINED), |
207 ASCIIToUTF16(MountErrorToString(error_code)))); | 227 ASCIIToUTF16(MountErrorToString(error_code)))); |
208 } | 228 } |
209 } | 229 } |
210 } | 230 } |
211 | 231 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 347 |
328 std::string args_json; | 348 std::string args_json; |
329 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 349 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
330 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 350 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
331 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, | 351 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
332 GURL()); | 352 GURL()); |
333 | 353 |
334 if (relative_mount_path_set && | 354 if (relative_mount_path_set && |
335 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 355 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
336 event == chromeos::MountLibrary::MOUNTING) { | 356 event == chromeos::MountLibrary::MOUNTING) { |
337 FileManagerUtil::ShowFullTabUrl(profile_, relative_mount_path); | 357 FileManagerUtil::ShowFullTabUrl(profile_, FilePath(mount_info.mount_path)); |
338 } | 358 } |
339 } | 359 } |
340 | 360 |
341 void ExtensionFileBrowserEventRouter::OnDiskAdded( | 361 void ExtensionFileBrowserEventRouter::OnDiskAdded( |
342 const chromeos::MountLibrary::Disk* disk) { | 362 const chromeos::MountLibrary::Disk* disk) { |
343 VLOG(1) << "Disk added: " << disk->device_path(); | 363 VLOG(1) << "Disk added: " << disk->device_path(); |
344 if (disk->device_path().empty()) { | 364 if (disk->device_path().empty()) { |
345 VLOG(1) << "Empty system path for " << disk->device_path(); | 365 VLOG(1) << "Empty system path for " << disk->device_path(); |
346 return; | 366 return; |
347 } | 367 } |
348 | 368 |
349 // If disk is not mounted yet, give it a try. | 369 // If disk is not mounted yet, give it a try. |
350 if (disk->mount_path().empty()) { | 370 if (disk->mount_path().empty()) { |
351 // Initiate disk mount operation. | 371 // Initiate disk mount operation. |
352 chromeos::MountLibrary* lib = | 372 chromeos::MountLibrary* lib = |
353 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 373 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
354 lib->MountPath(disk->device_path().c_str(), | 374 lib->MountPath(disk->device_path().c_str(), |
355 chromeos::MOUNT_TYPE_DEVICE, | 375 chromeos::MOUNT_TYPE_DEVICE, |
356 chromeos::MountPathOptions()); // Unused. | 376 chromeos::MountPathOptions()); // Unused. |
357 } | 377 } |
358 DispatchDiskEvent(disk, true); | 378 DispatchDiskEvent(disk, true); |
359 } | 379 } |
360 | 380 |
361 void ExtensionFileBrowserEventRouter::OnDiskRemoved( | 381 void ExtensionFileBrowserEventRouter::OnDiskRemoved( |
362 const chromeos::MountLibrary::Disk* disk) { | 382 const chromeos::MountLibrary::Disk* disk) { |
363 VLOG(1) << "Disk removed: " << disk->device_path(); | 383 VLOG(1) << "Disk removed: " << disk->device_path(); |
364 HideDeviceNotification(disk->system_path()); | 384 HideFileBrowserNotification("MOUNT", disk->system_path()); |
365 | 385 |
366 if (!disk->mount_path().empty()) { | 386 if (!disk->mount_path().empty()) { |
367 chromeos::MountLibrary* lib = | 387 chromeos::MountLibrary* lib = |
368 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 388 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
369 lib->UnmountPath(disk->mount_path().c_str()); | 389 lib->UnmountPath(disk->mount_path().c_str()); |
370 } | 390 } |
371 DispatchDiskEvent(disk, false); | 391 DispatchDiskEvent(disk, false); |
372 } | 392 } |
373 | 393 |
374 void ExtensionFileBrowserEventRouter::OnDeviceAdded( | 394 void ExtensionFileBrowserEventRouter::OnDeviceAdded( |
375 const std::string& device_path) { | 395 const std::string& device_path) { |
376 VLOG(1) << "Device added : " << device_path; | 396 VLOG(1) << "Device added : " << device_path; |
377 // TODO(zelidrag): Find better icon here. | 397 // TODO(zelidrag): Find better icon here. |
378 ShowDeviceNotification(device_path, IDR_PAGEINFO_INFO, | 398 ShowFileBrowserNotification("MOUNT", device_path, IDR_PAGEINFO_INFO, |
| 399 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_DETECTION_TITLE), |
379 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE)); | 400 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE)); |
380 | |
381 } | 401 } |
382 | 402 |
383 void ExtensionFileBrowserEventRouter::OnDeviceRemoved( | 403 void ExtensionFileBrowserEventRouter::OnDeviceRemoved( |
384 const std::string& system_path) { | 404 const std::string& system_path) { |
385 HideDeviceNotification(system_path); | 405 HideFileBrowserNotification("MOUNT", system_path); |
386 } | 406 } |
387 | 407 |
388 void ExtensionFileBrowserEventRouter::OnDeviceScanned( | 408 void ExtensionFileBrowserEventRouter::OnDeviceScanned( |
389 const std::string& device_path) { | 409 const std::string& device_path) { |
390 VLOG(1) << "Device scanned : " << device_path; | 410 VLOG(1) << "Device scanned : " << device_path; |
391 } | 411 } |
392 | 412 |
393 void ExtensionFileBrowserEventRouter::ShowDeviceNotification( | 413 void ExtensionFileBrowserEventRouter::OnFormattingStarted( |
394 const std::string& system_path, int icon_resource_id, | 414 const std::string& device_path) { |
395 const string16& message) { | 415 if (device_path[0] == '!') { |
396 NotificationMap::iterator iter = FindNotificationForPath(system_path); | 416 ShowFileBrowserNotification("FORMAT_FINISHED", device_path.substr(1), |
397 std::string mount_path; | 417 IDR_PAGEINFO_WARNING_MAJOR, |
398 if (iter != notifications_.end()) { | 418 l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE), |
399 iter->second->Show(message, false, false); | 419 l10n_util::GetStringUTF16(IDS_FORMATTING_STARTED_FAILURE_MESSAGE)); |
400 } else { | 420 } else { |
401 if (!profile_) { | 421 ShowFileBrowserNotification("FORMAT", device_path, IDR_PAGEINFO_INFO, |
402 NOTREACHED(); | 422 l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_PENDING_TITLE), |
403 return; | 423 l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_PENDING_MESSAGE)); |
404 } | |
405 chromeos::SystemNotification* notification = | |
406 new chromeos::SystemNotification( | |
407 profile_, | |
408 system_path, | |
409 icon_resource_id, | |
410 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_DETECTION_TITLE)); | |
411 notifications_.insert(NotificationMap::value_type(system_path, | |
412 linked_ptr<chromeos::SystemNotification>(notification))); | |
413 notification->Show(message, false, false); | |
414 } | 424 } |
415 } | 425 } |
416 | 426 |
417 void ExtensionFileBrowserEventRouter::HideDeviceNotification( | 427 void ExtensionFileBrowserEventRouter::OnFormattingFinished( |
418 const std::string& system_path) { | 428 const std::string& device_path) { |
419 NotificationMap::iterator iter = FindNotificationForPath(system_path); | 429 if (device_path[0] == '!') { |
| 430 HideFileBrowserNotification("FORMAT", device_path.substr(1)); |
| 431 ShowFileBrowserNotification("FORMAT_FINISHED", device_path.substr(1), |
| 432 IDR_PAGEINFO_WARNING_MAJOR, |
| 433 l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE), |
| 434 l10n_util::GetStringUTF16(IDS_FORMATTING_FINISHED_FAILURE_MESSAGE)); |
| 435 } else { |
| 436 HideFileBrowserNotification("FORMAT", device_path); |
| 437 ShowFileBrowserNotification("FORMAT_FINISHED", device_path, |
| 438 IDR_PAGEINFO_INFO, |
| 439 l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE), |
| 440 l10n_util::GetStringUTF16(IDS_FORMATTING_FINISHED_SUCCESS_MESSAGE)); |
| 441 // Hide it after a couple of seconds |
| 442 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 443 base::Bind(&HideFileBrowserNotificationExternally, "FORMAT_FINISHED", |
| 444 device_path, this), |
| 445 4000); |
| 446 |
| 447 chromeos::MountLibrary* lib = |
| 448 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 449 lib->MountPath(device_path.c_str(), |
| 450 chromeos::MOUNT_TYPE_DEVICE, |
| 451 chromeos::MountPathOptions()); // Unused. |
| 452 } |
| 453 } |
| 454 |
| 455 void ExtensionFileBrowserEventRouter::ShowFileBrowserNotification( |
| 456 const std::string& category, const std::string& system_path, |
| 457 int icon_resource_id, const string16& title, const string16& message) { |
| 458 std::string notification_id = category + system_path; |
| 459 // New notification always created because, it might have been closed by now. |
| 460 NotificationMap::iterator iter = FindNotificationForId(notification_id); |
| 461 if (iter != notifications_.end()) |
| 462 notifications_.erase(iter); |
| 463 if (!profile_) { |
| 464 NOTREACHED(); |
| 465 return; |
| 466 } |
| 467 chromeos::SystemNotification* notification = |
| 468 new chromeos::SystemNotification( |
| 469 profile_, |
| 470 notification_id, |
| 471 icon_resource_id, |
| 472 title); |
| 473 notifications_.insert(NotificationMap::value_type(notification_id, |
| 474 linked_ptr<chromeos::SystemNotification>(notification))); |
| 475 notification->Show(message, false, false); |
| 476 } |
| 477 |
| 478 void ExtensionFileBrowserEventRouter::HideFileBrowserNotification( |
| 479 const std::string& category, const std::string& system_path) { |
| 480 NotificationMap::iterator iter = FindNotificationForId( |
| 481 category + system_path); |
420 if (iter != notifications_.end()) { | 482 if (iter != notifications_.end()) { |
421 iter->second->Hide(); | 483 iter->second->Hide(); |
422 notifications_.erase(iter); | 484 notifications_.erase(iter); |
423 } | 485 } |
424 } | 486 } |
425 | 487 |
426 ExtensionFileBrowserEventRouter::NotificationMap::iterator | 488 ExtensionFileBrowserEventRouter::NotificationMap::iterator |
427 ExtensionFileBrowserEventRouter::FindNotificationForPath( | 489 ExtensionFileBrowserEventRouter::FindNotificationForId( |
428 const std::string& system_path) { | 490 const std::string& notification_id) { |
429 for (NotificationMap::iterator iter = notifications_.begin(); | 491 for (NotificationMap::iterator iter = notifications_.begin(); |
430 iter != notifications_.end(); | 492 iter != notifications_.end(); |
431 ++iter) { | 493 ++iter) { |
432 const std::string& notification_device_path = iter->first; | 494 const std::string& notification_device_path = iter->first; |
433 // Doing a sub string match so that we find if this new one is a subdevice | 495 // Doing a sub string match so that we find if this new one is a subdevice |
434 // of another already inserted device. | 496 // of another already inserted device. |
435 if (StartsWithASCII(system_path, notification_device_path, true)) { | 497 if (StartsWithASCII(notification_id, notification_device_path, true)) { |
436 return iter; | 498 return iter; |
437 } | 499 } |
438 } | 500 } |
439 return notifications_.end(); | 501 return notifications_.end(); |
440 } | 502 } |
441 | 503 |
442 // ExtensionFileBrowserEventRouter::WatcherDelegate methods. | 504 // ExtensionFileBrowserEventRouter::WatcherDelegate methods. |
443 ExtensionFileBrowserEventRouter::FileWatcherDelegate::FileWatcherDelegate( | 505 ExtensionFileBrowserEventRouter::FileWatcherDelegate::FileWatcherDelegate( |
444 ExtensionFileBrowserEventRouter* router) : router_(router) { | 506 ExtensionFileBrowserEventRouter* router) : router_(router) { |
445 } | 507 } |
(...skipping 16 matching lines...) Expand all Loading... |
462 &FileWatcherDelegate::HandleFileWatchOnUIThread, | 524 &FileWatcherDelegate::HandleFileWatchOnUIThread, |
463 local_path, | 525 local_path, |
464 true)); // got_error | 526 true)); // got_error |
465 } | 527 } |
466 | 528 |
467 void | 529 void |
468 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( | 530 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( |
469 const FilePath& local_path, bool got_error) { | 531 const FilePath& local_path, bool got_error) { |
470 router_->HandleFileWatchNotification(local_path, got_error); | 532 router_->HandleFileWatchNotification(local_path, got_error); |
471 } | 533 } |
OLD | NEW |