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_manager/event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/profiles/profile_manager.h" | 32 #include "chrome/browser/profiles/profile_manager.h" |
33 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
34 #include "chromeos/login/login_state.h" | 34 #include "chromeos/login/login_state.h" |
35 #include "chromeos/network/network_handler.h" | 35 #include "chromeos/network/network_handler.h" |
36 #include "chromeos/network/network_state_handler.h" | 36 #include "chromeos/network/network_state_handler.h" |
37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/notification_source.h" | 38 #include "content/public/browser/notification_source.h" |
39 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
40 #include "extensions/browser/event_router.h" | 40 #include "extensions/browser/event_router.h" |
| 41 #include "extensions/browser/extension_prefs.h" |
41 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
42 #include "webkit/common/fileapi/file_system_types.h" | 43 #include "webkit/common/fileapi/file_system_types.h" |
43 #include "webkit/common/fileapi/file_system_util.h" | 44 #include "webkit/common/fileapi/file_system_util.h" |
44 | 45 |
45 using chromeos::disks::DiskMountManager; | 46 using chromeos::disks::DiskMountManager; |
46 using chromeos::NetworkHandler; | 47 using chromeos::NetworkHandler; |
47 using content::BrowserThread; | 48 using content::BrowserThread; |
48 using drive::DriveIntegrationService; | 49 using drive::DriveIntegrationService; |
49 using drive::DriveIntegrationServiceFactory; | 50 using drive::DriveIntegrationServiceFactory; |
50 | 51 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // JavaScript does not have 64-bit integers. Instead we use double, which | 114 // JavaScript does not have 64-bit integers. Instead we use double, which |
114 // is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice | 115 // is in IEEE 754 formant and accurate up to 52-bits in JS, and in practice |
115 // in C++. Larger values are rounded. | 116 // in C++. Larger values are rounded. |
116 status->processed.reset( | 117 status->processed.reset( |
117 new double(static_cast<double>(job_info.num_completed_bytes))); | 118 new double(static_cast<double>(job_info.num_completed_bytes))); |
118 status->total.reset( | 119 status->total.reset( |
119 new double(static_cast<double>(job_info.num_total_bytes))); | 120 new double(static_cast<double>(job_info.num_total_bytes))); |
120 } | 121 } |
121 | 122 |
122 // Checks for availability of the Google+ Photos app. | 123 // Checks for availability of the Google+ Photos app. |
| 124 // TODO(mtomasz): Replace with crbug.com/341902 solution. |
123 bool IsGooglePhotosInstalled(Profile *profile) { | 125 bool IsGooglePhotosInstalled(Profile *profile) { |
124 ExtensionService* service = | 126 ExtensionService* service = |
125 extensions::ExtensionSystem::Get(profile)->extension_service(); | 127 extensions::ExtensionSystem::Get(profile)->extension_service(); |
126 if (!service) | 128 if (!service) |
127 return false; | 129 return false; |
128 | 130 |
129 // Google+ Photos uses several ids for different channels. Therefore, all of | 131 // Google+ Photos uses several ids for different channels. Therefore, all of |
130 // them should be checked. | 132 // them should be checked. |
131 const std::string kGooglePlusPhotosIds[] = { | 133 const std::string kGooglePlusPhotosIds[] = { |
132 "ebpbnabdhheoknfklmpddcdijjkmklkp", // G+ Photos staging | 134 "ebpbnabdhheoknfklmpddcdijjkmklkp", // G+ Photos staging |
133 "efjnaogkjbogokcnohkmnjdojkikgobo", // G+ Photos prod | 135 "efjnaogkjbogokcnohkmnjdojkikgobo", // G+ Photos prod |
134 "ejegoaikibpmikoejfephaneibodccma" // G+ Photos dev | 136 "ejegoaikibpmikoejfephaneibodccma" // G+ Photos dev |
135 }; | 137 }; |
136 | 138 |
137 for (size_t i = 0; i < arraysize(kGooglePlusPhotosIds); ++i) { | 139 for (size_t i = 0; i < arraysize(kGooglePlusPhotosIds); ++i) { |
138 if (service->GetExtensionById(kGooglePlusPhotosIds[i], | 140 if (service->GetExtensionById(kGooglePlusPhotosIds[i], |
139 false /* include_disable */) != NULL) | 141 false /* include_disable */) != NULL) |
140 return true; | 142 return true; |
141 } | 143 } |
142 | 144 |
143 return false; | 145 return false; |
144 } | 146 } |
145 | 147 |
| 148 // Checks if the Recovery Tool is running. This is a temporary solution. |
| 149 // TODO(mtomasz): Replace with crbug.com/341902 solution. |
| 150 bool IsRecoveryToolRunning(Profile* profile) { |
| 151 extensions::ExtensionPrefs* extension_prefs = |
| 152 extensions::ExtensionPrefs::Get(profile); |
| 153 if (!extension_prefs) |
| 154 return false; |
| 155 |
| 156 const std::string kRecoveryToolIds[] = { |
| 157 "kkebgepbbgbcmghedmmdfcbdcodlkngh", // Recovert tool staging |
| 158 "jndclpdbaamdhonoechobihbbiimdgai" // Recovery tool prod |
| 159 }; |
| 160 |
| 161 for (size_t i = 0; i < arraysize(kRecoveryToolIds); ++i) { |
| 162 const std::string extension_id = kRecoveryToolIds[i]; |
| 163 if (extension_prefs->IsExtensionRunning(extension_id)) |
| 164 return true; |
| 165 } |
| 166 |
| 167 return false; |
| 168 } |
| 169 |
146 // Sends an event named |event_name| with arguments |event_args| to extensions. | 170 // Sends an event named |event_name| with arguments |event_args| to extensions. |
147 void BroadcastEvent(Profile* profile, | 171 void BroadcastEvent(Profile* profile, |
148 const std::string& event_name, | 172 const std::string& event_name, |
149 scoped_ptr<base::ListValue> event_args) { | 173 scoped_ptr<base::ListValue> event_args) { |
150 extensions::ExtensionSystem::Get(profile)->event_router()-> | 174 extensions::ExtensionSystem::Get(profile)->event_router()-> |
151 BroadcastEvent(make_scoped_ptr( | 175 BroadcastEvent(make_scoped_ptr( |
152 new extensions::Event(event_name, event_args.Pass()))); | 176 new extensions::Event(event_name, event_args.Pass()))); |
153 } | 177 } |
154 | 178 |
155 file_browser_private::MountCompletedStatus | 179 file_browser_private::MountCompletedStatus |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 const base::FilePath& mount_path) { | 707 const base::FilePath& mount_path) { |
684 // Do not attempt to open File Manager while the login is in progress or | 708 // Do not attempt to open File Manager while the login is in progress or |
685 // the screen is locked or running in kiosk app mode and make sure the file | 709 // the screen is locked or running in kiosk app mode and make sure the file |
686 // manager is opened only for the active user. | 710 // manager is opened only for the active user. |
687 if (chromeos::LoginDisplayHostImpl::default_host() || | 711 if (chromeos::LoginDisplayHostImpl::default_host() || |
688 chromeos::ScreenLocker::default_screen_locker() || | 712 chromeos::ScreenLocker::default_screen_locker() || |
689 chrome::IsRunningInForcedAppMode() || | 713 chrome::IsRunningInForcedAppMode() || |
690 profile_ != ProfileManager::GetActiveUserProfile()) | 714 profile_ != ProfileManager::GetActiveUserProfile()) |
691 return; | 715 return; |
692 | 716 |
| 717 // Do not pop-up the File Manager, if the recovery tool is running. |
| 718 if (IsRecoveryToolRunning(profile_)) |
| 719 return; |
| 720 |
693 // According to DCF (Design rule of Camera File system) by JEITA / CP-3461 | 721 // According to DCF (Design rule of Camera File system) by JEITA / CP-3461 |
694 // cameras should have pictures located in the DCIM root directory. | 722 // cameras should have pictures located in the DCIM root directory. |
695 const base::FilePath dcim_path = mount_path.Append( | 723 const base::FilePath dcim_path = mount_path.Append( |
696 FILE_PATH_LITERAL("DCIM")); | 724 FILE_PATH_LITERAL("DCIM")); |
697 | 725 |
698 // If there is no DCIM folder or an external photo importer is not available, | 726 // If there is a DCIM folder and Google+ Photos is installed, then do not |
699 // then launch Files.app. | 727 // launch Files.app. |
700 DirectoryExistsOnUIThread( | 728 DirectoryExistsOnUIThread( |
701 dcim_path, | 729 dcim_path, |
702 IsGooglePhotosInstalled(profile_) ? | 730 IsGooglePhotosInstalled(profile_) |
703 base::Bind(&base::DoNothing) : | 731 ? base::Bind(&base::DoNothing) |
704 base::Bind(&util::OpenRemovableDrive, profile_, mount_path), | 732 : base::Bind(&util::OpenRemovableDrive, profile_, mount_path), |
705 base::Bind(&util::OpenRemovableDrive, profile_, mount_path)); | 733 base::Bind(&util::OpenRemovableDrive, profile_, mount_path)); |
706 } | 734 } |
707 | 735 |
708 void EventRouter::DispatchDeviceEvent( | 736 void EventRouter::DispatchDeviceEvent( |
709 file_browser_private::DeviceEventType type, | 737 file_browser_private::DeviceEventType type, |
710 const std::string& device_path) { | 738 const std::string& device_path) { |
711 file_browser_private::DeviceEvent event; | 739 file_browser_private::DeviceEvent event; |
712 event.type = type; | 740 event.type = type; |
713 event.device_path = device_path; | 741 event.device_path = device_path; |
714 BroadcastEvent(profile_, | 742 BroadcastEvent(profile_, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 } | 872 } |
845 } | 873 } |
846 | 874 |
847 void EventRouter::OnOwnerEntryChanged(aura::Window* window) { | 875 void EventRouter::OnOwnerEntryChanged(aura::Window* window) { |
848 BroadcastEvent(profile_, | 876 BroadcastEvent(profile_, |
849 file_browser_private::OnDesktopChanged::kEventName, | 877 file_browser_private::OnDesktopChanged::kEventName, |
850 file_browser_private::OnDesktopChanged::Create()); | 878 file_browser_private::OnDesktopChanged::Create()); |
851 } | 879 } |
852 | 880 |
853 } // namespace file_manager | 881 } // namespace file_manager |
OLD | NEW |