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

Unified Diff: chrome/browser/extensions/api/media_gallery/media_gallery_api.cc

Issue 10409084: Media Gallery: Implement a basic version of GetMediaFileSystems(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/media_gallery/media_gallery_api.cc
===================================================================
--- chrome/browser/extensions/api/media_gallery/media_gallery_api.cc (revision 138321)
+++ chrome/browser/extensions/api/media_gallery/media_gallery_api.cc (working copy)
@@ -6,16 +6,61 @@
#include "chrome/browser/extensions/api/media_gallery/media_gallery_api.h"
-#include "base/json/json_writer.h"
+#include <string>
+#include <vector>
+
+#include "base/platform_file.h"
#include "base/values.h"
+#include "chrome/browser/media_gallery/media_device_manager.h"
+#include "content/public/browser/child_process_security_policy.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
namespace extensions {
+using chrome::MediaDeviceManager;
+using content::ChildProcessSecurityPolicy;
+
GetMediaFileSystemsFunction::~GetMediaFileSystemsFunction() {}
bool GetMediaFileSystemsFunction::RunImpl() {
- // TODO(vandebo) Get the list of galleries.
- result_.reset(new ListValue());
+ scoped_ptr<std::vector<MediaDeviceManager::MediaFSIDAndPath> > filesystems;
+ chrome::MediaDeviceManager* media_device_manager =
+ MediaDeviceManager::GetInstance();
+ filesystems.reset(media_device_manager->GetMediaFileSystems());
+
+ base::ListValue* list = new base::ListValue();
+
+ for (size_t i = 0; i < filesystems->size(); i++) {
vandebo (ex-Chrome) 2012/05/23 00:50:46 nit: Can you add a TODO here about checking securi
Lei Zhang 2012/05/23 03:12:49 Done.
+ const MediaDeviceManager::MediaFSIDAndPath& fsid_and_path =
+ (*filesystems)[i];
+ const std::string& fsid = fsid_and_path.first;
+ const FilePath& path = fsid_and_path.second;
+ const FilePath::StringType basepath = path.BaseName().value();
+#if defined(OS_WIN)
+ // We standardize on UTF8 encoding for |basepath|.
+ const std::string basepath_utf8(base::SysWideToUTF8(basepath);
+#elif defined(OS_POSIX)
+ const std::string basepath_utf8(basepath);
+#endif
+
+ base::DictionaryValue* dict_value = new base::DictionaryValue();
+ dict_value->SetWithoutPathExpansion(
+ "fsid", Value::CreateStringValue(fsid));
+ dict_value->SetWithoutPathExpansion(
+ "dirname", Value::CreateStringValue(basepath_utf8));
+ list->Append(dict_value);
+
+ ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
+ render_view_host()->GetProcess()->GetID(),
+ path,
+ (base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_EXCLUSIVE_READ |
+ base::PLATFORM_FILE_ASYNC));
+ }
+
+ result_.reset(list);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698