Chromium Code Reviews| 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; |
| } |