| 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 } |
| 448 |
| 449 void ExtensionFileBrowserEventRouter::ShowFileBrowserNotification( |
| 450 const std::string& category, const std::string& system_path, |
| 451 int icon_resource_id, const string16& title, const string16& message) { |
| 452 std::string notification_id = category + system_path; |
| 453 // New notification always created because, it might have been closed by now. |
| 454 NotificationMap::iterator iter = FindNotificationForId(notification_id); |
| 455 if (iter != notifications_.end()) |
| 456 notifications_.erase(iter); |
| 457 if (!profile_) { |
| 458 NOTREACHED(); |
| 459 return; |
| 460 } |
| 461 chromeos::SystemNotification* notification = |
| 462 new chromeos::SystemNotification( |
| 463 profile_, |
| 464 notification_id, |
| 465 icon_resource_id, |
| 466 title); |
| 467 notifications_.insert(NotificationMap::value_type(notification_id, |
| 468 linked_ptr<chromeos::SystemNotification>(notification))); |
| 469 notification->Show(message, false, false); |
| 470 } |
| 471 |
| 472 void ExtensionFileBrowserEventRouter::HideFileBrowserNotification( |
| 473 const std::string& category, const std::string& system_path) { |
| 474 NotificationMap::iterator iter = FindNotificationForId( |
| 475 category + system_path); |
| 420 if (iter != notifications_.end()) { | 476 if (iter != notifications_.end()) { |
| 421 iter->second->Hide(); | 477 iter->second->Hide(); |
| 422 notifications_.erase(iter); | 478 notifications_.erase(iter); |
| 423 } | 479 } |
| 424 } | 480 } |
| 425 | 481 |
| 426 ExtensionFileBrowserEventRouter::NotificationMap::iterator | 482 ExtensionFileBrowserEventRouter::NotificationMap::iterator |
| 427 ExtensionFileBrowserEventRouter::FindNotificationForPath( | 483 ExtensionFileBrowserEventRouter::FindNotificationForId( |
| 428 const std::string& system_path) { | 484 const std::string& notification_id) { |
| 429 for (NotificationMap::iterator iter = notifications_.begin(); | 485 for (NotificationMap::iterator iter = notifications_.begin(); |
| 430 iter != notifications_.end(); | 486 iter != notifications_.end(); |
| 431 ++iter) { | 487 ++iter) { |
| 432 const std::string& notification_device_path = iter->first; | 488 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 | 489 // Doing a sub string match so that we find if this new one is a subdevice |
| 434 // of another already inserted device. | 490 // of another already inserted device. |
| 435 if (StartsWithASCII(system_path, notification_device_path, true)) { | 491 if (StartsWithASCII(notification_id, notification_device_path, true)) { |
| 436 return iter; | 492 return iter; |
| 437 } | 493 } |
| 438 } | 494 } |
| 439 return notifications_.end(); | 495 return notifications_.end(); |
| 440 } | 496 } |
| 441 | 497 |
| 442 // ExtensionFileBrowserEventRouter::WatcherDelegate methods. | 498 // ExtensionFileBrowserEventRouter::WatcherDelegate methods. |
| 443 ExtensionFileBrowserEventRouter::FileWatcherDelegate::FileWatcherDelegate( | 499 ExtensionFileBrowserEventRouter::FileWatcherDelegate::FileWatcherDelegate( |
| 444 ExtensionFileBrowserEventRouter* router) : router_(router) { | 500 ExtensionFileBrowserEventRouter* router) : router_(router) { |
| 445 } | 501 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 462 &FileWatcherDelegate::HandleFileWatchOnUIThread, | 518 &FileWatcherDelegate::HandleFileWatchOnUIThread, |
| 463 local_path, | 519 local_path, |
| 464 true)); // got_error | 520 true)); // got_error |
| 465 } | 521 } |
| 466 | 522 |
| 467 void | 523 void |
| 468 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( | 524 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( |
| 469 const FilePath& local_path, bool got_error) { | 525 const FilePath& local_path, bool got_error) { |
| 470 router_->HandleFileWatchNotification(local_path, got_error); | 526 router_->HandleFileWatchNotification(local_path, got_error); |
| 471 } | 527 } |
| OLD | NEW |