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

Side by Side Diff: chrome/browser/chromeos/file_manager/volume_manager.cc

Issue 1137383002: Show the eject button only for removabled and file handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tests. Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/file_manager/volume_manager.h" 5 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 std::string GetMountPointNameForMediaStorage( 123 std::string GetMountPointNameForMediaStorage(
124 const storage_monitor::StorageInfo& info) { 124 const storage_monitor::StorageInfo& info) {
125 std::string name(kFileManagerMTPMountNamePrefix); 125 std::string name(kFileManagerMTPMountNamePrefix);
126 name += info.device_id(); 126 name += info.device_id();
127 return name; 127 return name;
128 } 128 }
129 129
130 } // namespace 130 } // namespace
131 131
132 Volume::Volume() 132 Volume::Volume()
133 : type_(VOLUME_TYPE_GOOGLE_DRIVE), 133 : source_(SOURCE_FILE),
134 type_(VOLUME_TYPE_GOOGLE_DRIVE),
134 device_type_(chromeos::DEVICE_TYPE_UNKNOWN), 135 device_type_(chromeos::DEVICE_TYPE_UNKNOWN),
135 mount_condition_(chromeos::disks::MOUNT_CONDITION_NONE), 136 mount_condition_(chromeos::disks::MOUNT_CONDITION_NONE),
136 mount_context_(MOUNT_CONTEXT_UNKNOWN), 137 mount_context_(MOUNT_CONTEXT_UNKNOWN),
137 is_parent_(false), 138 is_parent_(false),
138 is_read_only_(false), 139 is_read_only_(false),
139 has_media_(false) { 140 has_media_(false),
141 configurable_(false) {
140 } 142 }
141 143
142 Volume::~Volume() { 144 Volume::~Volume() {
143 } 145 }
144 146
145 // static 147 // static
146 Volume* Volume::CreateForDrive(Profile* profile) { 148 Volume* Volume::CreateForDrive(Profile* profile) {
147 const base::FilePath& drive_path = 149 const base::FilePath& drive_path =
148 drive::util::GetDriveMountPointPath(profile); 150 drive::util::GetDriveMountPointPath(profile);
149 Volume* const volume = new Volume; 151 Volume* const volume = new Volume;
150 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE; 152 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE;
151 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 153 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
152 volume->source_path_ = drive_path; 154 volume->source_path_ = drive_path;
155 volume->source_ = SOURCE_NETWORK;
153 volume->mount_path_ = drive_path; 156 volume->mount_path_ = drive_path;
154 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 157 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
155 volume->is_parent_ = false;
156 volume->is_read_only_ = false;
157 volume->has_media_ = false;
158 volume->volume_id_ = GenerateVolumeId(*volume); 158 volume->volume_id_ = GenerateVolumeId(*volume);
159 return volume; 159 return volume;
160 } 160 }
161 161
162 // static 162 // static
163 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) { 163 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) {
164 Volume* const volume = new Volume; 164 Volume* const volume = new Volume;
165 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY; 165 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY;
166 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 166 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
167 // Keep source_path empty. 167 // Keep source_path empty.
168 volume->source_ = SOURCE_SYSTEM;
168 volume->mount_path_ = downloads_path; 169 volume->mount_path_ = downloads_path;
169 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 170 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
170 volume->is_parent_ = false;
171 volume->is_read_only_ = false;
172 volume->has_media_ = false;
173 volume->volume_id_ = GenerateVolumeId(*volume); 171 volume->volume_id_ = GenerateVolumeId(*volume);
174 return volume; 172 return volume;
175 } 173 }
176 174
177 // static 175 // static
178 Volume* Volume::CreateForRemovable( 176 Volume* Volume::CreateForRemovable(
179 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, 177 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point,
180 const chromeos::disks::DiskMountManager::Disk* disk) { 178 const chromeos::disks::DiskMountManager::Disk* disk) {
181 Volume* const volume = new Volume; 179 Volume* const volume = new Volume;
182 volume->type_ = MountTypeToVolumeType(mount_point.mount_type); 180 volume->type_ = MountTypeToVolumeType(mount_point.mount_type);
183 volume->source_path_ = base::FilePath(mount_point.source_path); 181 volume->source_path_ = base::FilePath(mount_point.source_path);
182 volume->source_ = mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE
183 ? SOURCE_FILE
184 : SOURCE_DEVICE;
184 volume->mount_path_ = base::FilePath(mount_point.mount_path); 185 volume->mount_path_ = base::FilePath(mount_point.mount_path);
185 volume->mount_condition_ = mount_point.mount_condition; 186 volume->mount_condition_ = mount_point.mount_condition;
186 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe(); 187 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe();
187 if (disk) { 188 if (disk) {
188 volume->device_type_ = disk->device_type(); 189 volume->device_type_ = disk->device_type();
189 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix()); 190 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix());
190 volume->is_parent_ = disk->is_parent(); 191 volume->is_parent_ = disk->is_parent();
191 volume->is_read_only_ = disk->is_read_only(); 192 volume->is_read_only_ = disk->is_read_only();
192 volume->has_media_ = disk->has_media(); 193 volume->has_media_ = disk->has_media();
193 } else { 194 } else {
194 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 195 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
195 volume->is_parent_ = false;
196 volume->is_read_only_ = 196 volume->is_read_only_ =
197 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE); 197 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE);
198 volume->has_media_ = false;
199 } 198 }
200 volume->volume_id_ = GenerateVolumeId(*volume); 199 volume->volume_id_ = GenerateVolumeId(*volume);
201 return volume; 200 return volume;
202 } 201 }
203 202
204 // static 203 // static
205 Volume* Volume::CreateForProvidedFileSystem( 204 Volume* Volume::CreateForProvidedFileSystem(
206 const chromeos::file_system_provider::ProvidedFileSystemInfo& 205 const chromeos::file_system_provider::ProvidedFileSystemInfo&
207 file_system_info, 206 file_system_info,
208 MountContext mount_context) { 207 MountContext mount_context) {
209 Volume* const volume = new Volume; 208 Volume* const volume = new Volume;
210 volume->file_system_id_ = file_system_info.file_system_id(); 209 volume->file_system_id_ = file_system_info.file_system_id();
211 volume->extension_id_ = file_system_info.extension_id(); 210 volume->extension_id_ = file_system_info.extension_id();
211 switch (file_system_info.source()) {
212 case extensions::SOURCE_FILE:
213 volume->source_ = SOURCE_FILE;
214 break;
215 case extensions::SOURCE_DEVICE:
216 volume->source_ = SOURCE_DEVICE;
217 break;
218 case extensions::SOURCE_NETWORK:
219 volume->source_ = SOURCE_NETWORK;
220 break;
221 }
212 volume->volume_label_ = file_system_info.display_name(); 222 volume->volume_label_ = file_system_info.display_name();
213 volume->type_ = VOLUME_TYPE_PROVIDED; 223 volume->type_ = VOLUME_TYPE_PROVIDED;
214 volume->mount_path_ = file_system_info.mount_path(); 224 volume->mount_path_ = file_system_info.mount_path();
215 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 225 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
216 volume->mount_context_ = mount_context; 226 volume->mount_context_ = mount_context;
217 volume->is_parent_ = true; 227 volume->is_parent_ = true;
218 volume->is_read_only_ = !file_system_info.writable(); 228 volume->is_read_only_ = !file_system_info.writable();
219 volume->has_media_ = false; 229 volume->configurable_ = file_system_info.configurable();
220 volume->volume_id_ = GenerateVolumeId(*volume); 230 volume->volume_id_ = GenerateVolumeId(*volume);
221 return volume; 231 return volume;
222 } 232 }
223 233
224 // static 234 // static
225 Volume* Volume::CreateForMTP(const base::FilePath& mount_path, 235 Volume* Volume::CreateForMTP(const base::FilePath& mount_path,
226 const std::string& label, 236 const std::string& label,
227 bool read_only) { 237 bool read_only) {
228 Volume* const volume = new Volume; 238 Volume* const volume = new Volume;
229 volume->type_ = VOLUME_TYPE_MTP; 239 volume->type_ = VOLUME_TYPE_MTP;
230 volume->mount_path_ = mount_path; 240 volume->mount_path_ = mount_path;
231 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 241 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
232 volume->is_parent_ = true; 242 volume->is_parent_ = true;
233 volume->is_read_only_ = read_only; 243 volume->is_read_only_ = read_only;
234 volume->volume_id_ = kMtpVolumeIdPrefix + label; 244 volume->volume_id_ = kMtpVolumeIdPrefix + label;
235 volume->volume_label_ = label; 245 volume->volume_label_ = label;
236 volume->source_path_ = mount_path; 246 volume->source_path_ = mount_path;
247 volume->source_ = SOURCE_DEVICE;
237 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; 248 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE;
238 return volume; 249 return volume;
239 } 250 }
240 251
241 // static 252 // static
242 Volume* Volume::CreateForTesting(const base::FilePath& path, 253 Volume* Volume::CreateForTesting(const base::FilePath& path,
243 VolumeType volume_type, 254 VolumeType volume_type,
244 chromeos::DeviceType device_type, 255 chromeos::DeviceType device_type,
245 bool read_only) { 256 bool read_only) {
246 Volume* const volume = new Volume; 257 Volume* const volume = new Volume;
247 volume->type_ = volume_type; 258 volume->type_ = volume_type;
248 volume->device_type_ = device_type; 259 volume->device_type_ = device_type;
249 // Keep source_path empty. 260 // Keep source_path empty.
261 volume->source_ = SOURCE_DEVICE;
250 volume->mount_path_ = path; 262 volume->mount_path_ = path;
251 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 263 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
252 volume->is_parent_ = false;
253 volume->is_read_only_ = read_only; 264 volume->is_read_only_ = read_only;
254 volume->has_media_ = false;
255 volume->volume_id_ = GenerateVolumeId(*volume); 265 volume->volume_id_ = GenerateVolumeId(*volume);
256 return volume; 266 return volume;
257 } 267 }
258 268
259 // static 269 // static
260 Volume* Volume::CreateForTesting(const base::FilePath& device_path, 270 Volume* Volume::CreateForTesting(const base::FilePath& device_path,
261 const base::FilePath& mount_path) { 271 const base::FilePath& mount_path) {
262 Volume* const volume = new Volume; 272 Volume* const volume = new Volume;
263 volume->system_path_prefix_ = device_path; 273 volume->system_path_prefix_ = device_path;
264 volume->mount_path_ = mount_path; 274 volume->mount_path_ = mount_path;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 void VolumeManager::AddVolumeForTesting(const base::FilePath& path, 424 void VolumeManager::AddVolumeForTesting(const base::FilePath& path,
415 VolumeType volume_type, 425 VolumeType volume_type,
416 chromeos::DeviceType device_type, 426 chromeos::DeviceType device_type,
417 bool read_only) { 427 bool read_only) {
418 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 428 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
419 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 429 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
420 make_linked_ptr(Volume::CreateForTesting( 430 make_linked_ptr(Volume::CreateForTesting(
421 path, volume_type, device_type, read_only))); 431 path, volume_type, device_type, read_only)));
422 } 432 }
423 433
434 void VolumeManager::AddVolumeForTesting(const linked_ptr<Volume>& volume) {
435 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
436 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
437 }
438
424 void VolumeManager::OnFileSystemMounted() { 439 void VolumeManager::OnFileSystemMounted() {
425 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 440 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
426 441
427 // Raise mount event. 442 // Raise mount event.
428 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed 443 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
429 // or network is unreachable. These two errors will be handled later. 444 // or network is unreachable. These two errors will be handled later.
430 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_)); 445 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_));
431 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); 446 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
432 } 447 }
433 448
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 793
779 void VolumeManager::OnStorageMonitorInitialized() { 794 void VolumeManager::OnStorageMonitorInitialized() {
780 std::vector<storage_monitor::StorageInfo> storages = 795 std::vector<storage_monitor::StorageInfo> storages =
781 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); 796 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages();
782 for (size_t i = 0; i < storages.size(); ++i) 797 for (size_t i = 0; i < storages.size(); ++i)
783 OnRemovableStorageAttached(storages[i]); 798 OnRemovableStorageAttached(storages[i]);
784 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); 799 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this);
785 } 800 }
786 801
787 void VolumeManager::DoMountEvent(chromeos::MountError error_code, 802 void VolumeManager::DoMountEvent(chromeos::MountError error_code,
788 linked_ptr<Volume> volume) { 803 const linked_ptr<Volume>& volume) {
789 // Archive files are mounted globally in system. We however don't want to show 804 // Archive files are mounted globally in system. We however don't want to show
790 // archives from profile-specific folders (Drive/Downloads) of other users in 805 // archives from profile-specific folders (Drive/Downloads) of other users in
791 // multi-profile session. To this end, we filter out archives not on the 806 // multi-profile session. To this end, we filter out archives not on the
792 // volumes already mounted on this VolumeManager instance. 807 // volumes already mounted on this VolumeManager instance.
793 if (volume->type() == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) { 808 if (volume->type() == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) {
794 // Source may be in Drive cache folder under the current profile directory. 809 // Source may be in Drive cache folder under the current profile directory.
795 bool from_current_profile = 810 bool from_current_profile =
796 profile_->GetPath().IsParent(volume->source_path()); 811 profile_->GetPath().IsParent(volume->source_path());
797 for (const auto& mounted_volume : mounted_volumes_) { 812 for (const auto& mounted_volume : mounted_volumes_) {
798 if (mounted_volume.second->mount_path().IsParent(volume->source_path())) { 813 if (mounted_volume.second->mount_path().IsParent(volume->source_path())) {
(...skipping 15 matching lines...) Expand all
814 mounted_volumes_[volume->volume_id()] = volume; 829 mounted_volumes_[volume->volume_id()] = volume;
815 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", volume->type(), 830 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", volume->type(),
816 NUM_VOLUME_TYPE); 831 NUM_VOLUME_TYPE);
817 } 832 }
818 833
819 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, 834 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_,
820 OnVolumeMounted(error_code, *volume)); 835 OnVolumeMounted(error_code, *volume));
821 } 836 }
822 837
823 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, 838 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code,
824 linked_ptr<Volume> volume) { 839 const linked_ptr<Volume>& volume) {
825 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) 840 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end())
826 return; 841 return;
827 if (error_code == chromeos::MOUNT_ERROR_NONE) 842 if (error_code == chromeos::MOUNT_ERROR_NONE)
828 mounted_volumes_.erase(volume->volume_id()); 843 mounted_volumes_.erase(volume->volume_id());
829 844
830 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, 845 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_,
831 OnVolumeUnmounted(error_code, *volume.get())); 846 OnVolumeUnmounted(error_code, *volume.get()));
832 } 847 }
833 848
834 } // namespace file_manager 849 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698