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

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: Simplified. 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 } // namespace 130 } // namespace
131 131
132 Volume::Volume() 132 Volume::Volume()
133 : type_(VOLUME_TYPE_GOOGLE_DRIVE), 133 : type_(VOLUME_TYPE_GOOGLE_DRIVE),
134 device_type_(chromeos::DEVICE_TYPE_UNKNOWN), 134 device_type_(chromeos::DEVICE_TYPE_UNKNOWN),
135 mount_condition_(chromeos::disks::MOUNT_CONDITION_NONE), 135 mount_condition_(chromeos::disks::MOUNT_CONDITION_NONE),
136 mount_context_(MOUNT_CONTEXT_UNKNOWN), 136 mount_context_(MOUNT_CONTEXT_UNKNOWN),
137 is_parent_(false), 137 is_parent_(false),
138 is_read_only_(false), 138 is_read_only_(false),
139 has_media_(false) { 139 has_media_(false),
140 configurable_(false) {
hirono 2015/05/14 10:43:08 Please also initialize source_.
mtomasz 2015/05/15 02:03:37 Oops. Done.
140 } 141 }
141 142
142 Volume::~Volume() { 143 Volume::~Volume() {
143 } 144 }
144 145
145 // static 146 // static
146 Volume* Volume::CreateForDrive(Profile* profile) { 147 Volume* Volume::CreateForDrive(Profile* profile) {
147 const base::FilePath& drive_path = 148 const base::FilePath& drive_path =
148 drive::util::GetDriveMountPointPath(profile); 149 drive::util::GetDriveMountPointPath(profile);
149 Volume* const volume = new Volume; 150 Volume* const volume = new Volume;
150 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE; 151 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE;
151 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 152 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
152 volume->source_path_ = drive_path; 153 volume->source_path_ = drive_path;
154 volume->source_ = SOURCE_NETWORK;
153 volume->mount_path_ = drive_path; 155 volume->mount_path_ = drive_path;
154 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 156 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); 157 volume->volume_id_ = GenerateVolumeId(*volume);
159 return volume; 158 return volume;
160 } 159 }
161 160
162 // static 161 // static
163 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) { 162 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) {
164 Volume* const volume = new Volume; 163 Volume* const volume = new Volume;
165 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY; 164 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY;
166 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 165 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
167 // Keep source_path empty. 166 // Keep source_path empty.
167 volume->source_ = SOURCE_SYSTEM;
168 volume->mount_path_ = downloads_path; 168 volume->mount_path_ = downloads_path;
169 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 169 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); 170 volume->volume_id_ = GenerateVolumeId(*volume);
174 return volume; 171 return volume;
175 } 172 }
176 173
177 // static 174 // static
178 Volume* Volume::CreateForRemovable( 175 Volume* Volume::CreateForRemovable(
179 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, 176 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point,
180 const chromeos::disks::DiskMountManager::Disk* disk) { 177 const chromeos::disks::DiskMountManager::Disk* disk) {
181 Volume* const volume = new Volume; 178 Volume* const volume = new Volume;
182 volume->type_ = MountTypeToVolumeType(mount_point.mount_type); 179 volume->type_ = MountTypeToVolumeType(mount_point.mount_type);
183 volume->source_path_ = base::FilePath(mount_point.source_path); 180 volume->source_path_ = base::FilePath(mount_point.source_path);
181 volume->source_ = mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE
182 ? SOURCE_FILE
183 : SOURCE_DEVICE;
184 volume->mount_path_ = base::FilePath(mount_point.mount_path); 184 volume->mount_path_ = base::FilePath(mount_point.mount_path);
185 volume->mount_condition_ = mount_point.mount_condition; 185 volume->mount_condition_ = mount_point.mount_condition;
186 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe(); 186 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe();
187 if (disk) { 187 if (disk) {
188 volume->device_type_ = disk->device_type(); 188 volume->device_type_ = disk->device_type();
189 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix()); 189 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix());
190 volume->is_parent_ = disk->is_parent(); 190 volume->is_parent_ = disk->is_parent();
191 volume->is_read_only_ = disk->is_read_only(); 191 volume->is_read_only_ = disk->is_read_only();
192 volume->has_media_ = disk->has_media(); 192 volume->has_media_ = disk->has_media();
193 } else { 193 } else {
194 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 194 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
195 volume->is_parent_ = false;
196 volume->is_read_only_ = 195 volume->is_read_only_ =
197 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE); 196 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE);
198 volume->has_media_ = false;
199 } 197 }
200 volume->volume_id_ = GenerateVolumeId(*volume); 198 volume->volume_id_ = GenerateVolumeId(*volume);
201 return volume; 199 return volume;
202 } 200 }
203 201
204 // static 202 // static
205 Volume* Volume::CreateForProvidedFileSystem( 203 Volume* Volume::CreateForProvidedFileSystem(
206 const chromeos::file_system_provider::ProvidedFileSystemInfo& 204 const chromeos::file_system_provider::ProvidedFileSystemInfo&
207 file_system_info, 205 file_system_info,
208 MountContext mount_context) { 206 MountContext mount_context) {
209 Volume* const volume = new Volume; 207 Volume* const volume = new Volume;
210 volume->file_system_id_ = file_system_info.file_system_id(); 208 volume->file_system_id_ = file_system_info.file_system_id();
211 volume->extension_id_ = file_system_info.extension_id(); 209 volume->extension_id_ = file_system_info.extension_id();
210 switch (file_system_info.source()) {
211 case extensions::SOURCE_FILE:
212 volume->source_ = SOURCE_FILE;
213 break;
214 case extensions::SOURCE_DEVICE:
215 volume->source_ = SOURCE_DEVICE;
216 break;
217 case extensions::SOURCE_NETWORK:
218 volume->source_ = SOURCE_NETWORK;
219 break;
220 }
212 volume->volume_label_ = file_system_info.display_name(); 221 volume->volume_label_ = file_system_info.display_name();
213 volume->type_ = VOLUME_TYPE_PROVIDED; 222 volume->type_ = VOLUME_TYPE_PROVIDED;
214 volume->mount_path_ = file_system_info.mount_path(); 223 volume->mount_path_ = file_system_info.mount_path();
215 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 224 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
216 volume->mount_context_ = mount_context; 225 volume->mount_context_ = mount_context;
217 volume->is_parent_ = true; 226 volume->is_parent_ = true;
218 volume->is_read_only_ = !file_system_info.writable(); 227 volume->is_read_only_ = !file_system_info.writable();
219 volume->has_media_ = false; 228 volume->configurable_ = file_system_info.configurable();
220 volume->volume_id_ = GenerateVolumeId(*volume); 229 volume->volume_id_ = GenerateVolumeId(*volume);
221 return volume; 230 return volume;
222 } 231 }
223 232
224 // static 233 // static
225 Volume* Volume::CreateForMTP(const base::FilePath& mount_path, 234 Volume* Volume::CreateForMTP(const base::FilePath& mount_path,
226 const std::string& label, 235 const std::string& label,
227 bool read_only) { 236 bool read_only) {
228 Volume* const volume = new Volume; 237 Volume* const volume = new Volume;
229 volume->type_ = VOLUME_TYPE_MTP; 238 volume->type_ = VOLUME_TYPE_MTP;
230 volume->mount_path_ = mount_path; 239 volume->mount_path_ = mount_path;
231 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 240 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
232 volume->is_parent_ = true; 241 volume->is_parent_ = true;
233 volume->is_read_only_ = read_only; 242 volume->is_read_only_ = read_only;
234 volume->volume_id_ = kMtpVolumeIdPrefix + label; 243 volume->volume_id_ = kMtpVolumeIdPrefix + label;
235 volume->volume_label_ = label; 244 volume->volume_label_ = label;
236 volume->source_path_ = mount_path; 245 volume->source_path_ = mount_path;
246 volume->source_ = SOURCE_DEVICE;
237 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; 247 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE;
238 return volume; 248 return volume;
239 } 249 }
240 250
241 // static 251 // static
242 Volume* Volume::CreateForTesting(const base::FilePath& path, 252 Volume* Volume::CreateForTesting(const base::FilePath& path,
243 VolumeType volume_type, 253 VolumeType volume_type,
244 chromeos::DeviceType device_type, 254 chromeos::DeviceType device_type,
245 bool read_only) { 255 bool read_only) {
246 Volume* const volume = new Volume; 256 Volume* const volume = new Volume;
247 volume->type_ = volume_type; 257 volume->type_ = volume_type;
248 volume->device_type_ = device_type; 258 volume->device_type_ = device_type;
249 // Keep source_path empty. 259 // Keep source_path empty.
260 volume->source_ = SOURCE_DEVICE;
250 volume->mount_path_ = path; 261 volume->mount_path_ = path;
251 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 262 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
252 volume->is_parent_ = false;
253 volume->is_read_only_ = read_only; 263 volume->is_read_only_ = read_only;
254 volume->has_media_ = false;
255 volume->volume_id_ = GenerateVolumeId(*volume); 264 volume->volume_id_ = GenerateVolumeId(*volume);
256 return volume; 265 return volume;
257 } 266 }
258 267
259 // static 268 // static
260 Volume* Volume::CreateForTesting(const base::FilePath& device_path, 269 Volume* Volume::CreateForTesting(const base::FilePath& device_path,
261 const base::FilePath& mount_path) { 270 const base::FilePath& mount_path) {
262 Volume* const volume = new Volume; 271 Volume* const volume = new Volume;
263 volume->system_path_prefix_ = device_path; 272 volume->system_path_prefix_ = device_path;
264 volume->mount_path_ = mount_path; 273 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, 423 void VolumeManager::AddVolumeForTesting(const base::FilePath& path,
415 VolumeType volume_type, 424 VolumeType volume_type,
416 chromeos::DeviceType device_type, 425 chromeos::DeviceType device_type,
417 bool read_only) { 426 bool read_only) {
418 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 427 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
419 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 428 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
420 make_linked_ptr(Volume::CreateForTesting( 429 make_linked_ptr(Volume::CreateForTesting(
421 path, volume_type, device_type, read_only))); 430 path, volume_type, device_type, read_only)));
422 } 431 }
423 432
433 void VolumeManager::AddVolumeForTesting(linked_ptr<Volume> volume) {
434 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
435 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
436 }
437
424 void VolumeManager::OnFileSystemMounted() { 438 void VolumeManager::OnFileSystemMounted() {
425 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 439 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
426 440
427 // Raise mount event. 441 // Raise mount event.
428 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed 442 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
429 // or network is unreachable. These two errors will be handled later. 443 // or network is unreachable. These two errors will be handled later.
430 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_)); 444 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_));
431 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume); 445 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
432 } 446 }
433 447
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end()) 839 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end())
826 return; 840 return;
827 if (error_code == chromeos::MOUNT_ERROR_NONE) 841 if (error_code == chromeos::MOUNT_ERROR_NONE)
828 mounted_volumes_.erase(volume->volume_id()); 842 mounted_volumes_.erase(volume->volume_id());
829 843
830 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, 844 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_,
831 OnVolumeUnmounted(error_code, *volume.get())); 845 OnVolumeUnmounted(error_code, *volume.get()));
832 } 846 }
833 847
834 } // namespace file_manager 848 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698