Skip to content

Commit

Permalink
Media Galleries API: Audio/Video attached pictures. IPC portion only.
Browse files Browse the repository at this point in the history
This is a subset of Patchset 13 of https://codereview.chromium.org/250143002/.

Intent is to try to get the less controversial portions of patch reviewed and committed so we can focus on the 'hard' part.

Depends on https://codereview.chromium.org/270873003/ landing.

BUG=304290

Review URL: https://codereview.chromium.org/278933003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270228 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tommycli@chromium.org committed May 13, 2014
1 parent 7beed4b commit c5e85fc
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -865,15 +865,18 @@ void MediaGalleriesGetMetadataFunction::SniffMimeType(
return;
}

// TODO(tommycli): Enable getting attached images.
scoped_refptr<metadata::SafeMediaMetadataParser> parser(
new metadata::SafeMediaMetadataParser(GetProfile(), blob_uuid,
total_blob_length, mime_type));
total_blob_length, mime_type,
false /* get_attached_images */));
parser->Start(base::Bind(
&MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone, this));
}

void MediaGalleriesGetMetadataFunction::OnSafeMediaMetadataParserDone(
bool parse_success, base::DictionaryValue* metadata_dictionary) {
bool parse_success, scoped_ptr<base::DictionaryValue> metadata_dictionary,
scoped_ptr<std::vector<metadata::AttachedImage> > attached_images) {
if (!parse_success) {
SendResponse(false);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "chrome/browser/media_galleries/media_file_system_registry.h"
#include "chrome/browser/media_galleries/media_scan_manager_observer.h"
#include "chrome/common/extensions/api/media_galleries.h"
#include "chrome/common/media_galleries/metadata_types.h"
#include "components/storage_monitor/media_storage_util.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"

Expand Down Expand Up @@ -271,7 +272,8 @@ class MediaGalleriesGetMetadataFunction : public ChromeAsyncExtensionFunction {
int64 total_blob_length);

void OnSafeMediaMetadataParserDone(
bool parse_success, base::DictionaryValue* metadata_dictionary);
bool parse_success, scoped_ptr<base::DictionaryValue> metadata_dictionary,
scoped_ptr<std::vector<metadata::AttachedImage> > attached_images);
};

} // namespace extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ using content::BrowserThread;

namespace metadata {

SafeMediaMetadataParser::SafeMediaMetadataParser(Profile* profile,
const std::string& blob_uuid,
int64 blob_size,
const std::string& mime_type)
SafeMediaMetadataParser::SafeMediaMetadataParser(
Profile* profile, const std::string& blob_uuid, int64 blob_size,
const std::string& mime_type, bool get_attached_images)
: profile_(profile),
blob_uuid_(blob_uuid),
blob_size_(blob_size),
mime_type_(mime_type),
get_attached_images_(get_attached_images),
parser_state_(INITIAL_STATE) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
Expand Down Expand Up @@ -51,24 +51,33 @@ void SafeMediaMetadataParser::StartWorkOnIOThread(
this, base::MessageLoopProxy::current())->AsWeakPtr();

utility_process_host_->Send(
new ChromeUtilityMsg_ParseMediaMetadata(mime_type_, blob_size_));
new ChromeUtilityMsg_ParseMediaMetadata(mime_type_, blob_size_,
get_attached_images_));

parser_state_ = STARTED_PARSING_STATE;
}

void SafeMediaMetadataParser::OnParseMediaMetadataFinished(
bool parse_success, const base::DictionaryValue& metadata_dictionary) {
bool parse_success, const base::DictionaryValue& metadata_dictionary,
const std::vector<AttachedImage>& attached_images) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!callback_.is_null());

if (parser_state_ != STARTED_PARSING_STATE)
return;

// We need to make a scoped copy of this vector since it will be destroyed
// at the end of the IPC message handler.
scoped_ptr<std::vector<metadata::AttachedImage> > attached_images_copy =
make_scoped_ptr(new std::vector<metadata::AttachedImage>(
attached_images));

BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(callback_, parse_success,
base::Owned(metadata_dictionary.DeepCopy())));
base::Passed(make_scoped_ptr(metadata_dictionary.DeepCopy())),
base::Passed(&attached_images_copy)));
parser_state_ = FINISHED_PARSING_STATE;
}

Expand Down Expand Up @@ -120,7 +129,9 @@ void SafeMediaMetadataParser::OnProcessCrashed(int exit_code) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(callback_, false, base::Owned(new base::DictionaryValue)));
base::Bind(callback_, false,
base::Passed(scoped_ptr<base::DictionaryValue>()),
base::Passed(scoped_ptr<std::vector<AttachedImage> >())));
parser_state_ = FINISHED_PARSING_STATE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
#ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_
#define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_MEDIA_METADATA_PARSER_H_

#include <string>
#include <vector>

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/common/extensions/api/media_galleries.h"
#include "chrome/common/media_galleries/metadata_types.h"
#include "content/public/browser/utility_process_host.h"
#include "content/public/browser/utility_process_host_client.h"

Expand All @@ -29,11 +33,14 @@ class SafeMediaMetadataParser : public content::UtilityProcessHostClient {
public:
// |metadata_dictionary| is owned by the callback.
typedef base::Callback<
void(bool parse_success, base::DictionaryValue* metadata_dictionary)>
void(bool parse_success,
scoped_ptr<base::DictionaryValue> metadata_dictionary,
scoped_ptr<std::vector<AttachedImage> > attached_images)>
DoneCallback;

SafeMediaMetadataParser(Profile* profile, const std::string& blob_uuid,
int64 blob_size, const std::string& mime_type);
int64 blob_size, const std::string& mime_type,
bool get_attached_images);

// Should be called on the UI thread. |callback| also runs on the UI thread.
void Start(const DoneCallback& callback);
Expand All @@ -54,8 +61,8 @@ class SafeMediaMetadataParser : public content::UtilityProcessHostClient {
// Notification from the utility process when it finishes parsing metadata.
// Runs on the IO thread.
void OnParseMediaMetadataFinished(
bool parse_success,
const base::DictionaryValue& metadata_dictionary);
bool parse_success, const base::DictionaryValue& metadata_dictionary,
const std::vector<AttachedImage>& attached_images);

// Sequence of functions that bounces from the IO thread to the UI thread to
// read the blob data, then sends the data back to the utility process.
Expand All @@ -78,6 +85,7 @@ class SafeMediaMetadataParser : public content::UtilityProcessHostClient {
const std::string blob_uuid_;
const int64 blob_size_;
const std::string mime_type_;
bool get_attached_images_;

DoneCallback callback_;

Expand Down
3 changes: 3 additions & 0 deletions chrome/chrome_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
'common/media/webrtc_logging_messages.h',
'common/media/webrtc_logging_message_data.cc',
'common/media/webrtc_logging_message_data.h',
'common/media_galleries/metadata_types.h',
'common/metrics/caching_permuted_entropy_provider.cc',
'common/metrics/caching_permuted_entropy_provider.h',
'common/metrics/metrics_service_base.cc',
Expand Down Expand Up @@ -390,6 +391,7 @@
['exclude', '^common/custom_handlers/'],
['exclude', '^common/extensions/'],
['exclude', '^common/logging_chrome\\.'],
['exclude', '^common/media_galleries/'],
['exclude', '^common/multi_process_'],
['exclude', '^common/nacl_'],
['exclude', '^common/pepper_flash\\.'],
Expand Down Expand Up @@ -435,6 +437,7 @@
['exclude', '^common/importer/'],
['include', '^common/importer/imported_favicon_usage.cc$'],
['include', '^common/importer/imported_favicon_usage.h$'],
['exclude', '^common/media_galleries/'],
['exclude', '^common/service_'],
],
'sources!': [
Expand Down
21 changes: 16 additions & 5 deletions chrome/common/chrome_utility_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "chrome/common/extensions/update_manifest.h"
#include "chrome/common/media_galleries/iphoto_library.h"
#include "chrome/common/media_galleries/itunes_library.h"
#include "chrome/common/media_galleries/metadata_types.h"
#include "chrome/common/media_galleries/picasa_types.h"
#include "chrome/common/safe_browsing/zip_analyzer.h"
#include "ipc/ipc_message_macros.h"
Expand Down Expand Up @@ -147,6 +148,13 @@ IPC_STRUCT_TRAITS_BEGIN(picasa::FolderINIContents)
IPC_STRUCT_TRAITS_END()
#endif // defined(OS_WIN) || defined(OS_MACOSX)

#if !defined(OS_ANDROID) && !defined(OS_IOS)
IPC_STRUCT_TRAITS_BEGIN(metadata::AttachedImage)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(data)
IPC_STRUCT_TRAITS_END()
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)

//------------------------------------------------------------------------------
// Utility process messages:
// These are messages from the browser to the utility process.
Expand Down Expand Up @@ -291,9 +299,10 @@ IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_CheckMediaFile,
int64 /* milliseconds_of_decoding */,
IPC::PlatformFileForTransit /* Media file to parse */)

IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_ParseMediaMetadata,
IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_ParseMediaMetadata,
std::string /* mime_type */,
int64 /* total_size */)
int64 /* total_size */,
bool /* get_attached_images */)

IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_RequestBlobBytes_Finished,
int64 /* request_id */,
Expand Down Expand Up @@ -481,9 +490,11 @@ IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_IndexPicasaAlbumsContents_Finished,
IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_CheckMediaFile_Finished,
bool /* passed_checks */)

IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_ParseMediaMetadata_Finished,
bool /* parse_success */,
base::DictionaryValue /* metadata */)
IPC_MESSAGE_CONTROL3(
ChromeUtilityHostMsg_ParseMediaMetadata_Finished,
bool /* parse_success */,
base::DictionaryValue /* metadata */,
std::vector<metadata::AttachedImage> /* attached_images */)

IPC_MESSAGE_CONTROL3(ChromeUtilityHostMsg_RequestBlobBytes,
int64 /* request_id */,
Expand Down
19 changes: 19 additions & 0 deletions chrome/common/media_galleries/metadata_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_COMMON_MEDIA_GALLERIES_METADATA_TYPES_H_
#define CHROME_COMMON_MEDIA_GALLERIES_METADATA_TYPES_H_

#include <string>

namespace metadata {

struct AttachedImage {
std::string type;
std::string data;
};

} // namespace metadata

#endif // CHROME_COMMON_MEDIA_GALLERIES_METADATA_TYPES_H_
15 changes: 8 additions & 7 deletions chrome/utility/chrome_content_utility_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#endif // defined(OS_WIN) || defined(OS_MACOSX)

#if !defined(OS_ANDROID) && !defined(OS_IOS)
#include "chrome/common/media_galleries/metadata_types.h"
#include "chrome/utility/media_galleries/image_metadata_extractor.h"
#include "chrome/utility/media_galleries/ipc_data_source.h"
#include "chrome/utility/media_galleries/media_metadata_parser.h"
Expand Down Expand Up @@ -170,7 +171,7 @@ class PdfFunctionsBase {
const base::FilePath& pdf_module_path,
const base::ScopedNativeLibrary& pdf_lib) {
return true;
};
}

private:
// Exported by PDF plugin.
Expand Down Expand Up @@ -303,9 +304,10 @@ typedef PdfFunctionsBase PdfFunctions;
#if !defined(OS_ANDROID) && !defined(OS_IOS)
void FinishParseMediaMetadata(
metadata::MediaMetadataParser* parser,
scoped_ptr<extensions::api::media_galleries::MediaMetadata> metadata) {
const extensions::api::media_galleries::MediaMetadata& metadata,
const std::vector<metadata::AttachedImage>& attached_images) {
Send(new ChromeUtilityHostMsg_ParseMediaMetadata_Finished(
true, *(metadata->ToValue().get())));
true, *metadata.ToValue(), attached_images));
ReleaseProcessIfNeeded();
}
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
Expand Down Expand Up @@ -919,14 +921,13 @@ void ChromeContentUtilityClient::OnCheckMediaFile(
}

void ChromeContentUtilityClient::OnParseMediaMetadata(
const std::string& mime_type,
int64 total_size) {
const std::string& mime_type, int64 total_size, bool get_attached_images) {
// Only one IPCDataSource may be created and added to the list of handlers.
metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size);
handlers_.push_back(source);

metadata::MediaMetadataParser* parser =
new metadata::MediaMetadataParser(source, mime_type);
metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser(
source, mime_type, get_attached_images);
parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser)));
}
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)
Expand Down
3 changes: 2 additions & 1 deletion chrome/utility/chrome_content_utility_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient {
#if !defined(OS_ANDROID) && !defined(OS_IOS)
void OnCheckMediaFile(int64 milliseconds_of_decoding,
const IPC::PlatformFileForTransit& media_file);
void OnParseMediaMetadata(const std::string& mime_type, int64 total_size);
void OnParseMediaMetadata(const std::string& mime_type, int64 total_size,
bool get_attached_images);
#endif // !defined(OS_ANDROID) && !defined(OS_IOS)

#if defined(OS_WIN)
Expand Down
Loading

0 comments on commit c5e85fc

Please sign in to comment.