OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/extensions/event_router.h" | 22 #include "chrome/browser/extensions/event_router.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/prefs/pref_change_registrar.h" | 24 #include "chrome/browser/prefs/pref_change_registrar.h" |
25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/profiles/profile_dependency_manager.h" | 27 #include "chrome/browser/profiles/profile_dependency_manager.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "ui/base/l10n/l10n_util.h" |
32 #include "webkit/fileapi/file_system_types.h" | 33 #include "webkit/fileapi/file_system_types.h" |
33 #include "webkit/fileapi/file_system_util.h" | 34 #include "webkit/fileapi/file_system_util.h" |
34 | 35 |
35 using chromeos::disks::DiskMountManager; | 36 using chromeos::disks::DiskMountManager; |
36 using chromeos::disks::DiskMountManagerEventType; | 37 using chromeos::disks::DiskMountManagerEventType; |
37 using content::BrowserThread; | 38 using content::BrowserThread; |
38 using gdata::GDataFileSystemInterface; | 39 using gdata::GDataFileSystemInterface; |
39 using gdata::GDataSystemService; | 40 using gdata::GDataSystemService; |
40 using gdata::GDataSystemServiceFactory; | 41 using gdata::GDataSystemServiceFactory; |
41 | 42 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 chromeos::NetworkLibrary* network_library = | 150 chromeos::NetworkLibrary* network_library = |
150 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 151 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
151 if (network_library) | 152 if (network_library) |
152 network_library->AddNetworkManagerObserver(this); | 153 network_library->AddNetworkManagerObserver(this); |
153 | 154 |
154 pref_change_registrar_->Init(profile_->GetPrefs()); | 155 pref_change_registrar_->Init(profile_->GetPrefs()); |
155 pref_change_registrar_->Add(prefs::kDisableGDataOverCellular, this); | 156 pref_change_registrar_->Add(prefs::kDisableGDataOverCellular, this); |
156 pref_change_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 157 pref_change_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
157 pref_change_registrar_->Add(prefs::kDisableGData, this); | 158 pref_change_registrar_->Add(prefs::kDisableGData, this); |
| 159 pref_change_registrar_->Add(prefs::kExternalStorageDisabled, this); |
158 } | 160 } |
159 | 161 |
160 // File watch setup routines. | 162 // File watch setup routines. |
161 bool FileBrowserEventRouter::AddFileWatch( | 163 bool FileBrowserEventRouter::AddFileWatch( |
162 const FilePath& local_path, | 164 const FilePath& local_path, |
163 const FilePath& virtual_path, | 165 const FilePath& virtual_path, |
164 const std::string& extension_id) { | 166 const std::string& extension_id) { |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
166 | 168 |
167 base::AutoLock lock(lock_); | 169 base::AutoLock lock(lock_); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 339 } |
338 | 340 |
339 void FileBrowserEventRouter::Observe( | 341 void FileBrowserEventRouter::Observe( |
340 int type, | 342 int type, |
341 const content::NotificationSource& source, | 343 const content::NotificationSource& source, |
342 const content::NotificationDetails& details) { | 344 const content::NotificationDetails& details) { |
343 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 345 if (!profile_ || !profile_->GetExtensionEventRouter()) { |
344 NOTREACHED(); | 346 NOTREACHED(); |
345 return; | 347 return; |
346 } | 348 } |
347 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 349 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
348 extensions::event_names::kOnFileBrowserGDataPreferencesChanged, | 350 std::string* pref_name = content::Details<std::string>(details).ptr(); |
349 "[]", NULL, GURL()); | 351 // If the policy just got disabled we have to unmount every device currently |
| 352 // mounted. The opposite is fine - we can let the user re-plug her device to |
| 353 // make it available. |
| 354 if (*pref_name == prefs::kExternalStorageDisabled && |
| 355 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| 356 DiskMountManager *manager = DiskMountManager::GetInstance(); |
| 357 DiskMountManager::MountPointMap mounts(manager->mount_points()); |
| 358 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); |
| 359 it != mounts.end(); ++it) { |
| 360 LOG(INFO) << "Unmounting " << it->second.mount_path |
| 361 << " because of policy."; |
| 362 manager->UnmountPath(it->second.mount_path); |
| 363 } |
| 364 return; |
| 365 } else if (*pref_name == prefs::kDisableGDataOverCellular || |
| 366 *pref_name == prefs::kDisableGDataHostedFiles || |
| 367 *pref_name == prefs::kDisableGData) { |
| 368 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 369 extensions::event_names::kOnFileBrowserGDataPreferencesChanged, |
| 370 "[]", NULL, GURL()); |
| 371 } |
| 372 } |
350 } | 373 } |
351 | 374 |
352 void FileBrowserEventRouter::OnProgressUpdate( | 375 void FileBrowserEventRouter::OnProgressUpdate( |
353 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { | 376 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
355 | 378 |
356 scoped_ptr<ListValue> event_list( | 379 scoped_ptr<ListValue> event_list( |
357 file_manager_util::ProgressStatusVectorToListValue( | 380 file_manager_util::ProgressStatusVectorToListValue( |
358 profile_, | 381 profile_, |
359 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), | 382 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 void FileBrowserEventRouter::OnDiskAdded( | 562 void FileBrowserEventRouter::OnDiskAdded( |
540 const DiskMountManager::Disk* disk) { | 563 const DiskMountManager::Disk* disk) { |
541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
542 | 565 |
543 VLOG(1) << "Disk added: " << disk->device_path(); | 566 VLOG(1) << "Disk added: " << disk->device_path(); |
544 if (disk->device_path().empty()) { | 567 if (disk->device_path().empty()) { |
545 VLOG(1) << "Empty system path for " << disk->device_path(); | 568 VLOG(1) << "Empty system path for " << disk->device_path(); |
546 return; | 569 return; |
547 } | 570 } |
548 | 571 |
549 // If disk is not mounted yet and it has media, give it a try. | 572 // If disk is not mounted yet and it has media and there is no policy |
550 if (disk->mount_path().empty() && disk->has_media()) { | 573 // forbidding external storage, give it a try. |
| 574 if (disk->mount_path().empty() && disk->has_media() && |
| 575 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
551 // Initiate disk mount operation. MountPath auto-detects the filesystem | 576 // Initiate disk mount operation. MountPath auto-detects the filesystem |
552 // format if the second argument is empty. The third argument (mount label) | 577 // format if the second argument is empty. The third argument (mount label) |
553 // is not used in a disk mount operation. | 578 // is not used in a disk mount operation. |
554 DiskMountManager::GetInstance()->MountPath( | 579 DiskMountManager::GetInstance()->MountPath( |
555 disk->device_path(), std::string(), std::string(), | 580 disk->device_path(), std::string(), std::string(), |
556 chromeos::MOUNT_TYPE_DEVICE); | 581 chromeos::MOUNT_TYPE_DEVICE); |
557 } else { | 582 } else { |
558 // Either the disk was mounted or it has no media. In both cases we don't | 583 // Either the disk was mounted or it has no media. In both cases we don't |
559 // want the Scanning notification to persist. | 584 // want the Scanning notification to persist. |
560 notifications_->HideNotification(FileBrowserNotifications::DEVICE, | 585 notifications_->HideNotification(FileBrowserNotifications::DEVICE, |
(...skipping 13 matching lines...) Expand all Loading... |
574 } | 599 } |
575 DispatchDiskEvent(disk, false); | 600 DispatchDiskEvent(disk, false); |
576 } | 601 } |
577 | 602 |
578 void FileBrowserEventRouter::OnDeviceAdded( | 603 void FileBrowserEventRouter::OnDeviceAdded( |
579 const std::string& device_path) { | 604 const std::string& device_path) { |
580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
581 | 606 |
582 VLOG(1) << "Device added : " << device_path; | 607 VLOG(1) << "Device added : " << device_path; |
583 | 608 |
| 609 // If the policy is set instead of showing the new device notification we show |
| 610 // a notification that the operation is not permitted. |
| 611 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| 612 notifications_->ShowNotificationWithMessage( |
| 613 FileBrowserNotifications::DEVICE_FAIL, |
| 614 device_path, |
| 615 l10n_util::GetStringUTF16(IDS_EXTERNAL_STORAGE_DISABLED_MESSAGE)); |
| 616 return; |
| 617 } |
| 618 |
584 notifications_->RegisterDevice(device_path); | 619 notifications_->RegisterDevice(device_path); |
585 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, | 620 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, |
586 device_path, | 621 device_path, |
587 base::TimeDelta::FromSeconds(5)); | 622 base::TimeDelta::FromSeconds(5)); |
588 } | 623 } |
589 | 624 |
590 void FileBrowserEventRouter::OnDeviceRemoved( | 625 void FileBrowserEventRouter::OnDeviceRemoved( |
591 const std::string& device_path) { | 626 const std::string& device_path) { |
592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
593 | 628 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 return scoped_refptr<RefcountedProfileKeyedService>( | 812 return scoped_refptr<RefcountedProfileKeyedService>( |
778 new FileBrowserEventRouter(profile)); | 813 new FileBrowserEventRouter(profile)); |
779 } | 814 } |
780 | 815 |
781 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 816 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
782 // Explicitly and always allow this router in guest login mode. see | 817 // Explicitly and always allow this router in guest login mode. see |
783 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 818 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
784 // for the details. | 819 // for the details. |
785 return true; | 820 return true; |
786 } | 821 } |
OLD | NEW |