diff options
author | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-22 22:43:54 +0000 |
---|---|---|
committer | zelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-22 22:43:54 +0000 |
commit | 1b5fe10d0fa46872e0c8ac6227cccee7ded5890f (patch) | |
tree | ee141972f995383e68770db6e5856e25f86c5034 /chrome | |
parent | 0b4dcee8e836f808026ea043a1b21abd1eeb5073 (diff) | |
download | chromium_src-1b5fe10d0fa46872e0c8ac6227cccee7ded5890f.zip chromium_src-1b5fe10d0fa46872e0c8ac6227cccee7ded5890f.tar.gz chromium_src-1b5fe10d0fa46872e0c8ac6227cccee7ded5890f.tar.bz2 |
Added extra data to chrome.fileBrowserPrivate.onDiskChanged even payload that will give us more data about the volume and really tell us what operation happened here.
BUG=chromium-os:14368
TEST=none
Review URL: http://codereview.chromium.org/6879105
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
4 files changed, 91 insertions, 10 deletions
diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc index 103e780..3ac86c3 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc @@ -19,6 +19,34 @@ #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" +const char kDiskAddedEventType[] = "added"; +const char kDiskRemovedEventType[] = "removed"; + +const char* DeviceTypeToString(chromeos::DeviceType type) { + switch (type) { + case chromeos::FLASH: + return "flash"; + case chromeos::HDD: + return "hdd"; + case chromeos::OPTICAL: + return "optical"; + default: + break; + } + return "undefined"; +} + +DictionaryValue* DiskToDictionaryValue( + const chromeos::MountLibrary::Disk* disk) { + DictionaryValue* result = new DictionaryValue(); + result->SetString("mountPath", disk->mount_path()); + result->SetString("label", disk->device_label()); + result->SetString("deviceType", DeviceTypeToString(disk->device_type())); + result->SetInteger("totalSizeKB", disk->total_size() / 1024); + result->SetBoolean("readOnly", disk->is_read_only()); + return result; +} + ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter() : profile_(NULL) { } @@ -28,7 +56,7 @@ ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { void ExtensionFileBrowserEventRouter::ObserveFileSystemEvents( Profile* profile) { - if (profile_) + if (!profile) return; profile_ = profile; if (chromeos::UserManager::Get()->user_is_logged_in()) { @@ -79,14 +107,20 @@ void ExtensionFileBrowserEventRouter::DeviceChanged( } void ExtensionFileBrowserEventRouter::DispatchEvent( - const std::string& web_path) { + const chromeos::MountLibrary::Disk* disk, bool added) { if (!profile_) { NOTREACHED(); return; } ListValue args; - args.Append(Value::CreateStringValue(web_path)); + DictionaryValue* mount_info = new DictionaryValue(); + args.Append(mount_info); + mount_info->SetString("eventType", + added ? kDiskAddedEventType : kDiskRemovedEventType); + DictionaryValue* disk_info = DiskToDictionaryValue(disk); + mount_info->Set("diskInfo", disk_info); + std::string args_json; base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); profile_->GetExtensionEventRouter()->DispatchEventToRenderers( @@ -130,7 +164,7 @@ void ExtensionFileBrowserEventRouter::OnDiskRemoved( // we might need to clean up mount directory on FILE thread here as well. lib->UnmountPath(disk->device_path().c_str()); - DispatchEvent(iter->second); + DispatchEvent(disk, false); mounted_devices_.erase(iter); } @@ -144,7 +178,7 @@ void ExtensionFileBrowserEventRouter::OnDiskChanged( mounted_devices_.insert( std::pair<std::string, std::string>(disk->device_path(), disk->mount_path())); - DispatchEvent(disk->mount_path()); + DispatchEvent(disk, true); HideDeviceNotification(disk->system_path()); FileManagerUtil::ShowFullTabUrl(profile_, FilePath(disk->mount_path())); } diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.h b/chrome/browser/chromeos/extensions/file_browser_event_router.h index a7b5599..320a80d 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.h +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.h @@ -59,7 +59,7 @@ class ExtensionFileBrowserEventRouter NotificationMap::iterator FindNotificationForPath(const std::string& path); // Sends filesystem changed extension message to all renderers. - void DispatchEvent(const std::string& web_path); + void DispatchEvent(const chromeos::MountLibrary::Disk* disk, bool added); void RemoveBrowserFromVector(const std::string& path); diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js index 1ac96ad..a2a7886 100644 --- a/chrome/browser/resources/file_manager/js/file_manager.js +++ b/chrome/browser/resources/file_manager/js/file_manager.js @@ -954,6 +954,8 @@ FileManager.prototype = { }; FileManager.prototype.onTasksFound_ = function(tasksList) { + console.log("FileManager.prototype.onTasksFound_"); + console.log(tasksList); this.taskButtons_.innerHTML = ''; for (var i = 0; i < tasksList.length; i++) { var task = tasksList[i]; @@ -1268,8 +1270,9 @@ FileManager.prototype = { * * @param {string} path The path that has been mounted or unmounted. */ - FileManager.prototype.onDiskChanged_ = function(path) { - this.changeDirectory(path); + FileManager.prototype.onDiskChanged_ = function(event) { + // TODO(rginda): Please check and wire handling of other data passed here. + this.changeDirectory(event.volumeInfo.mountPath); }; /** diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index edcaa18..85eac7b 100644 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -4691,6 +4691,50 @@ "title": {"type": "string", "description": "Task title."}, "iconUrl": {"type": "string", "description": "Task icon url (from chrome://extension-icon/...)"} } + }, + { + "id": "VolumeInfo", + "type": "object", + "description": "Mounted disk volume information.", + "properties": { + "mountPath": { + "type": "string", + "description": "Disk volume mount point path. The value corresponds to its Entry.fullPath in File API." + }, + "label": { + "type": "string", + "description": "Volume label." + }, + "deviceType": { + "type": "string", + "enum": ["flash", "hdd", "optical", "undefined"], + "description": "Device type." + }, + "readOnly": { + "type": "boolean", + "description": "Flag that specifies if volume is mounted in read-only mode." + }, + "totalSizeKB": { + "type": "integer", + "description": "Total disk volume size in KBs" + } + } + }, + { + "id": "MountEvent", + "type": "object", + "description": "Payload data for disk mount / unmount event.", + "properties": { + "eventType": { + "type": "string", + "enum": ["added", "removed"], + "description": "Event type that tells listeners which disk volume even was raised." + }, + "volumeInfo": { + "$ref": "VolumeInfo", + "description":"Volume information that this mount event applies to." + } + } } ], "functions": [ @@ -4839,9 +4883,9 @@ "description": "Fired when disk mount/unmount event is detected.", "parameters": [ { - "type": "string", + "$ref": "MountEvent", "name": "fullPath", - "description": "Path of the filesystem directory entry that changed." + "description": "Mount event information." } ] } |