summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-11 23:16:58 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-11 23:16:58 +0000
commit75a3230a00c5416d5cbdd1f1803d126ab507b512 (patch)
treed55526ede53341a5cd30125676bf453e3cc713ab
parent9bea0a88d3c89b66cc95c9e7eae57b13f57ce3d6 (diff)
downloadchromium_src-75a3230a00c5416d5cbdd1f1803d126ab507b512.zip
chromium_src-75a3230a00c5416d5cbdd1f1803d126ab507b512.tar.gz
chromium_src-75a3230a00c5416d5cbdd1f1803d126ab507b512.tar.bz2
Lands http://codereview.chromium.org/505031 for dhg:
Browser should pop up status when usb is inserted. BUG=NONE TEST=NONE Review URL: http://codereview.chromium.org/547009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35967 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_resources.grd2
-rw-r--r--chrome/browser/chromeos/mount_library.cc6
-rw-r--r--chrome/browser/chromeos/mount_library.h11
-rw-r--r--chrome/browser/chromeos/usb_mount_observer.cc76
-rw-r--r--chrome/browser/chromeos/usb_mount_observer.h4
-rw-r--r--chrome/browser/resources/filebrowse.html22
6 files changed, 98 insertions, 23 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index 0b65a12..2940bef 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This comment is only here because changes to resources are not picked up
-without changes to the corresponding grd file. dhg sdggg -->
+without changes to the corresponding grd file. dhg testing -->
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/browser_resources.h" type="rc_header">
diff --git a/chrome/browser/chromeos/mount_library.cc b/chrome/browser/chromeos/mount_library.cc
index 8222b01..488bc8b 100644
--- a/chrome/browser/chromeos/mount_library.cc
+++ b/chrome/browser/chromeos/mount_library.cc
@@ -42,13 +42,17 @@ void MountLibrary::ParseDisks(const MountStatus& status) {
for (int i = 0; i < status.size; i++) {
std::string path;
std::string mountpath;
+ std::string systempath;
if (status.disks[i].path != NULL) {
path = status.disks[i].path;
}
if (status.disks[i].mountpath != NULL) {
mountpath = status.disks[i].mountpath;
}
- disks_.push_back(Disk(path, mountpath));
+ if (status.disks[i].systempath != NULL) {
+ systempath = status.disks[i].systempath;
+ }
+ disks_.push_back(Disk(path, mountpath, systempath));
}
}
diff --git a/chrome/browser/chromeos/mount_library.h b/chrome/browser/chromeos/mount_library.h
index 642349b..2d04aad 100644
--- a/chrome/browser/chromeos/mount_library.h
+++ b/chrome/browser/chromeos/mount_library.h
@@ -23,11 +23,18 @@ class MountLibrary {
// Used to house an instance of each found mount device.
struct Disk {
Disk() {}
- Disk(const std::string& devicepath, const std::string& mountpath)
+ Disk(const std::string& devicepath,
+ const std::string& mountpath,
+ const std::string& systempath)
: device_path(devicepath),
- mount_path(mountpath) {}
+ mount_path(mountpath),
+ system_path(systempath) {}
+ // The path of the device, used by devicekit-disks.
std::string device_path;
+ // The path to the mount point of this device. Will be empty if not mounted.
std::string mount_path;
+ // The path of the device according to the udev system.
+ std::string system_path;
};
typedef std::vector<Disk> DiskVector;
diff --git a/chrome/browser/chromeos/usb_mount_observer.cc b/chrome/browser/chromeos/usb_mount_observer.cc
index 177aaf1..d088334 100644
--- a/chrome/browser/chromeos/usb_mount_observer.cc
+++ b/chrome/browser/chromeos/usb_mount_observer.cc
@@ -2,12 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/chromeos/usb_mount_observer.h"
+
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
-#include "chrome/browser/chromeos/usb_mount_observer.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
namespace chromeos {
+const char* kFilebrowseURLHash = "chrome://filebrowse#";
+const char* kFilebrowseURLScanning = "chrome://filebrowse#scanningdevice";
+const int kPopupLeft = 0;
+const int kPopupTop = 0;
+const int kPopupWidth = 250;
+const int kPopupHeight = 300;
+
void USBMountObserver::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -24,16 +33,39 @@ void USBMountObserver::Observe(NotificationType type,
}
}
+void USBMountObserver::PopUpWindow(const std::string& url,
+ const std::string& device_path) {
+ Browser* browser = Browser::CreateForPopup(profile_);
+ browser->AddTabWithURL(
+ GURL(url), GURL(), PageTransition::LINK,
+ true, -1, false, NULL);
+ browser->window()->SetBounds(gfx::Rect(kPopupLeft,
+ kPopupTop,
+ kPopupWidth,
+ kPopupHeight));
+ registrar_.Add(this,
+ NotificationType::BROWSER_CLOSED,
+ Source<Browser>(browser));
+ browser->window()->Show();
+ BrowserWithPath new_browser;
+ new_browser.browser = browser;
+ new_browser.device_path = device_path;
+ browsers_.push_back(new_browser);
+
+}
+
void USBMountObserver::MountChanged(chromeos::MountLibrary* obj,
chromeos::MountEventType evt,
const std::string& path) {
if (evt == chromeos::DISK_ADDED) {
// Return since disk added doesn't mean anything until
// its mounted, which is a change event.
+ LOG(INFO) << "Got added mount:" << path;
} else if (evt == chromeos::DISK_REMOVED) {
RemoveBrowserFromVector(path);
} else if (evt == chromeos::DISK_CHANGED) {
BrowserIterator iter = FindBrowserForPath(path);
+ LOG(INFO) << "Got changed mount:" << path;
if (iter == browsers_.end()) {
// We don't currently have this one, so it must have been
// mounted
@@ -41,26 +73,34 @@ void USBMountObserver::MountChanged(chromeos::MountLibrary* obj,
for (size_t i = 0; i < disks.size(); ++i) {
if (disks[i].device_path == path) {
if (!disks[i].mount_path.empty()) {
- Browser* browser = Browser::CreateForPopup(profile_);
- std::string url = "chrome://filebrowse#";
- url += disks[i].mount_path;
- browser->AddTabWithURL(
- GURL(url), GURL(), PageTransition::START_PAGE,
- true, -1, false, NULL);
- browser->window()->SetBounds(gfx::Rect(0, 0, 250, 300));
- registrar_.Add(this,
- NotificationType::BROWSER_CLOSED,
- Source<Browser>(browser));
- browser->window()->Show();
- BrowserWithPath new_browser;
- new_browser.browser = browser;
- new_browser.device_path = disks[i].device_path;
- browsers_.push_back(new_browser);
+ // Doing second search to see if the current disk has already
+ // been popped up due to its parent device being plugged in.
+ iter = FindBrowserForPath(disks[i].system_path);
+ if (iter != browsers_.end()) {
+ std::string url = kFilebrowseURLHash;
+ url += disks[i].mount_path;
+ TabContents* tab = iter->browser->GetSelectedTabContents();
+ tab->OpenURL(GURL(url), GURL(), CURRENT_TAB,
+ PageTransition::LINK);
+ iter->device_path = path;
+ iter->browser->Reload();
+ } else {
+ std::string url = kFilebrowseURLHash;
+ url += disks[i].mount_path;
+ PopUpWindow(url, disks[i].device_path);
+ }
}
return;
}
}
}
+ } else if (evt == chromeos::DEVICE_ADDED) {
+ LOG(INFO) << "Got device added" << path;
+ // TODO(dhg): Refactor once mole api is ready.
+ std::string url = kFilebrowseURLScanning;
+ PopUpWindow(url, path);
+ } else if (evt == chromeos::DEVICE_SCANNED) {
+ LOG(INFO) << "Got device scanned:" << path;
}
}
@@ -68,7 +108,9 @@ USBMountObserver::BrowserIterator USBMountObserver::FindBrowserForPath(
const std::string& path) {
for (BrowserIterator i = browsers_.begin();i != browsers_.end();
++i) {
- if (i->device_path == path) {
+ // Doing a substring match so that we find if this new one is a subdevice
+ // of another already inserted device.
+ if (path.find(i->device_path) != std::string::npos) {
return i;
}
}
diff --git a/chrome/browser/chromeos/usb_mount_observer.h b/chrome/browser/chromeos/usb_mount_observer.h
index c6cb2b9..84a8fe2 100644
--- a/chrome/browser/chromeos/usb_mount_observer.h
+++ b/chrome/browser/chromeos/usb_mount_observer.h
@@ -50,6 +50,10 @@ class USBMountObserver : public chromeos::MountLibrary::Observer,
void RemoveBrowserFromVector(const std::string& path);
+ // Used to create a window of a standard size, and add it to a list
+ // of tracked browser windows in case that device goes away.
+ void PopUpWindow(const std::string& url, const std::string& device_path);
+
Profile* profile_;
std::vector<BrowserWithPath> browsers_;
NotificationRegistrar registrar_;
diff --git a/chrome/browser/resources/filebrowse.html b/chrome/browser/resources/filebrowse.html
index bd9a31b..12f133c 100644
--- a/chrome/browser/resources/filebrowse.html
+++ b/chrome/browser/resources/filebrowse.html
@@ -116,7 +116,7 @@ li.filebrowserow span.name {
}
div.title {
- text-align: center;
+ text-align: right;
position: relative;
font-size: .8em;
font-weight: bold;
@@ -180,6 +180,14 @@ div.playbackcontainer {
background: black;
}
+div.scanningcontainer {
+ top: 0;
+ left: 0;
+ position: absolute;
+ width: 100%;
+ height: 100%;
+}
+
div.container {
top: 50px;
position: absolute;
@@ -325,6 +333,14 @@ function getDataForPath(path) {
}
};
+function setUpForScanning() {
+ var header = $('header');
+ document.body.removeChild(header);
+ var main = $('main');
+ main.className = 'scanningcontainer';
+ main.textContent = 'Scanning Device...';
+};
+
///////////////////////////////////////////////////////////////////////////////
// Document Functions:
/**
@@ -334,7 +350,9 @@ function load() {
if (document.location.href.indexOf('#') != -1) {
var currentpathArray = document.location.href.split('#');
var path = currentpathArray[1];
- if (pathIsVideoFile(path) || pathIsAudioFile(path)) {
+ if (path == 'scanningdevice') {
+ setUpForScanning();
+ } else if (pathIsVideoFile(path) || pathIsAudioFile(path)) {
setUpForPlayback(path);
} else {
pathArray.push(path);