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"
17 NS_IMPL_THREADSAFE_ISUPPORTS2(AsyncHelper
, nsIRunnable
, nsIRequest
)
20 AsyncHelper::AsyncWork(nsIRequestObserver
* aObserver
, nsISupports
* aCtxt
)
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
);
44 NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
47 mObserver
->OnStartRequest(this, nullptr);
50 mStatus
= DoStreamWork(mStream
);
53 mObserver
->OnStopRequest(this, nullptr, mStatus
);
60 AsyncHelper::GetName(nsACString
& aName
)
62 NS_WARNING("Shouldn't be called!");
63 return NS_ERROR_NOT_IMPLEMENTED
;
67 AsyncHelper::IsPending(bool* _retval
)
69 NS_WARNING("Shouldn't be called!");
70 return NS_ERROR_NOT_IMPLEMENTED
;
74 AsyncHelper::GetStatus(nsresult
* aStatus
)
81 AsyncHelper::Cancel(nsresult aStatus
)
87 AsyncHelper::Suspend()
89 NS_WARNING("Shouldn't be called!");
90 return NS_ERROR_NOT_IMPLEMENTED
;
96 NS_WARNING("Shouldn't be called!");
97 return NS_ERROR_NOT_IMPLEMENTED
;
101 AsyncHelper::GetLoadGroup(nsILoadGroup
** aLoadGroup
)
103 NS_WARNING("Shouldn't be called!");
104 return NS_ERROR_NOT_IMPLEMENTED
;
108 AsyncHelper::SetLoadGroup(nsILoadGroup
* aLoadGroup
)
110 NS_WARNING("Shouldn't be called!");
111 return NS_ERROR_NOT_IMPLEMENTED
;
115 AsyncHelper::GetLoadFlags(nsLoadFlags
* aLoadFlags
)
117 NS_WARNING("Shouldn't be called!");
118 return NS_ERROR_NOT_IMPLEMENTED
;
122 AsyncHelper::SetLoadFlags(nsLoadFlags aLoadFlags
)
124 NS_WARNING("Shouldn't be called!");
125 return NS_ERROR_NOT_IMPLEMENTED
;