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

Unified Diff: chrome/browser/chromeos/extensions/file_browser_event_router.cc

Issue 7599015: Revert 94812 - Formatting feature initial commit for ChromeOS Tree (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/file_browser_event_router.cc
===================================================================
--- chrome/browser/chromeos/extensions/file_browser_event_router.cc (revision 95908)
+++ chrome/browser/chromeos/extensions/file_browser_event_router.cc (working copy)
@@ -4,10 +4,7 @@
#include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
-#include "base/bind.h"
#include "base/json/json_writer.h"
-#include "base/memory/singleton.h"
-#include "base/message_loop.h"
#include "base/stl_util.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
@@ -25,38 +22,24 @@
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_util.h"
-namespace {
- const char kDiskAddedEventType[] = "added";
- const char kDiskRemovedEventType[] = "removed";
+const char kDiskAddedEventType[] = "added";
+const char kDiskRemovedEventType[] = "removed";
- const char kPathChanged[] = "changed";
- const char kPathWatchError[] = "error";
+const char kPathChanged[] = "changed";
+const char kPathWatchError[] = "error";
- 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";
+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;
}
-
- DictionaryValue* DiskToDictionaryValue(
- const chromeos::MountLibrary::Disk* disk) {
- DictionaryValue* result = new DictionaryValue();
- result->SetString("mountPath", disk->mount_path());
- result->SetString("devicePath", disk->device_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;
- }
+ return "undefined";
}
const char* MountErrorToString(chromeos::MountError error) {
@@ -81,9 +64,16 @@
return "";
}
-void HideFileBrowserNotificationExternally(const std::string& category,
- const std::string& system_path, ExtensionFileBrowserEventRouter* that) {
- that->HideFileBrowserNotification(category, system_path);
+DictionaryValue* DiskToDictionaryValue(
+ const chromeos::MountLibrary::Disk* disk) {
+ DictionaryValue* result = new DictionaryValue();
+ result->SetString("mountPath", disk->mount_path());
+ result->SetString("devicePath", disk->device_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(
@@ -182,10 +172,6 @@
OnDeviceRemoved(device_path);
} else if (event == chromeos::MOUNT_DEVICE_SCANNED) {
OnDeviceScanned(device_path);
- } else if (event == chromeos::MOUNT_FORMATTING_STARTED) {
- OnFormattingStarted(device_path);
- } else if (event == chromeos::MOUNT_FORMATTING_FINISHED) {
- OnFormattingFinished(device_path);
}
}
void ExtensionFileBrowserEventRouter::MountCompleted(
@@ -321,7 +307,7 @@
}
if (disk->is_parent()) {
if (!disk->has_media()) {
- HideFileBrowserNotification("MOUNT", disk->system_path());
+ HideDeviceNotification(disk->system_path());
return;
}
}
@@ -335,13 +321,12 @@
chromeos::MOUNT_TYPE_DEVICE,
chromeos::MountPathOptions()); // Unused.
}
- DispatchMountEvent(disk, true);
}
void ExtensionFileBrowserEventRouter::OnDiskRemoved(
const chromeos::MountLibrary::Disk* disk) {
VLOG(1) << "Disk removed: " << disk->device_path();
- HideFileBrowserNotification("MOUNT", disk->system_path());
+ HideDeviceNotification(disk->system_path());
MountPointMap::iterator iter = mounted_devices_.find(disk->device_path());
if (iter == mounted_devices_.end())
return;
@@ -351,6 +336,7 @@
// TODO(zelidrag): This for some reason does not work as advertized.
// we might need to clean up mount directory on FILE thread here as well.
lib->UnmountPath(disk->device_path().c_str());
+
DispatchMountEvent(disk, false);
mounted_devices_.erase(iter);
}
@@ -359,14 +345,14 @@
const chromeos::MountLibrary::Disk* disk) {
VLOG(1) << "Disk changed : " << disk->device_path();
if (!disk->mount_path().empty()) {
- HideFileBrowserNotification("MOUNT", disk->system_path());
+ HideDeviceNotification(disk->system_path());
// Remember this mount point.
if (mounted_devices_.find(disk->device_path()) == mounted_devices_.end()) {
mounted_devices_.insert(
std::pair<std::string, std::string>(disk->device_path(),
disk->mount_path()));
DispatchMountEvent(disk, true);
- HideFileBrowserNotification("MOUNT", disk->system_path());
+ HideDeviceNotification(disk->system_path());
FileManagerUtil::ShowFullTabUrl(profile_, FilePath(disk->mount_path()));
}
}
@@ -376,14 +362,14 @@
const std::string& device_path) {
VLOG(1) << "Device added : " << device_path;
// TODO(zelidrag): Find better icon here.
- ShowFileBrowserNotification("MOUNT", device_path, IDR_PAGEINFO_INFO,
- l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_DETECTION_TITLE),
+ ShowDeviceNotification(device_path, IDR_PAGEINFO_INFO,
l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE));
+
}
void ExtensionFileBrowserEventRouter::OnDeviceRemoved(
const std::string& system_path) {
- HideFileBrowserNotification("MOUNT", system_path);
+ HideDeviceNotification(system_path);
}
void ExtensionFileBrowserEventRouter::OnDeviceScanned(
@@ -391,74 +377,33 @@
VLOG(1) << "Device scanned : " << device_path;
}
-void ExtensionFileBrowserEventRouter::OnFormattingStarted(
- const std::string& device_path) {
- if (device_path[0] == '!') {
- ShowFileBrowserNotification("FORMAT_FINISHED", device_path.substr(1),
- IDR_PAGEINFO_WARNING_MAJOR,
- l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE),
- l10n_util::GetStringUTF16(IDS_FORMATTING_STARTED_FAILURE_MESSAGE));
+void ExtensionFileBrowserEventRouter::ShowDeviceNotification(
+ const std::string& system_path, int icon_resource_id,
+ const string16& message) {
+ NotificationMap::iterator iter = FindNotificationForPath(system_path);
+ std::string mount_path;
+ if (iter != notifications_.end()) {
+ iter->second->Show(message, false, false);
} else {
- ShowFileBrowserNotification("FORMAT", device_path, IDR_PAGEINFO_INFO,
- l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_PENDING_TITLE),
- l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_PENDING_MESSAGE));
+ if (!profile_) {
+ NOTREACHED();
+ return;
+ }
+ chromeos::SystemNotification* notification =
+ new chromeos::SystemNotification(
+ profile_,
+ system_path,
+ icon_resource_id,
+ l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_DETECTION_TITLE));
+ notifications_.insert(NotificationMap::value_type(system_path,
+ linked_ptr<chromeos::SystemNotification>(notification)));
+ notification->Show(message, false, false);
}
}
-void ExtensionFileBrowserEventRouter::OnFormattingFinished(
- const std::string& device_path) {
- if (device_path[0] == '!') {
- HideFileBrowserNotification("FORMAT", device_path.substr(1));
- ShowFileBrowserNotification("FORMAT_FINISHED", device_path.substr(1),
- IDR_PAGEINFO_WARNING_MAJOR,
- l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE),
- l10n_util::GetStringUTF16(IDS_FORMATTING_FINISHED_FAILURE_MESSAGE));
- } else {
- HideFileBrowserNotification("FORMAT", device_path);
- ShowFileBrowserNotification("FORMAT_FINISHED", device_path,
- IDR_PAGEINFO_INFO,
- l10n_util::GetStringUTF16(IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE),
- l10n_util::GetStringUTF16(IDS_FORMATTING_FINISHED_SUCCESS_MESSAGE));
- // Hide it after a couple of seconds
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- base::Bind(&HideFileBrowserNotificationExternally, "FORMAT_FINISHED",
- device_path, this),
- 4000);
- chromeos::MountLibrary* lib =
- chromeos::CrosLibrary::Get()->GetMountLibrary();
- lib->MountPath(device_path.c_str(),
- chromeos::MOUNT_TYPE_DEVICE,
- chromeos::MountPathOptions());
- }
-}
-
-void ExtensionFileBrowserEventRouter::ShowFileBrowserNotification(
- const std::string& category, const std::string& system_path,
- int icon_resource_id, const string16& title, const string16& message) {
- std::string notification_id = category + system_path;
- // New notification always created because, it might have been closed by now.
- NotificationMap::iterator iter = FindNotificationForId(notification_id);
- if (iter != notifications_.end())
- notifications_.erase(iter);
- if (!profile_) {
- NOTREACHED();
- return;
- }
- chromeos::SystemNotification* notification =
- new chromeos::SystemNotification(
- profile_,
- notification_id,
- icon_resource_id,
- title);
- notifications_.insert(NotificationMap::value_type(notification_id,
- linked_ptr<chromeos::SystemNotification>(notification)));
- notification->Show(message, false, false);
-}
-
-void ExtensionFileBrowserEventRouter::HideFileBrowserNotification(
- const std::string& category, const std::string& system_path) {
- NotificationMap::iterator iter = FindNotificationForId(
- category + system_path);
+void ExtensionFileBrowserEventRouter::HideDeviceNotification(
+ const std::string& system_path) {
+ NotificationMap::iterator iter = FindNotificationForPath(system_path);
if (iter != notifications_.end()) {
iter->second->Hide();
notifications_.erase(iter);
@@ -466,15 +411,15 @@
}
ExtensionFileBrowserEventRouter::NotificationMap::iterator
- ExtensionFileBrowserEventRouter::FindNotificationForId(
- const std::string& notification_id) {
+ ExtensionFileBrowserEventRouter::FindNotificationForPath(
+ const std::string& system_path) {
for (NotificationMap::iterator iter = notifications_.begin();
iter != notifications_.end();
++iter) {
const std::string& notification_device_path = iter->first;
// Doing a sub string match so that we find if this new one is a subdevice
// of another already inserted device.
- if (StartsWithASCII(notification_id, notification_device_path, true)) {
+ if (StartsWithASCII(system_path, notification_device_path, true)) {
return iter;
}
}

Powered by Google App Engine
This is Rietveld 408576698