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

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

Issue 10697097: Add a policy to disable mounting of external storage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to ToT. Created 8 years, 5 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
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/chromeos/preferences.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/extensions/file_browser_event_router.cc
diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
index 78a9e2701e0cd02c3dd4ab483efb9c0eccb97c1e..be09f77b3b3c5a2b5f40ad65534677eeff059347 100644
--- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
@@ -29,6 +29,7 @@
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_source.h"
#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_util.h"
@@ -155,6 +156,7 @@ void FileBrowserEventRouter::ObserveFileSystemEvents() {
pref_change_registrar_->Add(prefs::kDisableGDataOverCellular, this);
pref_change_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
pref_change_registrar_->Add(prefs::kDisableGData, this);
+ pref_change_registrar_->Add(prefs::kExternalStorageDisabled, this);
}
// File watch setup routines.
@@ -344,9 +346,30 @@ void FileBrowserEventRouter::Observe(
NOTREACHED();
return;
}
- profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
- extensions::event_names::kOnFileBrowserGDataPreferencesChanged,
- "[]", NULL, GURL());
+ if (type == chrome::NOTIFICATION_PREF_CHANGED) {
+ std::string* pref_name = content::Details<std::string>(details).ptr();
+ // If the policy just got disabled we have to unmount every device currently
+ // mounted. The opposite is fine - we can let the user re-plug her device to
+ // make it available.
+ if (*pref_name == prefs::kExternalStorageDisabled &&
+ profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
+ DiskMountManager *manager = DiskMountManager::GetInstance();
+ DiskMountManager::MountPointMap mounts(manager->mount_points());
+ for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin();
+ it != mounts.end(); ++it) {
+ LOG(INFO) << "Unmounting " << it->second.mount_path
+ << " because of policy.";
+ manager->UnmountPath(it->second.mount_path);
+ }
+ return;
+ } else if (*pref_name == prefs::kDisableGDataOverCellular ||
+ *pref_name == prefs::kDisableGDataHostedFiles ||
+ *pref_name == prefs::kDisableGData) {
+ profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
+ extensions::event_names::kOnFileBrowserGDataPreferencesChanged,
+ "[]", NULL, GURL());
+ }
+ }
}
void FileBrowserEventRouter::OnProgressUpdate(
@@ -546,8 +569,10 @@ void FileBrowserEventRouter::OnDiskAdded(
return;
}
- // If disk is not mounted yet and it has media, give it a try.
- if (disk->mount_path().empty() && disk->has_media()) {
+ // If disk is not mounted yet and it has media and there is no policy
+ // forbidding external storage, give it a try.
+ if (disk->mount_path().empty() && disk->has_media() &&
+ !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
// Initiate disk mount operation. MountPath auto-detects the filesystem
// format if the second argument is empty. The third argument (mount label)
// is not used in a disk mount operation.
@@ -581,6 +606,16 @@ void FileBrowserEventRouter::OnDeviceAdded(
VLOG(1) << "Device added : " << device_path;
+ // If the policy is set instead of showing the new device notification we show
+ // a notification that the operation is not permitted.
+ if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
+ notifications_->ShowNotificationWithMessage(
+ FileBrowserNotifications::DEVICE_FAIL,
+ device_path,
+ l10n_util::GetStringUTF16(IDS_EXTERNAL_STORAGE_DISABLED_MESSAGE));
+ return;
+ }
+
notifications_->RegisterDevice(device_path);
notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE,
device_path,
« no previous file with comments | « chrome/app/policy/policy_templates.json ('k') | chrome/browser/chromeos/preferences.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698