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

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

Issue 10933137: Media Galleries: Change the media gallery name to be a JSON value with the name and pref id. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: dcheck Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media_gallery/media_file_system_registry.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media_gallery/media_file_system_registry.cc
===================================================================
--- chrome/browser/media_gallery/media_file_system_registry.cc (revision 157149)
+++ chrome/browser/media_gallery/media_file_system_registry.cc (working copy)
@@ -12,10 +12,13 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/file_path.h"
+#include "base/json/json_writer.h"
#include "base/path_service.h"
#include "base/stl_util.h"
+#include "base/string_util.h"
#include "base/system_monitor/system_monitor.h"
#include "base/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/browser/media_gallery/media_galleries_preferences.h"
#include "chrome/browser/media_gallery/media_galleries_preferences_factory.h"
#include "chrome/browser/profiles/profile.h"
@@ -82,8 +85,42 @@
return fsid;
}
+// Make a JSON string out of |name| and |id|. The |id| makes the combined name
+// unique. The JSON string should not contain any slashes.
+std::string MakeJSONFileSystemName(const string16& name,
+ const MediaGalleryPrefId& id) {
+ string16 sanitized_name;
+ string16 separators =
+#if defined(FILE_PATH_USES_WIN_SEPARATORS)
+ FilePath::kSeparators
+#else
+ ASCIIToUTF16(FilePath::kSeparators)
+#endif
+ ; // NOLINT
+ ReplaceChars(name, separators.c_str(), ASCIIToUTF16("_"), &sanitized_name);
+
+ base::DictionaryValue dict_value;
+ dict_value.SetWithoutPathExpansion(
+ "name", Value::CreateStringValue(sanitized_name));
+ dict_value.SetWithoutPathExpansion("id", Value::CreateIntegerValue(id));
+
+ std::string json_string;
+ base::JSONWriter::Write(&dict_value, &json_string);
+ return json_string;
+}
+
} // namespace
+MediaFileSystemInfo::MediaFileSystemInfo(const std::string& fs_name,
+ const FilePath& fs_path,
+ const std::string& filesystem_id)
+ : name(fs_name),
+ path(fs_path),
+ fsid(filesystem_id) {
+}
+
+MediaFileSystemInfo::MediaFileSystemInfo() {}
+
#if defined(SUPPORT_MEDIA_FILESYSTEM)
// Class to manage MediaDeviceDelegateImpl object for the attached media
// device. Refcounted to reuse the same media device delegate entry across
@@ -279,17 +316,18 @@
galleries.begin();
pref_id_it != galleries.end();
++pref_id_it) {
+ const MediaGalleryPrefId& pref_id = *pref_id_it;
const MediaGalleryPrefInfo& gallery_info =
- galleries_info.find(*pref_id_it)->second;
+ galleries_info.find(pref_id)->second;
const std::string& device_id = gallery_info.device_id;
if (!ContainsKey(*attached_devices, device_id))
continue;
PrefIdFsInfoMap::const_iterator existing_info =
- pref_id_map_.find(*pref_id_it);
+ pref_id_map_.find(pref_id);
if (existing_info != pref_id_map_.end()) {
result.push_back(existing_info->second);
- new_galleries.insert(*pref_id_it);
+ new_galleries.insert(pref_id);
continue;
}
@@ -306,7 +344,7 @@
fsid = registry_->RegisterFileSystemForMtpDevice(
device_id, path, &mtp_device_host);
DCHECK(mtp_device_host.get());
- media_device_map_references_[*pref_id_it] = mtp_device_host;
+ media_device_map_references_[pref_id] = mtp_device_host;
#else
NOTIMPLEMENTED();
continue;
@@ -314,13 +352,13 @@
}
DCHECK(!fsid.empty());
- MediaFileSystemInfo new_entry;
- new_entry.name = gallery_info.display_name;
- new_entry.path = path;
- new_entry.fsid = fsid;
+ MediaFileSystemInfo new_entry(
+ MakeJSONFileSystemName(gallery_info.display_name, pref_id),
+ path,
+ fsid);
result.push_back(new_entry);
- new_galleries.insert(*pref_id_it);
- pref_id_map_[*pref_id_it] = new_entry;
+ new_galleries.insert(pref_id);
+ pref_id_map_[pref_id] = new_entry;
}
RevokeOldGalleries(new_galleries);
« no previous file with comments | « chrome/browser/media_gallery/media_file_system_registry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698