Chromium Code Reviews| Index: chrome/browser/extensions/api/streams_private/streams_private_api.cc |
| diff --git a/chrome/browser/extensions/api/streams_private/streams_private_api.cc b/chrome/browser/extensions/api/streams_private/streams_private_api.cc |
| index db22e8e2a03b611fa67b5f6f9f2e07cdc2566a04..436c46b12f2ccac88f4d38c37326dec3f6f11152 100644 |
| --- a/chrome/browser/extensions/api/streams_private/streams_private_api.cc |
| +++ b/chrome/browser/extensions/api/streams_private/streams_private_api.cc |
| @@ -15,6 +15,7 @@ |
| #include "chrome/browser/extensions/extension_system.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/extensions/mime_types_handler.h" |
| +#include "content/public/browser/stream_handle.h" |
| namespace keys = extension_input_module_constants; |
| @@ -27,14 +28,51 @@ const char kOnExecuteMimeTypeHandler[] = |
| namespace extensions { |
| +// static |
| +StreamsPrivateAPI* StreamsPrivateAPI::Get(Profile* profile) { |
| + return GetFactoryInstance()->GetForProfile(profile); |
| +} |
| + |
| StreamsPrivateAPI::StreamsPrivateAPI(Profile* profile) |
| - : profile_(profile) { |
| + : profile_(profile), |
| + weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| (new MimeTypesHandlerParser)->Register(); |
| + |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| + content::Source<Profile>(profile)); |
| } |
| StreamsPrivateAPI::~StreamsPrivateAPI() { |
| } |
| +void StreamsPrivateAPI::ExecuteMimeTypeHandler( |
| + const std::string& extension_id, |
| + scoped_ptr<content::StreamHandle> stream) { |
| + // Create the event's arguments value. |
| + scoped_ptr<ListValue> event_args(new ListValue()); |
| + event_args->Append(new base::StringValue(stream->GetMimeType())); |
| + event_args->Append(new base::StringValue(stream->GetOriginalURL().spec())); |
| + event_args->Append(new base::StringValue(stream->GetURL().spec())); |
| + |
| + scoped_ptr<Event> event(new Event(events::kOnExecuteMimeTypeHandler, |
| + event_args.Pass())); |
| + |
| + ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( |
| + extension_id, event.Pass()); |
| + |
| + stream->NotifyWhenConsumed(base::Bind(&StreamsPrivateAPI::OnStreamClosed, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + extension_id, |
| + stream->GetURL())); |
| + streams_[extension_id][stream->GetURL()] = |
| + make_linked_ptr(stream.release()); |
| +} |
| + |
| +void StreamsPrivateAPI::OnStreamClosed(const std::string& extension_id, |
|
darin (slow to review)
2013/03/19 14:32:19
nit: OnStreamConsumed?
Note: As I mentioned befor
|
| + const GURL& url) { |
| + streams_[extension_id].erase(url); |
| +} |
| + |
| static base::LazyInstance<ProfileKeyedAPIFactory<StreamsPrivateAPI> > |
| g_factory = LAZY_INSTANCE_INITIALIZER; |
| @@ -44,4 +82,13 @@ ProfileKeyedAPIFactory<StreamsPrivateAPI>* |
| return &g_factory.Get(); |
| } |
| +void StreamsPrivateAPI::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
| + const Extension* extension = |
| + content::Details<const UnloadedExtensionInfo>(details)->extension; |
| + streams_.erase(extension->id()); |
| + } |
| +} |
| } // namespace extensions |