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/extension_event_router.h" | 22 #include "chrome/browser/extensions/extension_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::GDataFileSystem; | 39 using gdata::GDataFileSystem; |
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 } |
349 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | |
350 std::string* pref_name = content::Details<std::string>(details).ptr(); | |
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 } | |
366 } | |
Mattias Nissler (ping if slow)
2012/07/11 09:48:13
I'd still list the preferences that are supposed t
pastarmovj
2012/07/13 15:06:06
Done.
| |
347 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 367 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
348 extension_event_names::kOnFileBrowserGDataPreferencesChanged, | 368 extension_event_names::kOnFileBrowserGDataPreferencesChanged, |
349 "[]", NULL, GURL()); | 369 "[]", NULL, GURL()); |
350 } | 370 } |
351 | 371 |
352 void FileBrowserEventRouter::OnProgressUpdate( | 372 void FileBrowserEventRouter::OnProgressUpdate( |
353 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { | 373 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
355 | 375 |
356 scoped_ptr<ListValue> event_list( | 376 scoped_ptr<ListValue> event_list( |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 void FileBrowserEventRouter::OnDiskAdded( | 559 void FileBrowserEventRouter::OnDiskAdded( |
540 const DiskMountManager::Disk* disk) { | 560 const DiskMountManager::Disk* disk) { |
541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
542 | 562 |
543 VLOG(1) << "Disk added: " << disk->device_path(); | 563 VLOG(1) << "Disk added: " << disk->device_path(); |
544 if (disk->device_path().empty()) { | 564 if (disk->device_path().empty()) { |
545 VLOG(1) << "Empty system path for " << disk->device_path(); | 565 VLOG(1) << "Empty system path for " << disk->device_path(); |
546 return; | 566 return; |
547 } | 567 } |
548 | 568 |
549 // If disk is not mounted yet and it has media, give it a try. | 569 // If disk is not mounted yet and it has media and there is no policy |
550 if (disk->mount_path().empty() && disk->has_media()) { | 570 // forbidding external storage, give it a try. |
571 if (disk->mount_path().empty() && disk->has_media() && | |
572 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | |
551 // Initiate disk mount operation. MountPath auto-detects the filesystem | 573 // Initiate disk mount operation. MountPath auto-detects the filesystem |
552 // format if the second argument is empty. The third argument (mount label) | 574 // format if the second argument is empty. The third argument (mount label) |
553 // is not used in a disk mount operation. | 575 // is not used in a disk mount operation. |
554 DiskMountManager::GetInstance()->MountPath( | 576 DiskMountManager::GetInstance()->MountPath( |
555 disk->device_path(), std::string(), std::string(), | 577 disk->device_path(), std::string(), std::string(), |
556 chromeos::MOUNT_TYPE_DEVICE); | 578 chromeos::MOUNT_TYPE_DEVICE); |
557 } else { | 579 } else { |
558 // Either the disk was mounted or it has no media. In both cases we don't | 580 // Either the disk was mounted or it has no media. In both cases we don't |
559 // want the Scanning notification to persist. | 581 // want the Scanning notification to persist. |
560 notifications_->HideNotification(FileBrowserNotifications::DEVICE, | 582 notifications_->HideNotification(FileBrowserNotifications::DEVICE, |
(...skipping 13 matching lines...) Expand all Loading... | |
574 } | 596 } |
575 DispatchDiskEvent(disk, false); | 597 DispatchDiskEvent(disk, false); |
576 } | 598 } |
577 | 599 |
578 void FileBrowserEventRouter::OnDeviceAdded( | 600 void FileBrowserEventRouter::OnDeviceAdded( |
579 const std::string& device_path) { | 601 const std::string& device_path) { |
580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
581 | 603 |
582 VLOG(1) << "Device added : " << device_path; | 604 VLOG(1) << "Device added : " << device_path; |
583 | 605 |
606 // If the policy is set instead of showing the new device notification we show | |
607 // a notification that the operation is not permitted. | |
608 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | |
609 notifications_->ShowNotificationWithMessage( | |
610 FileBrowserNotifications::DEVICE_FAIL, | |
611 device_path, | |
612 l10n_util::GetStringUTF16(IDS_EXTERNAL_STORAGE_DISABLED_MESSAGE)); | |
613 return; | |
614 } | |
615 | |
584 notifications_->RegisterDevice(device_path); | 616 notifications_->RegisterDevice(device_path); |
585 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, | 617 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, |
586 device_path, | 618 device_path, |
587 base::TimeDelta::FromSeconds(5)); | 619 base::TimeDelta::FromSeconds(5)); |
588 } | 620 } |
589 | 621 |
590 void FileBrowserEventRouter::OnDeviceRemoved( | 622 void FileBrowserEventRouter::OnDeviceRemoved( |
591 const std::string& device_path) { | 623 const std::string& device_path) { |
592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
593 | 625 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 return scoped_refptr<RefcountedProfileKeyedService>( | 808 return scoped_refptr<RefcountedProfileKeyedService>( |
777 new FileBrowserEventRouter(profile)); | 809 new FileBrowserEventRouter(profile)); |
778 } | 810 } |
779 | 811 |
780 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 812 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
781 // Explicitly and always allow this router in guest login mode. see | 813 // Explicitly and always allow this router in guest login mode. see |
782 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 814 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
783 // for the details. | 815 // for the details. |
784 return true; | 816 return true; |
785 } | 817 } |
OLD | NEW |