Bug 891986 - Keep the source ArrayBuffer to a decodeAudioData call alive until the...
[gecko.git] / dom / file / AsyncHelper.cpp
blobe9714195a59d4a1e7520f32543c23747405e1bc5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "AsyncHelper.h"
9 #include "nsIRequestObserver.h"
11 #include "nsNetUtil.h"
13 #include "FileService.h"
15 USING_FILE_NAMESPACE
17 NS_IMPL_THREADSAFE_ISUPPORTS2(AsyncHelper, nsIRunnable, nsIRequest)
19 nsresult
20 AsyncHelper::AsyncWork(nsIRequestObserver* aObserver, nsISupports* aCtxt)
22 nsresult rv;
24 if (aObserver) {
25 // build proxy for observer events
26 rv = NS_NewRequestObserverProxy(getter_AddRefs(mObserver), aObserver, aCtxt);
27 NS_ENSURE_SUCCESS(rv, rv);
30 FileService* service = FileService::GetOrCreate();
31 NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
33 nsIEventTarget* target = service->StreamTransportTarget();
35 rv = target->Dispatch(this, NS_DISPATCH_NORMAL);
36 NS_ENSURE_SUCCESS(rv, rv);
38 return NS_OK;
41 NS_IMETHODIMP
42 AsyncHelper::Run()
44 NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
46 if (mObserver) {
47 mObserver->OnStartRequest(this, nullptr);
50 mStatus = DoStreamWork(mStream);
52 if (mObserver) {
53 mObserver->OnStopRequest(this, nullptr, mStatus);
56 return NS_OK;
59 NS_IMETHODIMP
60 AsyncHelper::GetName(nsACString& aName)
62 NS_WARNING("Shouldn't be called!");
63 return NS_ERROR_NOT_IMPLEMENTED;
66 NS_IMETHODIMP
67 AsyncHelper::IsPending(bool* _retval)
69 NS_WARNING("Shouldn't be called!");
70 return NS_ERROR_NOT_IMPLEMENTED;
73 NS_IMETHODIMP
74 AsyncHelper::GetStatus(nsresult* aStatus)
76 *aStatus = mStatus;
77 return NS_OK;
80 NS_IMETHODIMP
81 AsyncHelper::Cancel(nsresult aStatus)
83 return NS_OK;
86 NS_IMETHODIMP
87 AsyncHelper::Suspend()
89 NS_WARNING("Shouldn't be called!");
90 return NS_ERROR_NOT_IMPLEMENTED;
93 NS_IMETHODIMP
94 AsyncHelper::Resume()
96 NS_WARNING("Shouldn't be called!");
97 return NS_ERROR_NOT_IMPLEMENTED;
100 NS_IMETHODIMP
101 AsyncHelper::GetLoadGroup(nsILoadGroup** aLoadGroup)
103 NS_WARNING("Shouldn't be called!");
104 return NS_ERROR_NOT_IMPLEMENTED;
107 NS_IMETHODIMP
108 AsyncHelper::SetLoadGroup(nsILoadGroup* aLoadGroup)
110 NS_WARNING("Shouldn't be called!");
111 return NS_ERROR_NOT_IMPLEMENTED;
114 NS_IMETHODIMP
115 AsyncHelper::GetLoadFlags(nsLoadFlags* aLoadFlags)
117 NS_WARNING("Shouldn't be called!");
118 return NS_ERROR_NOT_IMPLEMENTED;
121 NS_IMETHODIMP
122 AsyncHelper::SetLoadFlags(nsLoadFlags aLoadFlags)
124 NS_WARNING("Shouldn't be called!");
125 return NS_ERROR_NOT_IMPLEMENTED;