Chromium Code Reviews| 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 5fabd108e6b9e39e00d53cbb47c72da14f6c2406..03c8fdeff94baa20eb91fc85a90f4acc96c88807 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,6 +346,24 @@ void FileBrowserEventRouter::Observe( |
| NOTREACHED(); |
| return; |
| } |
| + if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| + std::string* pref_name = content::Details<std::string>(details).ptr(); |
| + // If the policy got just disabled we have to unmount every device currently |
|
Mattias Nissler (ping if slow)
2012/07/09 09:43:01
s/got just/just got/
pastarmovj
2012/07/11 01:13:57
Done.
|
| + // mounted. The opposite is fine - we can let the user re-plug its device to |
|
Mattias Nissler (ping if slow)
2012/07/09 09:43:01
s/its/her/
pastarmovj
2012/07/11 01:13:57
Done.
|
| + // get it available. |
|
Mattias Nissler (ping if slow)
2012/07/09 09:43:01
s/get/make/
pastarmovj
2012/07/11 01:13:57
Done.
|
| + if (*pref_name == prefs::kExternalStorageDisabled && |
| + profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| + DiskMountManager *manager = DiskMountManager::GetInstance(); |
| + DiskMountManager::MountPointMap mounts(manager->mount_points()); |
| + while (!mounts.empty()) { |
|
Mattias Nissler (ping if slow)
2012/07/09 09:43:01
seems like a simple loop instead of a while(!empty
pastarmovj
2012/07/11 01:13:57
Done.
|
| + LOG(INFO) << "Unmounting " << mounts.begin()->second.mount_path |
| + << " because of policy."; |
| + manager->UnmountPath(mounts.begin()->second.mount_path); |
| + mounts.erase(mounts.begin()); |
| + } |
| + return; |
| + } |
| + } |
| profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
|
Mattias Nissler (ping if slow)
2012/07/09 09:43:01
This should probably be guarded in a type/pref nam
pastarmovj
2012/07/11 01:13:57
I don't think so it used to catch all notification
|
| extension_event_names::kOnFileBrowserGDataPreferencesChanged, |
| "[]", NULL, GURL()); |
| @@ -546,8 +566,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 +603,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, |