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

Side by Side Diff: chrome/browser/media_gallery/media_file_system_registry.cc

Issue 11442047: Media Galleries: Add more tests for media gallery names. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years 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 (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
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
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
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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 } 697 }
692 698
693 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM) 699 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
694 ScopedMTPDeviceMapEntry* 700 ScopedMTPDeviceMapEntry*
695 MediaFileSystemRegistry::GetOrCreateScopedMTPDeviceMapEntry( 701 MediaFileSystemRegistry::GetOrCreateScopedMTPDeviceMapEntry(
696 const FilePath::StringType& device_location) { 702 const FilePath::StringType& device_location) {
697 MTPDeviceDelegateMap::iterator delegate_it = 703 MTPDeviceDelegateMap::iterator delegate_it =
698 mtp_device_delegate_map_.find(device_location); 704 mtp_device_delegate_map_.find(device_location);
699 if (delegate_it != mtp_device_delegate_map_.end()) 705 if (delegate_it != mtp_device_delegate_map_.end())
700 return delegate_it->second; 706 return delegate_it->second;
701 ScopedMTPDeviceMapEntry* mtp_device_host = new ScopedMTPDeviceMapEntry( 707 ScopedMTPDeviceMapEntry* mtp_device_host =
702 device_location, base::Bind( 708 new ScopedMTPDeviceMapEntry(
703 &MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry, 709 device_location,
704 base::Unretained(this), device_location)); 710 base::Bind(
711 &MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry,
712 base::Unretained(this),
713 device_location));
705 mtp_device_delegate_map_[device_location] = mtp_device_host; 714 mtp_device_delegate_map_[device_location] = mtp_device_host;
706 return mtp_device_host; 715 return mtp_device_host;
707 } 716 }
708 717
709 void MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry( 718 void MediaFileSystemRegistry::RemoveScopedMTPDeviceMapEntry(
710 const FilePath::StringType& device_location) { 719 const FilePath::StringType& device_location) {
711 MTPDeviceDelegateMap::iterator delegate_it = 720 MTPDeviceDelegateMap::iterator delegate_it =
712 mtp_device_delegate_map_.find(device_location); 721 mtp_device_delegate_map_.find(device_location);
713 DCHECK(delegate_it != mtp_device_delegate_map_.end()); 722 DCHECK(delegate_it != mtp_device_delegate_map_.end());
714 mtp_device_delegate_map_.erase(delegate_it); 723 mtp_device_delegate_map_.erase(delegate_it);
(...skipping 15 matching lines...) Expand all
730 739
731 PrefChangeRegistrarMap::iterator pref_it = 740 PrefChangeRegistrarMap::iterator pref_it =
732 pref_change_registrar_map_.find(profile); 741 pref_change_registrar_map_.find(profile);
733 DCHECK(pref_it != pref_change_registrar_map_.end()); 742 DCHECK(pref_it != pref_change_registrar_map_.end());
734 delete pref_it->second; 743 delete pref_it->second;
735 pref_change_registrar_map_.erase(pref_it); 744 pref_change_registrar_map_.erase(pref_it);
736 } 745 }
737 } 746 }
738 747
739 } // namespace chrome 748 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698