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 // MediaFileSystemRegistry implementation. | 5 // MediaFileSystemRegistry implementation. |
6 | 6 |
7 #include "chrome/browser/media_gallery/media_file_system_registry.h" | 7 #include "chrome/browser/media_gallery/media_file_system_registry.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 DCHECK(mtp_device_host.get()); | 271 DCHECK(mtp_device_host.get()); |
272 media_device_map_references_[pref_id] = mtp_device_host; | 272 media_device_map_references_[pref_id] = mtp_device_host; |
273 #else | 273 #else |
274 NOTIMPLEMENTED(); | 274 NOTIMPLEMENTED(); |
275 continue; | 275 continue; |
276 #endif | 276 #endif |
277 } | 277 } |
278 DCHECK(!fsid.empty()); | 278 DCHECK(!fsid.empty()); |
279 | 279 |
280 MediaFileSystemInfo new_entry( | 280 MediaFileSystemInfo new_entry( |
281 MakeJSONFileSystemName(gallery_info.display_name, | 281 MakeJSONFileSystemName(gallery_info.display_name, pref_id, device_id), |
282 pref_id, | |
283 device_id), | |
284 path, | 282 path, |
285 fsid); | 283 fsid); |
286 result.push_back(new_entry); | 284 result.push_back(new_entry); |
287 new_galleries.insert(pref_id); | 285 new_galleries.insert(pref_id); |
288 pref_id_map_[pref_id] = new_entry; | 286 pref_id_map_[pref_id] = new_entry; |
289 } | 287 } |
290 | 288 |
291 if (result.size() == 0) { | 289 if (result.size() == 0) { |
292 rph_refs_.clear(); | 290 rph_refs_.clear(); |
293 CleanUp(); | 291 CleanUp(); |
(...skipping 21 matching lines...) Expand all Loading... |
315 string16 separators = | 313 string16 separators = |
316 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 314 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
317 FilePath::kSeparators | 315 FilePath::kSeparators |
318 #else | 316 #else |
319 ASCIIToUTF16(FilePath::kSeparators) | 317 ASCIIToUTF16(FilePath::kSeparators) |
320 #endif | 318 #endif |
321 ; // NOLINT | 319 ; // NOLINT |
322 ReplaceChars(name, separators.c_str(), ASCIIToUTF16("_"), &sanitized_name); | 320 ReplaceChars(name, separators.c_str(), ASCIIToUTF16("_"), &sanitized_name); |
323 | 321 |
324 base::DictionaryValue dict_value; | 322 base::DictionaryValue dict_value; |
325 dict_value.SetStringWithoutPathExpansion("name", sanitized_name); | 323 dict_value.SetStringWithoutPathExpansion( |
| 324 MediaFileSystemRegistry::kNameKey, sanitized_name); |
326 | 325 |
327 // This should have been a StringValue, but it's a bit late to change it. | 326 // This should have been a StringValue, but it's a bit late to change it. |
328 dict_value.SetIntegerWithoutPathExpansion("galleryId", pref_id); | 327 dict_value.SetIntegerWithoutPathExpansion( |
| 328 MediaFileSystemRegistry::kGalleryIdKey, pref_id); |
329 | 329 |
330 // |device_id| can be empty, in which case, just omit it. | 330 // |device_id| can be empty, in which case, just omit it. |
331 std::string transient_device_id = | 331 std::string transient_device_id = |
332 GetTransientIdForRemovableDeviceId(device_id); | 332 GetTransientIdForRemovableDeviceId(device_id); |
333 if (!transient_device_id.empty()) | 333 if (!transient_device_id.empty()) { |
334 dict_value.SetStringWithoutPathExpansion("deviceId", transient_device_id); | 334 dict_value.SetStringWithoutPathExpansion( |
| 335 MediaFileSystemRegistry::kDeviceIdKey, transient_device_id); |
| 336 } |
335 | 337 |
336 std::string json_string; | 338 std::string json_string; |
337 base::JSONWriter::Write(&dict_value, &json_string); | 339 base::JSONWriter::Write(&dict_value, &json_string); |
338 return json_string; | 340 return json_string; |
339 } | 341 } |
340 | 342 |
341 void OnRendererProcessTerminated(const RenderProcessHost* rph) { | 343 void OnRendererProcessTerminated(const RenderProcessHost* rph) { |
342 RenderProcessHostRefCount::const_iterator rph_info = rph_refs_.find(rph); | 344 RenderProcessHostRefCount::const_iterator rph_info = rph_refs_.find(rph); |
343 DCHECK(rph_info != rph_refs_.end()); | 345 DCHECK(rph_info != rph_refs_.end()); |
344 // We're going to remove everything from the set, so we make a copy | 346 // We're going to remove everything from the set, so we make a copy |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 // A registrar for listening notifications. | 418 // A registrar for listening notifications. |
417 content::NotificationRegistrar registrar_; | 419 content::NotificationRegistrar registrar_; |
418 | 420 |
419 DISALLOW_COPY_AND_ASSIGN(ExtensionGalleriesHost); | 421 DISALLOW_COPY_AND_ASSIGN(ExtensionGalleriesHost); |
420 }; | 422 }; |
421 | 423 |
422 /****************** | 424 /****************** |
423 * Public methods | 425 * Public methods |
424 ******************/ | 426 ******************/ |
425 | 427 |
| 428 const char MediaFileSystemRegistry::kDeviceIdKey[] = "deviceId"; |
| 429 const char MediaFileSystemRegistry::kGalleryIdKey[] = "galleryId"; |
| 430 const char MediaFileSystemRegistry::kNameKey[] = "name"; |
| 431 |
426 void MediaFileSystemRegistry::GetMediaFileSystemsForExtension( | 432 void MediaFileSystemRegistry::GetMediaFileSystemsForExtension( |
427 const content::RenderViewHost* rvh, | 433 const content::RenderViewHost* rvh, |
428 const extensions::Extension* extension, | 434 const extensions::Extension* extension, |
429 const MediaFileSystemsCallback& callback) { | 435 const MediaFileSystemsCallback& callback) { |
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
431 | 437 |
432 Profile* profile = | 438 Profile* profile = |
433 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); | 439 Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); |
434 MediaGalleriesPreferences* preferences = GetPreferences(profile); | 440 MediaGalleriesPreferences* preferences = GetPreferences(profile); |
435 MediaGalleryPrefIdSet galleries = | 441 MediaGalleryPrefIdSet galleries = |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 | 739 |
734 PrefChangeRegistrarMap::iterator pref_it = | 740 PrefChangeRegistrarMap::iterator pref_it = |
735 pref_change_registrar_map_.find(profile); | 741 pref_change_registrar_map_.find(profile); |
736 DCHECK(pref_it != pref_change_registrar_map_.end()); | 742 DCHECK(pref_it != pref_change_registrar_map_.end()); |
737 delete pref_it->second; | 743 delete pref_it->second; |
738 pref_change_registrar_map_.erase(pref_it); | 744 pref_change_registrar_map_.erase(pref_it); |
739 } | 745 } |
740 } | 746 } |
741 | 747 |
742 } // namespace chrome | 748 } // namespace chrome |
OLD | NEW |