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

Unified Diff: chrome/browser/media_gallery/media_file_system_registry.cc

Issue 11027051: MediaFileSystemRegistry unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media_gallery/media_file_system_registry.cc
diff --git a/chrome/browser/media_gallery/media_file_system_registry.cc b/chrome/browser/media_gallery/media_file_system_registry.cc
index 10811764f4b3a292ce230ac8458e9ab7e1bd4098..797ee05b011c98df42df0a6d0e5707b9d82e3890 100644
--- a/chrome/browser/media_gallery/media_file_system_registry.cc
+++ b/chrome/browser/media_gallery/media_file_system_registry.cc
@@ -106,11 +106,15 @@ std::string MakeJSONFileSystemName(const string16& name,
}
std::string GetTransientIdForRemovableDeviceId(const std::string& device_id) {
+#if defined(OS_ANDROID)
+ return std::string();
+#else
using extensions::MediaGalleriesPrivateEventRouter;
if (!MediaStorageUtil::IsRemovableDevice(device_id))
return std::string();
return MediaGalleriesPrivateEventRouter::GetTransientIdForDeviceId(device_id);
+#endif // OS_ANDROID
}
} // namespace
@@ -126,51 +130,30 @@ MediaFileSystemInfo::MediaFileSystemInfo(const std::string& fs_name,
MediaFileSystemInfo::MediaFileSystemInfo() {}
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
-// Class to manage MTPDeviceDelegateImpl object for the attached MTP device.
-// Refcounted to reuse the same MTP device delegate entry across extensions.
-// This class supports WeakPtr (extends SupportsWeakPtr) to expose itself as
-// a weak pointer to MediaFileSystemRegistry.
-class ScopedMTPDeviceMapEntry
- : public base::RefCounted<ScopedMTPDeviceMapEntry>,
- public base::SupportsWeakPtr<ScopedMTPDeviceMapEntry> {
- public:
- // |no_references_callback| is called when the last ScopedMTPDeviceMapEntry
- // reference goes away.
- ScopedMTPDeviceMapEntry(const FilePath::StringType& device_location,
- const base::Closure& no_references_callback)
- : device_location_(device_location),
- no_references_callback_(no_references_callback) {
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- Bind(&MTPDeviceMapService::AddDelegate,
- base::Unretained(MTPDeviceMapService::GetInstance()),
- device_location_,
- make_scoped_refptr(new MTPDeviceDelegateImpl(device_location))));
- }
-
- private:
- // Friend declaration for ref counted implementation.
- friend class base::RefCounted<ScopedMTPDeviceMapEntry>;
-
- // Private because this class is ref-counted.
- ~ScopedMTPDeviceMapEntry() {
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- Bind(&MTPDeviceMapService::RemoveDelegate,
- base::Unretained(MTPDeviceMapService::GetInstance()),
- device_location_));
- no_references_callback_.Run();
- }
- // Store the MTP or PTP device location.
- const FilePath::StringType device_location_;
+ScopedMTPDeviceMapEntry::ScopedMTPDeviceMapEntry(
+ const FilePath::StringType& device_location,
+ const base::Closure& no_references_callback)
+ : device_location_(device_location),
+ delegate_(new MTPDeviceDelegateImpl(device_location)),
+ no_references_callback_(no_references_callback) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ Bind(&MTPDeviceMapService::AddDelegate,
+ base::Unretained(MTPDeviceMapService::GetInstance()),
+ device_location_, make_scoped_refptr(delegate_)));
+}
- // A callback to call when the last reference of this object goes away.
- base::Closure no_references_callback_;
+ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ Bind(&MTPDeviceMapService::RemoveDelegate,
+ base::Unretained(MTPDeviceMapService::GetInstance()),
+ device_location_));
+ no_references_callback_.Run();
+}
- DISALLOW_COPY_AND_ASSIGN(ScopedMTPDeviceMapEntry);
-};
-#endif
+#endif // defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
// The main owner of this class is
// |MediaFileSystemRegistry::extension_hosts_map_|, but a callback may
@@ -245,6 +228,11 @@ class ExtensionGalleriesHost
if (mtp_device_host != media_device_map_references_.end())
media_device_map_references_.erase(mtp_device_host);
#endif
+
+ if (pref_id_map_.empty()) {
+ rph_refs_.clear();
+ CleanUp();
+ }
}
// Indicate that the passed |rvh| will reference the file system ids created
@@ -265,7 +253,7 @@ class ExtensionGalleriesHost
RenderProcessHost* rph = contents->GetRenderProcessHost();
rph_refs_[rph].insert(contents);
if (rph_refs_[rph].size() == 1) {
- registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
+ registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::Source<RenderProcessHost>(rph));
}
}
@@ -298,8 +286,8 @@ class ExtensionGalleriesHost
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
switch (type) {
- case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
- OnRendererProcessClosed(
+ case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
+ OnRendererProcessTerminated(
content::Source<RenderProcessHost>(source).ptr());
break;
}
@@ -381,12 +369,17 @@ class ExtensionGalleriesHost
pref_id_map_[pref_id] = new_entry;
}
- RevokeOldGalleries(new_galleries);
+ if (result.size() == 0) {
+ rph_refs_.clear();
+ CleanUp();
+ } else {
+ RevokeOldGalleries(new_galleries);
+ }
callback.Run(result);
}
- void OnRendererProcessClosed(const RenderProcessHost* rph) {
+ void OnRendererProcessTerminated(const RenderProcessHost* rph) {
RenderProcessHostRefCount::const_iterator rph_info = rph_refs_.find(rph);
DCHECK(rph_info != rph_refs_.end());
// We're going to remove everything from the set, so we make a copy
@@ -414,25 +407,31 @@ class ExtensionGalleriesHost
DCHECK(process_refs != rph_refs_.end());
process_refs->second.erase(contents);
if (process_refs->second.empty()) {
- registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
+ registrar_.Remove(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::Source<RenderProcessHost>(rph));
rph_refs_.erase(process_refs);
}
- if (rph_refs_.empty()) {
- for (PrefIdFsInfoMap::const_iterator it = pref_id_map_.begin();
- it != pref_id_map_.end();
- ++it) {
- file_system_context_->RevokeFileSystem(it->second.fsid);
- }
- pref_id_map_.clear();
+ if (rph_refs_.empty())
+ CleanUp();
+ }
+
+ void CleanUp() {
+ DCHECK(rph_refs_.empty());
+ for (PrefIdFsInfoMap::const_iterator it = pref_id_map_.begin();
+ it != pref_id_map_.end();
+ ++it) {
+ file_system_context_->RevokeFileSystem(it->second.fsid);
+ }
+ pref_id_map_.clear();
#if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
- media_device_map_references_.clear();
+ media_device_map_references_.clear();
#endif
- no_references_callback_.Run();
- }
+ registrar_.RemoveAll();
+
+ no_references_callback_.Run();
}
// MediaFileSystemRegistry owns |this| and |file_system_context_|, so it's
@@ -554,6 +553,10 @@ void MediaFileSystemRegistry::OnRemovableStorageAttached(
}
}
+size_t MediaFileSystemRegistry::GetExtensionHostCountForTests() const {
+ return extension_hosts_map_.size();
+}
+
void MediaFileSystemRegistry::OnRemovableStorageDetached(
const std::string& id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

Powered by Google App Engine
This is Rietveld 408576698