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

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

Issue 15294020: StorageMonitor: Make StorageInfo a real class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address nits Created 7 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 | 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_galleries/media_file_system_registry.h" 7 #include "chrome/browser/media_galleries/media_file_system_registry.h"
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // once per profile. 467 // once per profile.
468 extension_hosts_map_[profile] = ExtensionHostMap(); 468 extension_hosts_map_[profile] = ExtensionHostMap();
469 469
470 // TODO(gbillock): Move this stanza to MediaGalleriesPreferences init code. 470 // TODO(gbillock): Move this stanza to MediaGalleriesPreferences init code.
471 // StorageMonitor may be NULL in unit tests. 471 // StorageMonitor may be NULL in unit tests.
472 StorageMonitor* monitor = StorageMonitor::GetInstance(); 472 StorageMonitor* monitor = StorageMonitor::GetInstance();
473 if (!monitor) 473 if (!monitor)
474 return preferences; 474 return preferences;
475 std::vector<StorageInfo> existing_devices = monitor->GetAttachedStorage(); 475 std::vector<StorageInfo> existing_devices = monitor->GetAttachedStorage();
476 for (size_t i = 0; i < existing_devices.size(); i++) { 476 for (size_t i = 0; i < existing_devices.size(); i++) {
477 if (!StorageInfo::IsMediaDevice(existing_devices[i].device_id)) 477 if (!StorageInfo::IsMediaDevice(existing_devices[i].device_id()))
478 continue; 478 continue;
479 if (!existing_devices[i].name.empty()) { 479 if (!existing_devices[i].name().empty()) {
480 preferences->AddGalleryWithName(existing_devices[i].device_id, 480 preferences->AddGalleryWithName(existing_devices[i].device_id(),
481 existing_devices[i].name, 481 existing_devices[i].name(),
482 base::FilePath(), 482 base::FilePath(),
483 false /*not user added*/); 483 false /*not user added*/);
484 } else { 484 } else {
485 preferences->AddGallery(existing_devices[i].device_id, 485 preferences->AddGallery(existing_devices[i].device_id(),
486 base::FilePath(), 486 base::FilePath(),
487 false, 487 false,
488 existing_devices[i].storage_label, 488 existing_devices[i].storage_label(),
489 existing_devices[i].vendor_name, 489 existing_devices[i].vendor_name(),
490 existing_devices[i].model_name, 490 existing_devices[i].model_name(),
491 existing_devices[i].total_size_in_bytes, 491 existing_devices[i].total_size_in_bytes(),
492 base::Time::Now()); 492 base::Time::Now());
493 } 493 }
494 } 494 }
495 return preferences; 495 return preferences;
496 } 496 }
497 497
498 void MediaFileSystemRegistry::OnRemovableStorageDetached( 498 void MediaFileSystemRegistry::OnRemovableStorageDetached(
499 const StorageInfo& info) { 499 const StorageInfo& info) {
500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
501 501
502 // Since revoking a gallery in the ExtensionGalleriesHost may cause it 502 // Since revoking a gallery in the ExtensionGalleriesHost may cause it
503 // to be removed from the map and therefore invalidate any iterator pointing 503 // to be removed from the map and therefore invalidate any iterator pointing
504 // to it, this code first copies all the invalid gallery ids and the 504 // to it, this code first copies all the invalid gallery ids and the
505 // extension hosts in which they may appear (per profile) and revoked it in 505 // extension hosts in which they may appear (per profile) and revoked it in
506 // a second step. 506 // a second step.
507 std::vector<InvalidatedGalleriesInfo> invalid_galleries_info; 507 std::vector<InvalidatedGalleriesInfo> invalid_galleries_info;
508 508
509 for (ExtensionGalleriesHostMap::iterator profile_it = 509 for (ExtensionGalleriesHostMap::iterator profile_it =
510 extension_hosts_map_.begin(); 510 extension_hosts_map_.begin();
511 profile_it != extension_hosts_map_.end(); 511 profile_it != extension_hosts_map_.end();
512 ++profile_it) { 512 ++profile_it) {
513 MediaGalleriesPreferences* preferences = GetPreferences(profile_it->first); 513 MediaGalleriesPreferences* preferences = GetPreferences(profile_it->first);
514 InvalidatedGalleriesInfo invalid_galleries_in_profile; 514 InvalidatedGalleriesInfo invalid_galleries_in_profile;
515 invalid_galleries_in_profile.pref_ids = 515 invalid_galleries_in_profile.pref_ids =
516 preferences->LookUpGalleriesByDeviceId(info.device_id); 516 preferences->LookUpGalleriesByDeviceId(info.device_id());
517 517
518 for (ExtensionHostMap::const_iterator extension_host_it = 518 for (ExtensionHostMap::const_iterator extension_host_it =
519 profile_it->second.begin(); 519 profile_it->second.begin();
520 extension_host_it != profile_it->second.end(); 520 extension_host_it != profile_it->second.end();
521 ++extension_host_it) { 521 ++extension_host_it) {
522 invalid_galleries_in_profile.extension_hosts.insert( 522 invalid_galleries_in_profile.extension_hosts.insert(
523 extension_host_it->second.get()); 523 extension_host_it->second.get());
524 } 524 }
525 525
526 invalid_galleries_info.push_back(invalid_galleries_in_profile); 526 invalid_galleries_info.push_back(invalid_galleries_in_profile);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 // previously used. 720 // previously used.
721 PrefChangeRegistrarMap::iterator pref_it = 721 PrefChangeRegistrarMap::iterator pref_it =
722 pref_change_registrar_map_.find(profile); 722 pref_change_registrar_map_.find(profile);
723 DCHECK(pref_it != pref_change_registrar_map_.end()); 723 DCHECK(pref_it != pref_change_registrar_map_.end());
724 delete pref_it->second; 724 delete pref_it->second;
725 pref_change_registrar_map_.erase(pref_it); 725 pref_change_registrar_map_.erase(pref_it);
726 } 726 }
727 } 727 }
728 728
729 } // namespace chrome 729 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698