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

Side by Side Diff: chrome/browser/extensions/api/streams_private/streams_private_api.cc

Issue 281513003: Implement chrome.streamsPrivate.abort() extensions function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/streams_private/streams_private_api.h" 5 #include "chrome/browser/extensions/api/streams_private/streams_private_api.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_tab_util.h" 9 #include "chrome/browser/extensions/extension_tab_util.h"
10 #include "chrome/common/extensions/api/streams_private.h" 10 #include "chrome/common/extensions/api/streams_private.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 new Event(streams_private::OnExecuteMimeTypeHandler::kEventName, 81 new Event(streams_private::OnExecuteMimeTypeHandler::kEventName,
82 streams_private::OnExecuteMimeTypeHandler::Create(info))); 82 streams_private::OnExecuteMimeTypeHandler::Create(info)));
83 83
84 EventRouter::Get(browser_context_) 84 EventRouter::Get(browser_context_)
85 ->DispatchEventToExtension(extension_id, event.Pass()); 85 ->DispatchEventToExtension(extension_id, event.Pass());
86 86
87 GURL url = stream->GetURL(); 87 GURL url = stream->GetURL();
88 streams_[extension_id][url] = make_linked_ptr(stream.release()); 88 streams_[extension_id][url] = make_linked_ptr(stream.release());
89 } 89 }
90 90
91 void StreamsPrivateAPI::AbortStream(const std::string& extension_id,
92 const GURL& stream_url,
93 const base::Closure& callback) {
94 StreamMap::iterator extension_it = streams_.find(extension_id);
95 if (extension_it == streams_.end()) {
96 callback.Run();
97 return;
98 }
99
100 StreamMap::mapped_type* url_map = &extension_it->second;
101 StreamMap::mapped_type::iterator url_it = url_map->find(stream_url);
102 if (url_it == url_map->end()) {
103 callback.Run();
104 return;
105 }
106
107 url_it->second->AddCloseListener(callback);
108 url_map->erase(url_it);
109 }
110
91 void StreamsPrivateAPI::OnExtensionUnloaded( 111 void StreamsPrivateAPI::OnExtensionUnloaded(
92 content::BrowserContext* browser_context, 112 content::BrowserContext* browser_context,
93 const Extension* extension, 113 const Extension* extension,
94 UnloadedExtensionInfo::Reason reason) { 114 UnloadedExtensionInfo::Reason reason) {
95 streams_.erase(extension->id()); 115 streams_.erase(extension->id());
96 } 116 }
97 117
118 StreamsPrivateAbortFunction::StreamsPrivateAbortFunction() {
119 }
120
121 ExtensionFunction::ResponseAction StreamsPrivateAbortFunction::Run() {
122 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
123 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &stream_url_));
124 StreamsPrivateAPI::Get(browser_context())->AbortStream(
125 extension_id(), GURL(stream_url_), base::Bind(
126 &StreamsPrivateAbortFunction::OnClose, this));
127 return RespondLater();
128 }
129
130 void StreamsPrivateAbortFunction::OnClose() {
131 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
132 Respond(NoArguments());
133 }
134
98 static base::LazyInstance<BrowserContextKeyedAPIFactory<StreamsPrivateAPI> > 135 static base::LazyInstance<BrowserContextKeyedAPIFactory<StreamsPrivateAPI> >
99 g_factory = LAZY_INSTANCE_INITIALIZER; 136 g_factory = LAZY_INSTANCE_INITIALIZER;
100 137
101 // static 138 // static
102 BrowserContextKeyedAPIFactory<StreamsPrivateAPI>* 139 BrowserContextKeyedAPIFactory<StreamsPrivateAPI>*
103 StreamsPrivateAPI::GetFactoryInstance() { 140 StreamsPrivateAPI::GetFactoryInstance() {
104 return g_factory.Pointer(); 141 return g_factory.Pointer();
105 } 142 }
106 143
107 } // namespace extensions 144 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698