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

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

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 | Annotate | Revision Log
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 15 matching lines...) Expand all
26 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" 26 #include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h"
27 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" 27 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h"
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
31 #include "chromeos/chromeos_switches.h" 31 #include "chromeos/chromeos_switches.h"
32 #include "chromeos/disks/disk_mount_manager.h" 32 #include "chromeos/disks/disk_mount_manager.h"
33 #include "components/storage_monitor/storage_monitor.h" 33 #include "components/storage_monitor/storage_monitor.h"
34 #include "content/public/browser/browser_context.h" 34 #include "content/public/browser/browser_context.h"
35 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 #include "webkit/browser/fileapi/external_mount_points.h" 36 #include "storage/browser/fileapi/external_mount_points.h"
37 37
38 namespace file_manager { 38 namespace file_manager {
39 namespace { 39 namespace {
40 40
41 // A named constant to be passed to the |is_remounting| parameter. 41 // A named constant to be passed to the |is_remounting| parameter.
42 const bool kNotRemounting = false; 42 const bool kNotRemounting = false;
43 43
44 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-"; 44 const char kFileManagerMTPMountNamePrefix[] = "fileman-mtp-";
45 const char kMtpVolumeIdPrefix [] = "mtp:"; 45 const char kMtpVolumeIdPrefix [] = "mtp:";
46 46
47 // Registers |path| as the "Downloads" folder to the FileSystem API backend. 47 // Registers |path| as the "Downloads" folder to the FileSystem API backend.
48 // If another folder is already mounted. It revokes and overrides the old one. 48 // If another folder is already mounted. It revokes and overrides the old one.
49 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) { 49 bool RegisterDownloadsMountPoint(Profile* profile, const base::FilePath& path) {
50 // Although we show only profile's own "Downloads" folder in Files.app, 50 // Although we show only profile's own "Downloads" folder in Files.app,
51 // in the backend we need to mount all profile's download directory globally. 51 // in the backend we need to mount all profile's download directory globally.
52 // Otherwise, Files.app cannot support cross-profile file copies, etc. 52 // Otherwise, Files.app cannot support cross-profile file copies, etc.
53 // For this reason, we need to register to the global GetSystemInstance(). 53 // For this reason, we need to register to the global GetSystemInstance().
54 const std::string mount_point_name = 54 const std::string mount_point_name =
55 file_manager::util::GetDownloadsMountPointName(profile); 55 file_manager::util::GetDownloadsMountPointName(profile);
56 fileapi::ExternalMountPoints* const mount_points = 56 storage::ExternalMountPoints* const mount_points =
57 fileapi::ExternalMountPoints::GetSystemInstance(); 57 storage::ExternalMountPoints::GetSystemInstance();
58 58
59 // In some tests we want to override existing Downloads mount point, so we 59 // In some tests we want to override existing Downloads mount point, so we
60 // first revoke the existing mount point (if any). 60 // first revoke the existing mount point (if any).
61 mount_points->RevokeFileSystem(mount_point_name); 61 mount_points->RevokeFileSystem(mount_point_name);
62 return mount_points->RegisterFileSystem( 62 return mount_points->RegisterFileSystem(mount_point_name,
63 mount_point_name, fileapi::kFileSystemTypeNativeLocal, 63 storage::kFileSystemTypeNativeLocal,
64 fileapi::FileSystemMountOption(), path); 64 storage::FileSystemMountOption(),
65 path);
65 } 66 }
66 67
67 // Finds the path register as the "Downloads" folder to FileSystem API backend. 68 // Finds the path register as the "Downloads" folder to FileSystem API backend.
68 // Returns false if it is not registered. 69 // Returns false if it is not registered.
69 bool FindDownloadsMountPointPath(Profile* profile, base::FilePath* path) { 70 bool FindDownloadsMountPointPath(Profile* profile, base::FilePath* path) {
70 const std::string mount_point_name = 71 const std::string mount_point_name =
71 util::GetDownloadsMountPointName(profile); 72 util::GetDownloadsMountPointName(profile);
72 fileapi::ExternalMountPoints* const mount_points = 73 storage::ExternalMountPoints* const mount_points =
73 fileapi::ExternalMountPoints::GetSystemInstance(); 74 storage::ExternalMountPoints::GetSystemInstance();
74 75
75 return mount_points->GetRegisteredPath(mount_point_name, path); 76 return mount_points->GetRegisteredPath(mount_point_name, path);
76 } 77 }
77 78
78 VolumeType MountTypeToVolumeType(chromeos::MountType type) { 79 VolumeType MountTypeToVolumeType(chromeos::MountType type) {
79 switch (type) { 80 switch (type) {
80 case chromeos::MOUNT_TYPE_INVALID: 81 case chromeos::MOUNT_TYPE_INVALID:
81 // We don't expect this value, but list here, so that when any value 82 // We don't expect this value, but list here, so that when any value
82 // is added to the enum definition but this is not edited, the compiler 83 // is added to the enum definition but this is not edited, the compiler
83 // warns it. 84 // warns it.
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 const base::FilePath path = base::FilePath::FromUTF8Unsafe(info.location()); 690 const base::FilePath path = base::FilePath::FromUTF8Unsafe(info.location());
690 const std::string fsid = GetMountPointNameForMediaStorage(info); 691 const std::string fsid = GetMountPointNameForMediaStorage(info);
691 const std::string base_name = base::UTF16ToUTF8(info.model_name()); 692 const std::string base_name = base::UTF16ToUTF8(info.model_name());
692 693
693 // Assign a fresh volume ID based on the volume name. 694 // Assign a fresh volume ID based on the volume name.
694 std::string label = base_name; 695 std::string label = base_name;
695 for (int i = 2; mounted_volumes_.count(kMtpVolumeIdPrefix + label); ++i) 696 for (int i = 2; mounted_volumes_.count(kMtpVolumeIdPrefix + label); ++i)
696 label = base_name + base::StringPrintf(" (%d)", i); 697 label = base_name + base::StringPrintf(" (%d)", i);
697 698
698 bool result = 699 bool result =
699 fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 700 storage::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
700 fsid, fileapi::kFileSystemTypeDeviceMediaAsFileStorage, 701 fsid,
701 fileapi::FileSystemMountOption(), path); 702 storage::kFileSystemTypeDeviceMediaAsFileStorage,
703 storage::FileSystemMountOption(),
704 path);
702 DCHECK(result); 705 DCHECK(result);
703 content::BrowserThread::PostTask( 706 content::BrowserThread::PostTask(
704 content::BrowserThread::IO, FROM_HERE, base::Bind( 707 content::BrowserThread::IO, FROM_HERE, base::Bind(
705 &MTPDeviceMapService::RegisterMTPFileSystem, 708 &MTPDeviceMapService::RegisterMTPFileSystem,
706 base::Unretained(MTPDeviceMapService::GetInstance()), 709 base::Unretained(MTPDeviceMapService::GetInstance()),
707 info.location(), fsid)); 710 info.location(), fsid));
708 711
709 VolumeInfo volume_info; 712 VolumeInfo volume_info;
710 volume_info.type = VOLUME_TYPE_MTP; 713 volume_info.type = VOLUME_TYPE_MTP;
711 volume_info.mount_path = path; 714 volume_info.mount_path = path;
(...skipping 11 matching lines...) Expand all
723 const storage_monitor::StorageInfo& info) { 726 const storage_monitor::StorageInfo& info) {
724 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) 727 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id()))
725 return; 728 return;
726 729
727 for (std::map<std::string, VolumeInfo>::iterator it = 730 for (std::map<std::string, VolumeInfo>::iterator it =
728 mounted_volumes_.begin(); it != mounted_volumes_.end(); ++it) { 731 mounted_volumes_.begin(); it != mounted_volumes_.end(); ++it) {
729 if (it->second.source_path.value() == info.location()) { 732 if (it->second.source_path.value() == info.location()) {
730 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, VolumeInfo(it->second)); 733 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, VolumeInfo(it->second));
731 734
732 const std::string fsid = GetMountPointNameForMediaStorage(info); 735 const std::string fsid = GetMountPointNameForMediaStorage(info);
733 fileapi::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem( 736 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fsid);
734 fsid);
735 content::BrowserThread::PostTask( 737 content::BrowserThread::PostTask(
736 content::BrowserThread::IO, FROM_HERE, base::Bind( 738 content::BrowserThread::IO, FROM_HERE, base::Bind(
737 &MTPDeviceMapService::RevokeMTPFileSystem, 739 &MTPDeviceMapService::RevokeMTPFileSystem,
738 base::Unretained(MTPDeviceMapService::GetInstance()), 740 base::Unretained(MTPDeviceMapService::GetInstance()),
739 fsid)); 741 fsid));
740 return; 742 return;
741 } 743 }
742 } 744 }
743 } 745 }
744 746
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 return; 855 return;
854 if (error_code == chromeos::MOUNT_ERROR_NONE) 856 if (error_code == chromeos::MOUNT_ERROR_NONE)
855 mounted_volumes_.erase(volume_info.volume_id); 857 mounted_volumes_.erase(volume_info.volume_id);
856 858
857 FOR_EACH_OBSERVER(VolumeManagerObserver, 859 FOR_EACH_OBSERVER(VolumeManagerObserver,
858 observers_, 860 observers_,
859 OnVolumeUnmounted(error_code, volume_info)); 861 OnVolumeUnmounted(error_code, volume_info));
860 } 862 }
861 863
862 } // namespace file_manager 864 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698