OLD | NEW |
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/media_galleries/imported_media_gallery_registry.h" | 5 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" | 10 #include "chrome/browser/media_galleries/fileapi/iphoto_data_provider.h" |
10 #include "chrome/browser/media_galleries/fileapi/itunes_data_provider.h" | 11 #include "chrome/browser/media_galleries/fileapi/itunes_data_provider.h" |
11 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" | 12 #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
12 #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" | 13 #include "chrome/browser/media_galleries/fileapi/picasa_data_provider.h" |
13 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "webkit/browser/fileapi/isolated_context.h" | 16 #include "webkit/browser/fileapi/external_mount_points.h" |
16 | 17 |
17 using base::Bind; | 18 using base::Bind; |
18 using fileapi::IsolatedContext; | 19 using fileapi::ExternalMountPoints; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 static base::LazyInstance<ImportedMediaGalleryRegistry>::Leaky | 23 static base::LazyInstance<ImportedMediaGalleryRegistry>::Leaky |
23 g_imported_media_gallery_registry = LAZY_INSTANCE_INITIALIZER; | 24 g_imported_media_gallery_registry = LAZY_INSTANCE_INITIALIZER; |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
27 // static | 28 // static |
28 ImportedMediaGalleryRegistry* ImportedMediaGalleryRegistry::GetInstance() { | 29 ImportedMediaGalleryRegistry* ImportedMediaGalleryRegistry::GetInstance() { |
29 return g_imported_media_gallery_registry.Pointer(); | 30 return g_imported_media_gallery_registry.Pointer(); |
30 } | 31 } |
31 | 32 |
32 std::string ImportedMediaGalleryRegistry::RegisterPicasaFilesystemOnUIThread( | 33 bool ImportedMediaGalleryRegistry::RegisterPicasaFilesystemOnUIThread( |
33 const base::FilePath& database_path) { | 34 const std::string& fs_name, const base::FilePath& database_path) { |
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 36 DCHECK(!fs_name.empty()); |
35 DCHECK(!database_path.empty()); | 37 DCHECK(!database_path.empty()); |
36 | 38 |
37 std::string fsid; | 39 bool result = false; |
38 | 40 |
39 #if defined(OS_WIN) || defined(OS_MACOSX) | 41 #if defined(OS_WIN) || defined(OS_MACOSX) |
40 fsid = IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( | 42 base::FilePath root = ImportedRoot(); |
41 fileapi::kFileSystemTypePicasa, | 43 if (root.empty()) |
42 extension_misc::kMediaFileSystemPathPart, | 44 return false; |
43 base::FilePath()); | 45 result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 46 fs_name, fileapi::kFileSystemTypePicasa, root.AppendASCII("picasa")); |
| 47 if (!result) |
| 48 return result; |
44 | 49 |
45 if (fsid.empty()) | 50 picasa_fs_names_.insert(fs_name); |
46 return fsid; | |
47 | 51 |
48 picasa_fsids_.insert(fsid); | 52 if (picasa_fs_names_.size() == 1) { |
49 | |
50 if (picasa_fsids_.size() == 1) { | |
51 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 53 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
52 FROM_HERE, | 54 FROM_HERE, |
53 Bind(&ImportedMediaGalleryRegistry::RegisterPicasaFileSystem, | 55 Bind(&ImportedMediaGalleryRegistry::RegisterPicasaFileSystem, |
54 base::Unretained(this), database_path)); | 56 base::Unretained(this), database_path)); |
55 #ifndef NDEBUG | 57 #ifndef NDEBUG |
56 picasa_database_path_ = database_path; | 58 picasa_database_path_ = database_path; |
57 } else { | 59 } else { |
58 DCHECK_EQ(picasa_database_path_.value(), database_path.value()); | 60 DCHECK_EQ(picasa_database_path_.value(), database_path.value()); |
59 #endif | 61 #endif |
60 } | 62 } |
61 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 63 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
62 | 64 |
63 return fsid; | 65 return result; |
64 } | 66 } |
65 | 67 |
66 std::string ImportedMediaGalleryRegistry::RegisterITunesFilesystemOnUIThread( | 68 bool ImportedMediaGalleryRegistry::RegisterITunesFilesystemOnUIThread( |
67 const base::FilePath& library_xml_path) { | 69 const std::string& fs_name, const base::FilePath& library_xml_path) { |
68 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
69 DCHECK(!library_xml_path.empty()); | 71 DCHECK(!library_xml_path.empty()); |
70 | 72 |
71 std::string fsid; | 73 bool result = false; |
72 | 74 |
73 #if defined(OS_WIN) || defined(OS_MACOSX) | 75 #if defined(OS_WIN) || defined(OS_MACOSX) |
74 fsid = IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( | 76 base::FilePath root = ImportedRoot(); |
75 fileapi::kFileSystemTypeItunes, | 77 if (root.empty()) |
76 extension_misc::kMediaFileSystemPathPart, | 78 return false; |
77 base::FilePath()); | 79 result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 80 fs_name, fileapi::kFileSystemTypeItunes, root.AppendASCII("itunes")); |
| 81 if (!result) |
| 82 return result; |
78 | 83 |
79 if (fsid.empty()) | 84 itunes_fs_names_.insert(fs_name); |
80 return fsid; | |
81 | 85 |
82 itunes_fsids_.insert(fsid); | 86 if (itunes_fs_names_.size() == 1) { |
83 | |
84 if (itunes_fsids_.size() == 1) { | |
85 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 87 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
86 FROM_HERE, | 88 FROM_HERE, |
87 Bind(&ImportedMediaGalleryRegistry::RegisterITunesFileSystem, | 89 Bind(&ImportedMediaGalleryRegistry::RegisterITunesFileSystem, |
88 base::Unretained(this), library_xml_path)); | 90 base::Unretained(this), library_xml_path)); |
89 #ifndef NDEBUG | 91 #ifndef NDEBUG |
90 itunes_xml_library_path_ = library_xml_path; | 92 itunes_xml_library_path_ = library_xml_path; |
91 } else { | 93 } else { |
92 DCHECK_EQ(itunes_xml_library_path_.value(), library_xml_path.value()); | 94 DCHECK_EQ(itunes_xml_library_path_.value(), library_xml_path.value()); |
93 #endif | 95 #endif |
94 } | 96 } |
95 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 97 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
96 | 98 |
97 return fsid; | 99 return result; |
98 } | 100 } |
99 | 101 |
100 std::string ImportedMediaGalleryRegistry::RegisterIPhotoFilesystemOnUIThread( | 102 bool ImportedMediaGalleryRegistry::RegisterIPhotoFilesystemOnUIThread( |
101 const base::FilePath& library_xml_path) { | 103 const std::string& fs_name, const base::FilePath& library_xml_path) { |
102 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
103 DCHECK(!library_xml_path.empty()); | 105 DCHECK(!library_xml_path.empty()); |
104 | 106 |
105 std::string fsid; | 107 bool result = false; |
106 | 108 |
107 // TODO(gbillock): Investigate how to refactor this to reduce duplicated | 109 // TODO(gbillock): Investigate how to refactor this to reduce duplicated |
108 // code. | 110 // code. |
109 #if defined(OS_MACOSX) | 111 #if defined(OS_MACOSX) |
110 fsid = IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( | 112 base::FilePath root = ImportedRoot(); |
111 fileapi::kFileSystemTypeIphoto, | 113 if (root.empty()) |
112 extension_misc::kMediaFileSystemPathPart, | 114 return false; |
113 base::FilePath()); | 115 result = ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 116 fs_name, fileapi::kFileSystemTypeIphoto, root.AppendASCII("iphoto")); |
| 117 if (!result) |
| 118 return result; |
114 | 119 |
115 if (fsid.empty()) | 120 iphoto_fs_names_.insert(fs_name); |
116 return fsid; | |
117 | 121 |
118 iphoto_fsids_.insert(fsid); | 122 if (iphoto_fs_names_.size() == 1) { |
119 | |
120 if (iphoto_fsids_.size() == 1) { | |
121 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 123 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
122 FROM_HERE, | 124 FROM_HERE, |
123 Bind(&ImportedMediaGalleryRegistry::RegisterIPhotoFileSystem, | 125 Bind(&ImportedMediaGalleryRegistry::RegisterIPhotoFileSystem, |
124 base::Unretained(this), library_xml_path)); | 126 base::Unretained(this), library_xml_path)); |
125 #ifndef NDEBUG | 127 #ifndef NDEBUG |
126 iphoto_xml_library_path_ = library_xml_path; | 128 iphoto_xml_library_path_ = library_xml_path; |
127 } else { | 129 } else { |
128 DCHECK_EQ(iphoto_xml_library_path_.value(), library_xml_path.value()); | 130 DCHECK_EQ(iphoto_xml_library_path_.value(), library_xml_path.value()); |
129 #endif | 131 #endif |
130 } | 132 } |
131 #endif // defined(OS_MACOSX) | 133 #endif // defined(OS_MACOSX) |
132 | 134 |
133 return fsid; | 135 return result; |
134 } | 136 } |
135 | 137 |
136 bool ImportedMediaGalleryRegistry::RevokeImportedFilesystemOnUIThread( | 138 bool ImportedMediaGalleryRegistry::RevokeImportedFilesystemOnUIThread( |
137 const std::string& fsid) { | 139 const std::string& fs_name) { |
138 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 140 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
139 | 141 |
140 #if defined(OS_WIN) || defined(OS_MACOSX) | 142 #if defined(OS_WIN) || defined(OS_MACOSX) |
141 if (picasa_fsids_.erase(fsid)) { | 143 if (picasa_fs_names_.erase(fs_name)) { |
142 if (picasa_fsids_.empty()) { | 144 if (picasa_fs_names_.empty()) { |
143 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 145 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
144 FROM_HERE, | 146 FROM_HERE, |
145 Bind(&ImportedMediaGalleryRegistry::RevokePicasaFileSystem, | 147 Bind(&ImportedMediaGalleryRegistry::RevokePicasaFileSystem, |
146 base::Unretained(this))); | 148 base::Unretained(this))); |
147 } | 149 } |
148 return IsolatedContext::GetInstance()->RevokeFileSystem(fsid); | 150 return ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name); |
149 } | 151 } |
150 | 152 |
151 if (itunes_fsids_.erase(fsid)) { | 153 if (itunes_fs_names_.erase(fs_name)) { |
152 if (itunes_fsids_.empty()) { | 154 if (itunes_fs_names_.empty()) { |
153 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 155 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
154 FROM_HERE, | 156 FROM_HERE, |
155 Bind(&ImportedMediaGalleryRegistry::RevokeITunesFileSystem, | 157 Bind(&ImportedMediaGalleryRegistry::RevokeITunesFileSystem, |
156 base::Unretained(this))); | 158 base::Unretained(this))); |
157 } | 159 } |
158 return IsolatedContext::GetInstance()->RevokeFileSystem(fsid); | 160 return ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name); |
159 } | 161 } |
160 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 162 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
161 | 163 |
162 #if defined(OS_MACOSX) | 164 #if defined(OS_MACOSX) |
163 if (iphoto_fsids_.erase(fsid)) { | 165 if (iphoto_fs_names_.erase(fs_name)) { |
164 if (iphoto_fsids_.empty()) { | 166 if (iphoto_fs_names_.empty()) { |
165 MediaFileSystemBackend::MediaTaskRunner()->PostTask( | 167 MediaFileSystemBackend::MediaTaskRunner()->PostTask( |
166 FROM_HERE, | 168 FROM_HERE, |
167 Bind(&ImportedMediaGalleryRegistry::RevokeIPhotoFileSystem, | 169 Bind(&ImportedMediaGalleryRegistry::RevokeIPhotoFileSystem, |
168 base::Unretained(this))); | 170 base::Unretained(this))); |
169 } | 171 } |
170 return IsolatedContext::GetInstance()->RevokeFileSystem(fsid); | 172 return ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fs_name); |
171 } | 173 } |
172 #endif // defined(OS_MACOSX) | 174 #endif // defined(OS_MACOSX) |
173 | 175 |
174 return false; | 176 return false; |
175 } | 177 } |
176 | 178 |
177 #if defined(OS_WIN) || defined(OS_MACOSX) | 179 #if defined(OS_WIN) || defined(OS_MACOSX) |
178 // static | 180 // static |
179 picasa::PicasaDataProvider* | 181 picasa::PicasaDataProvider* |
180 ImportedMediaGalleryRegistry::PicasaDataProvider() { | 182 ImportedMediaGalleryRegistry::PicasaDataProvider() { |
(...skipping 26 matching lines...) Expand all Loading... |
207 ImportedMediaGalleryRegistry::~ImportedMediaGalleryRegistry() { | 209 ImportedMediaGalleryRegistry::~ImportedMediaGalleryRegistry() { |
208 #if defined(OS_WIN) || defined(OS_MACOSX) | 210 #if defined(OS_WIN) || defined(OS_MACOSX) |
209 DCHECK_EQ(0U, picasa_fsids_.size()); | 211 DCHECK_EQ(0U, picasa_fsids_.size()); |
210 DCHECK_EQ(0U, itunes_fsids_.size()); | 212 DCHECK_EQ(0U, itunes_fsids_.size()); |
211 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 213 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
212 #if defined(OS_MACOSX) | 214 #if defined(OS_MACOSX) |
213 DCHECK_EQ(0U, iphoto_fsids_.size()); | 215 DCHECK_EQ(0U, iphoto_fsids_.size()); |
214 #endif // defined(OS_MACOSX) | 216 #endif // defined(OS_MACOSX) |
215 } | 217 } |
216 | 218 |
| 219 base::FilePath ImportedMediaGalleryRegistry::ImportedRoot() { |
| 220 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
| 221 if (imported_root_.empty()) { |
| 222 if (!base::CreateTemporaryFile(&imported_root_)) |
| 223 imported_root_ = base::FilePath(); |
| 224 // TODO(vandebo) Setting the permissions of |imported_root_| in CPSP to |
| 225 // zero would be an extra step to ensure permissions are correctly |
| 226 // enforced. |
| 227 } |
| 228 return imported_root_; |
| 229 } |
| 230 |
217 #if defined(OS_WIN) || defined(OS_MACOSX) | 231 #if defined(OS_WIN) || defined(OS_MACOSX) |
218 void ImportedMediaGalleryRegistry::RegisterPicasaFileSystem( | 232 void ImportedMediaGalleryRegistry::RegisterPicasaFileSystem( |
219 const base::FilePath& database_path) { | 233 const base::FilePath& database_path) { |
220 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 234 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
221 DCHECK(!picasa_data_provider_); | 235 DCHECK(!picasa_data_provider_); |
222 picasa_data_provider_.reset(new picasa::PicasaDataProvider(database_path)); | 236 picasa_data_provider_.reset(new picasa::PicasaDataProvider(database_path)); |
223 } | 237 } |
224 | 238 |
225 void ImportedMediaGalleryRegistry::RevokePicasaFileSystem() { | 239 void ImportedMediaGalleryRegistry::RevokePicasaFileSystem() { |
226 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 240 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
(...skipping 22 matching lines...) Expand all Loading... |
249 DCHECK(!iphoto_data_provider_); | 263 DCHECK(!iphoto_data_provider_); |
250 iphoto_data_provider_.reset(new iphoto::IPhotoDataProvider(xml_library_path)); | 264 iphoto_data_provider_.reset(new iphoto::IPhotoDataProvider(xml_library_path)); |
251 } | 265 } |
252 | 266 |
253 void ImportedMediaGalleryRegistry::RevokeIPhotoFileSystem() { | 267 void ImportedMediaGalleryRegistry::RevokeIPhotoFileSystem() { |
254 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 268 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); |
255 DCHECK(iphoto_data_provider_); | 269 DCHECK(iphoto_data_provider_); |
256 iphoto_data_provider_.reset(); | 270 iphoto_data_provider_.reset(); |
257 } | 271 } |
258 #endif // defined(OS_MACOSX) | 272 #endif // defined(OS_MACOSX) |
OLD | NEW |