Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "DeviceStorageRequestParent.h" |
michael@0 | 7 | #include "nsDOMFile.h" |
michael@0 | 8 | #include "nsIMIMEService.h" |
michael@0 | 9 | #include "nsCExternalHandlerService.h" |
michael@0 | 10 | #include "mozilla/unused.h" |
michael@0 | 11 | #include "mozilla/dom/ipc/Blob.h" |
michael@0 | 12 | #include "ContentParent.h" |
michael@0 | 13 | #include "nsProxyRelease.h" |
michael@0 | 14 | #include "AppProcessChecker.h" |
michael@0 | 15 | #include "mozilla/Preferences.h" |
michael@0 | 16 | #include "nsNetCID.h" |
michael@0 | 17 | |
michael@0 | 18 | namespace mozilla { |
michael@0 | 19 | namespace dom { |
michael@0 | 20 | namespace devicestorage { |
michael@0 | 21 | |
michael@0 | 22 | DeviceStorageRequestParent::DeviceStorageRequestParent( |
michael@0 | 23 | const DeviceStorageParams& aParams) |
michael@0 | 24 | : mParams(aParams) |
michael@0 | 25 | , mMutex("DeviceStorageRequestParent::mMutex") |
michael@0 | 26 | , mActorDestoryed(false) |
michael@0 | 27 | { |
michael@0 | 28 | MOZ_COUNT_CTOR(DeviceStorageRequestParent); |
michael@0 | 29 | |
michael@0 | 30 | DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache |
michael@0 | 31 | = DeviceStorageUsedSpaceCache::CreateOrGet(); |
michael@0 | 32 | MOZ_ASSERT(usedSpaceCache); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | void |
michael@0 | 36 | DeviceStorageRequestParent::Dispatch() |
michael@0 | 37 | { |
michael@0 | 38 | switch (mParams.type()) { |
michael@0 | 39 | case DeviceStorageParams::TDeviceStorageAddParams: |
michael@0 | 40 | { |
michael@0 | 41 | DeviceStorageAddParams p = mParams; |
michael@0 | 42 | |
michael@0 | 43 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 44 | new DeviceStorageFile(p.type(), p.storageName(), p.relpath()); |
michael@0 | 45 | |
michael@0 | 46 | BlobParent* bp = static_cast<BlobParent*>(p.blobParent()); |
michael@0 | 47 | nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob(); |
michael@0 | 48 | |
michael@0 | 49 | nsCOMPtr<nsIInputStream> stream; |
michael@0 | 50 | blob->GetInternalStream(getter_AddRefs(stream)); |
michael@0 | 51 | |
michael@0 | 52 | nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream); |
michael@0 | 53 | |
michael@0 | 54 | nsCOMPtr<nsIEventTarget> target |
michael@0 | 55 | = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); |
michael@0 | 56 | MOZ_ASSERT(target); |
michael@0 | 57 | target->Dispatch(r, NS_DISPATCH_NORMAL); |
michael@0 | 58 | break; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | case DeviceStorageParams::TDeviceStorageCreateFdParams: |
michael@0 | 62 | { |
michael@0 | 63 | DeviceStorageCreateFdParams p = mParams; |
michael@0 | 64 | |
michael@0 | 65 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 66 | new DeviceStorageFile(p.type(), p.storageName(), p.relpath()); |
michael@0 | 67 | |
michael@0 | 68 | nsRefPtr<CancelableRunnable> r = new CreateFdEvent(this, dsf); |
michael@0 | 69 | |
michael@0 | 70 | nsCOMPtr<nsIEventTarget> target |
michael@0 | 71 | = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); |
michael@0 | 72 | MOZ_ASSERT(target); |
michael@0 | 73 | target->Dispatch(r, NS_DISPATCH_NORMAL); |
michael@0 | 74 | break; |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | case DeviceStorageParams::TDeviceStorageGetParams: |
michael@0 | 78 | { |
michael@0 | 79 | DeviceStorageGetParams p = mParams; |
michael@0 | 80 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 81 | new DeviceStorageFile(p.type(), p.storageName(), |
michael@0 | 82 | p.rootDir(), p.relpath()); |
michael@0 | 83 | nsRefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf); |
michael@0 | 84 | |
michael@0 | 85 | nsCOMPtr<nsIEventTarget> target |
michael@0 | 86 | = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); |
michael@0 | 87 | MOZ_ASSERT(target); |
michael@0 | 88 | target->Dispatch(r, NS_DISPATCH_NORMAL); |
michael@0 | 89 | break; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | case DeviceStorageParams::TDeviceStorageDeleteParams: |
michael@0 | 93 | { |
michael@0 | 94 | DeviceStorageDeleteParams p = mParams; |
michael@0 | 95 | |
michael@0 | 96 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 97 | new DeviceStorageFile(p.type(), p.storageName(), p.relpath()); |
michael@0 | 98 | nsRefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf); |
michael@0 | 99 | |
michael@0 | 100 | nsCOMPtr<nsIEventTarget> target |
michael@0 | 101 | = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); |
michael@0 | 102 | MOZ_ASSERT(target); |
michael@0 | 103 | target->Dispatch(r, NS_DISPATCH_NORMAL); |
michael@0 | 104 | break; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | case DeviceStorageParams::TDeviceStorageFreeSpaceParams: |
michael@0 | 108 | { |
michael@0 | 109 | DeviceStorageFreeSpaceParams p = mParams; |
michael@0 | 110 | |
michael@0 | 111 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 112 | new DeviceStorageFile(p.type(), p.storageName()); |
michael@0 | 113 | nsRefPtr<FreeSpaceFileEvent> r = new FreeSpaceFileEvent(this, dsf); |
michael@0 | 114 | |
michael@0 | 115 | nsCOMPtr<nsIEventTarget> target |
michael@0 | 116 | = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); |
michael@0 | 117 | MOZ_ASSERT(target); |
michael@0 | 118 | target->Dispatch(r, NS_DISPATCH_NORMAL); |
michael@0 | 119 | break; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | case DeviceStorageParams::TDeviceStorageUsedSpaceParams: |
michael@0 | 123 | { |
michael@0 | 124 | DeviceStorageUsedSpaceCache* usedSpaceCache |
michael@0 | 125 | = DeviceStorageUsedSpaceCache::CreateOrGet(); |
michael@0 | 126 | MOZ_ASSERT(usedSpaceCache); |
michael@0 | 127 | |
michael@0 | 128 | DeviceStorageUsedSpaceParams p = mParams; |
michael@0 | 129 | |
michael@0 | 130 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 131 | new DeviceStorageFile(p.type(), p.storageName()); |
michael@0 | 132 | nsRefPtr<UsedSpaceFileEvent> r = new UsedSpaceFileEvent(this, dsf); |
michael@0 | 133 | |
michael@0 | 134 | usedSpaceCache->Dispatch(r); |
michael@0 | 135 | break; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | case DeviceStorageParams::TDeviceStorageAvailableParams: |
michael@0 | 139 | { |
michael@0 | 140 | DeviceStorageAvailableParams p = mParams; |
michael@0 | 141 | |
michael@0 | 142 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 143 | new DeviceStorageFile(p.type(), p.storageName()); |
michael@0 | 144 | nsRefPtr<PostAvailableResultEvent> r |
michael@0 | 145 | = new PostAvailableResultEvent(this, dsf); |
michael@0 | 146 | DebugOnly<nsresult> rv = NS_DispatchToMainThread(r); |
michael@0 | 147 | MOZ_ASSERT(NS_SUCCEEDED(rv)); |
michael@0 | 148 | break; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | case DeviceStorageParams::TDeviceStorageStatusParams: |
michael@0 | 152 | { |
michael@0 | 153 | DeviceStorageStatusParams p = mParams; |
michael@0 | 154 | |
michael@0 | 155 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 156 | new DeviceStorageFile(p.type(), p.storageName()); |
michael@0 | 157 | nsRefPtr<PostStatusResultEvent> r |
michael@0 | 158 | = new PostStatusResultEvent(this, dsf); |
michael@0 | 159 | DebugOnly<nsresult> rv = NS_DispatchToMainThread(r); |
michael@0 | 160 | MOZ_ASSERT(NS_SUCCEEDED(rv)); |
michael@0 | 161 | break; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | case DeviceStorageParams::TDeviceStorageFormatParams: |
michael@0 | 165 | { |
michael@0 | 166 | DeviceStorageFormatParams p = mParams; |
michael@0 | 167 | |
michael@0 | 168 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 169 | new DeviceStorageFile(p.type(), p.storageName()); |
michael@0 | 170 | nsRefPtr<PostFormatResultEvent> r |
michael@0 | 171 | = new PostFormatResultEvent(this, dsf); |
michael@0 | 172 | DebugOnly<nsresult> rv = NS_DispatchToMainThread(r); |
michael@0 | 173 | MOZ_ASSERT(NS_SUCCEEDED(rv)); |
michael@0 | 174 | break; |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | case DeviceStorageParams::TDeviceStorageMountParams: |
michael@0 | 178 | { |
michael@0 | 179 | DeviceStorageMountParams p = mParams; |
michael@0 | 180 | |
michael@0 | 181 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 182 | new DeviceStorageFile(p.type(), p.storageName()); |
michael@0 | 183 | nsRefPtr<PostMountResultEvent> r |
michael@0 | 184 | = new PostMountResultEvent(this, dsf); |
michael@0 | 185 | DebugOnly<nsresult> rv = NS_DispatchToMainThread(r); |
michael@0 | 186 | MOZ_ASSERT(NS_SUCCEEDED(rv)); |
michael@0 | 187 | break; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | case DeviceStorageParams::TDeviceStorageUnmountParams: |
michael@0 | 191 | { |
michael@0 | 192 | DeviceStorageUnmountParams p = mParams; |
michael@0 | 193 | |
michael@0 | 194 | nsRefPtr<DeviceStorageFile> dsf = |
michael@0 | 195 | new DeviceStorageFile(p.type(), p.storageName()); |
michael@0 | 196 | nsRefPtr<PostUnmountResultEvent> r |
michael@0 | 197 | = new PostUnmountResultEvent(this, dsf); |
michael@0 | 198 | DebugOnly<nsresult> rv = NS_DispatchToMainThread(r); |
michael@0 | 199 | MOZ_ASSERT(NS_SUCCEEDED(rv)); |
michael@0 | 200 | break; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | case DeviceStorageParams::TDeviceStorageEnumerationParams: |
michael@0 | 204 | { |
michael@0 | 205 | DeviceStorageEnumerationParams p = mParams; |
michael@0 | 206 | nsRefPtr<DeviceStorageFile> dsf |
michael@0 | 207 | = new DeviceStorageFile(p.type(), p.storageName(), |
michael@0 | 208 | p.rootdir(), NS_LITERAL_STRING("")); |
michael@0 | 209 | nsRefPtr<CancelableRunnable> r |
michael@0 | 210 | = new EnumerateFileEvent(this, dsf, p.since()); |
michael@0 | 211 | |
michael@0 | 212 | nsCOMPtr<nsIEventTarget> target |
michael@0 | 213 | = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); |
michael@0 | 214 | MOZ_ASSERT(target); |
michael@0 | 215 | target->Dispatch(r, NS_DISPATCH_NORMAL); |
michael@0 | 216 | break; |
michael@0 | 217 | } |
michael@0 | 218 | default: |
michael@0 | 219 | { |
michael@0 | 220 | NS_RUNTIMEABORT("not reached"); |
michael@0 | 221 | break; |
michael@0 | 222 | } |
michael@0 | 223 | } |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | bool |
michael@0 | 227 | DeviceStorageRequestParent::EnsureRequiredPermissions( |
michael@0 | 228 | mozilla::dom::ContentParent* aParent) |
michael@0 | 229 | { |
michael@0 | 230 | if (mozilla::Preferences::GetBool("device.storage.testing", false)) { |
michael@0 | 231 | return true; |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | nsString type; |
michael@0 | 235 | DeviceStorageRequestType requestType; |
michael@0 | 236 | |
michael@0 | 237 | switch (mParams.type()) |
michael@0 | 238 | { |
michael@0 | 239 | case DeviceStorageParams::TDeviceStorageAddParams: |
michael@0 | 240 | { |
michael@0 | 241 | DeviceStorageAddParams p = mParams; |
michael@0 | 242 | type = p.type(); |
michael@0 | 243 | requestType = DEVICE_STORAGE_REQUEST_CREATE; |
michael@0 | 244 | break; |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | case DeviceStorageParams::TDeviceStorageCreateFdParams: |
michael@0 | 248 | { |
michael@0 | 249 | DeviceStorageCreateFdParams p = mParams; |
michael@0 | 250 | type = p.type(); |
michael@0 | 251 | requestType = DEVICE_STORAGE_REQUEST_CREATEFD; |
michael@0 | 252 | break; |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | case DeviceStorageParams::TDeviceStorageGetParams: |
michael@0 | 256 | { |
michael@0 | 257 | DeviceStorageGetParams p = mParams; |
michael@0 | 258 | type = p.type(); |
michael@0 | 259 | requestType = DEVICE_STORAGE_REQUEST_READ; |
michael@0 | 260 | break; |
michael@0 | 261 | } |
michael@0 | 262 | |
michael@0 | 263 | case DeviceStorageParams::TDeviceStorageDeleteParams: |
michael@0 | 264 | { |
michael@0 | 265 | DeviceStorageDeleteParams p = mParams; |
michael@0 | 266 | type = p.type(); |
michael@0 | 267 | requestType = DEVICE_STORAGE_REQUEST_DELETE; |
michael@0 | 268 | break; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | case DeviceStorageParams::TDeviceStorageFreeSpaceParams: |
michael@0 | 272 | { |
michael@0 | 273 | DeviceStorageFreeSpaceParams p = mParams; |
michael@0 | 274 | type = p.type(); |
michael@0 | 275 | requestType = DEVICE_STORAGE_REQUEST_FREE_SPACE; |
michael@0 | 276 | break; |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | case DeviceStorageParams::TDeviceStorageUsedSpaceParams: |
michael@0 | 280 | { |
michael@0 | 281 | DeviceStorageUsedSpaceParams p = mParams; |
michael@0 | 282 | type = p.type(); |
michael@0 | 283 | requestType = DEVICE_STORAGE_REQUEST_FREE_SPACE; |
michael@0 | 284 | break; |
michael@0 | 285 | } |
michael@0 | 286 | |
michael@0 | 287 | case DeviceStorageParams::TDeviceStorageAvailableParams: |
michael@0 | 288 | { |
michael@0 | 289 | DeviceStorageAvailableParams p = mParams; |
michael@0 | 290 | type = p.type(); |
michael@0 | 291 | requestType = DEVICE_STORAGE_REQUEST_AVAILABLE; |
michael@0 | 292 | break; |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | case DeviceStorageParams::TDeviceStorageStatusParams: |
michael@0 | 296 | { |
michael@0 | 297 | DeviceStorageStatusParams p = mParams; |
michael@0 | 298 | type = p.type(); |
michael@0 | 299 | requestType = DEVICE_STORAGE_REQUEST_STATUS; |
michael@0 | 300 | break; |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | case DeviceStorageParams::TDeviceStorageFormatParams: |
michael@0 | 304 | { |
michael@0 | 305 | DeviceStorageFormatParams p = mParams; |
michael@0 | 306 | type = p.type(); |
michael@0 | 307 | requestType = DEVICE_STORAGE_REQUEST_FORMAT; |
michael@0 | 308 | break; |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | case DeviceStorageParams::TDeviceStorageMountParams: |
michael@0 | 312 | { |
michael@0 | 313 | DeviceStorageMountParams p = mParams; |
michael@0 | 314 | type = p.type(); |
michael@0 | 315 | requestType = DEVICE_STORAGE_REQUEST_MOUNT; |
michael@0 | 316 | break; |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | case DeviceStorageParams::TDeviceStorageUnmountParams: |
michael@0 | 320 | { |
michael@0 | 321 | DeviceStorageUnmountParams p = mParams; |
michael@0 | 322 | type = p.type(); |
michael@0 | 323 | requestType = DEVICE_STORAGE_REQUEST_UNMOUNT; |
michael@0 | 324 | break; |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | case DeviceStorageParams::TDeviceStorageEnumerationParams: |
michael@0 | 328 | { |
michael@0 | 329 | DeviceStorageEnumerationParams p = mParams; |
michael@0 | 330 | type = p.type(); |
michael@0 | 331 | requestType = DEVICE_STORAGE_REQUEST_READ; |
michael@0 | 332 | break; |
michael@0 | 333 | } |
michael@0 | 334 | |
michael@0 | 335 | default: |
michael@0 | 336 | { |
michael@0 | 337 | return false; |
michael@0 | 338 | } |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | // The 'apps' type is special. We only want this exposed |
michael@0 | 342 | // if the caller has the "webapps-manage" permission. |
michael@0 | 343 | if (type.EqualsLiteral("apps")) { |
michael@0 | 344 | if (!AssertAppProcessPermission(aParent, "webapps-manage")) { |
michael@0 | 345 | return false; |
michael@0 | 346 | } |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | nsAutoCString permissionName; |
michael@0 | 350 | nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type, |
michael@0 | 351 | permissionName); |
michael@0 | 352 | if (NS_FAILED(rv)) { |
michael@0 | 353 | return false; |
michael@0 | 354 | } |
michael@0 | 355 | |
michael@0 | 356 | nsCString access; |
michael@0 | 357 | rv = DeviceStorageTypeChecker::GetAccessForRequest(requestType, access); |
michael@0 | 358 | if (NS_FAILED(rv)) { |
michael@0 | 359 | return false; |
michael@0 | 360 | } |
michael@0 | 361 | |
michael@0 | 362 | permissionName.AppendLiteral("-"); |
michael@0 | 363 | permissionName.Append(access); |
michael@0 | 364 | |
michael@0 | 365 | if (!AssertAppProcessPermission(aParent, permissionName.get())) { |
michael@0 | 366 | return false; |
michael@0 | 367 | } |
michael@0 | 368 | |
michael@0 | 369 | return true; |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | DeviceStorageRequestParent::~DeviceStorageRequestParent() |
michael@0 | 373 | { |
michael@0 | 374 | MOZ_COUNT_DTOR(DeviceStorageRequestParent); |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | NS_IMPL_ADDREF(DeviceStorageRequestParent) |
michael@0 | 378 | NS_IMPL_RELEASE(DeviceStorageRequestParent) |
michael@0 | 379 | |
michael@0 | 380 | void |
michael@0 | 381 | DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason) |
michael@0 | 382 | { |
michael@0 | 383 | MutexAutoLock lock(mMutex); |
michael@0 | 384 | mActorDestoryed = true; |
michael@0 | 385 | int32_t count = mRunnables.Length(); |
michael@0 | 386 | for (int32_t index = 0; index < count; index++) { |
michael@0 | 387 | mRunnables[index]->Cancel(); |
michael@0 | 388 | } |
michael@0 | 389 | } |
michael@0 | 390 | |
michael@0 | 391 | DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent( |
michael@0 | 392 | DeviceStorageRequestParent* aParent, |
michael@0 | 393 | uint64_t aFreeSpace) |
michael@0 | 394 | : CancelableRunnable(aParent) |
michael@0 | 395 | , mFreeSpace(aFreeSpace) |
michael@0 | 396 | { |
michael@0 | 397 | } |
michael@0 | 398 | |
michael@0 | 399 | DeviceStorageRequestParent::PostFreeSpaceResultEvent:: |
michael@0 | 400 | ~PostFreeSpaceResultEvent() {} |
michael@0 | 401 | |
michael@0 | 402 | nsresult |
michael@0 | 403 | DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() { |
michael@0 | 404 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 405 | |
michael@0 | 406 | FreeSpaceStorageResponse response(mFreeSpace); |
michael@0 | 407 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 408 | return NS_OK; |
michael@0 | 409 | } |
michael@0 | 410 | |
michael@0 | 411 | DeviceStorageRequestParent::PostUsedSpaceResultEvent:: |
michael@0 | 412 | PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 413 | const nsAString& aType, |
michael@0 | 414 | uint64_t aUsedSpace) |
michael@0 | 415 | : CancelableRunnable(aParent) |
michael@0 | 416 | , mType(aType) |
michael@0 | 417 | , mUsedSpace(aUsedSpace) |
michael@0 | 418 | { |
michael@0 | 419 | } |
michael@0 | 420 | |
michael@0 | 421 | DeviceStorageRequestParent::PostUsedSpaceResultEvent:: |
michael@0 | 422 | ~PostUsedSpaceResultEvent() {} |
michael@0 | 423 | |
michael@0 | 424 | nsresult |
michael@0 | 425 | DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() { |
michael@0 | 426 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 427 | |
michael@0 | 428 | UsedSpaceStorageResponse response(mUsedSpace); |
michael@0 | 429 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 430 | return NS_OK; |
michael@0 | 431 | } |
michael@0 | 432 | |
michael@0 | 433 | DeviceStorageRequestParent::PostErrorEvent:: |
michael@0 | 434 | PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError) |
michael@0 | 435 | : CancelableRunnable(aParent) |
michael@0 | 436 | { |
michael@0 | 437 | CopyASCIItoUTF16(aError, mError); |
michael@0 | 438 | } |
michael@0 | 439 | |
michael@0 | 440 | DeviceStorageRequestParent::PostErrorEvent::~PostErrorEvent() {} |
michael@0 | 441 | |
michael@0 | 442 | nsresult |
michael@0 | 443 | DeviceStorageRequestParent::PostErrorEvent::CancelableRun() { |
michael@0 | 444 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 445 | |
michael@0 | 446 | ErrorResponse response(mError); |
michael@0 | 447 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 448 | return NS_OK; |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | DeviceStorageRequestParent::PostSuccessEvent:: |
michael@0 | 452 | PostSuccessEvent(DeviceStorageRequestParent* aParent) |
michael@0 | 453 | : CancelableRunnable(aParent) |
michael@0 | 454 | { |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | DeviceStorageRequestParent::PostSuccessEvent::~PostSuccessEvent() {} |
michael@0 | 458 | |
michael@0 | 459 | nsresult |
michael@0 | 460 | DeviceStorageRequestParent::PostSuccessEvent::CancelableRun() { |
michael@0 | 461 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 462 | |
michael@0 | 463 | SuccessResponse response; |
michael@0 | 464 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 465 | return NS_OK; |
michael@0 | 466 | } |
michael@0 | 467 | |
michael@0 | 468 | DeviceStorageRequestParent::PostBlobSuccessEvent:: |
michael@0 | 469 | PostBlobSuccessEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 470 | DeviceStorageFile* aFile, |
michael@0 | 471 | uint32_t aLength, |
michael@0 | 472 | nsACString& aMimeType, |
michael@0 | 473 | uint64_t aLastModifiedDate) |
michael@0 | 474 | : CancelableRunnable(aParent) |
michael@0 | 475 | , mLength(aLength) |
michael@0 | 476 | , mLastModificationDate(aLastModifiedDate) |
michael@0 | 477 | , mFile(aFile) |
michael@0 | 478 | , mMimeType(aMimeType) |
michael@0 | 479 | { |
michael@0 | 480 | } |
michael@0 | 481 | |
michael@0 | 482 | DeviceStorageRequestParent::PostBlobSuccessEvent::~PostBlobSuccessEvent() {} |
michael@0 | 483 | |
michael@0 | 484 | nsresult |
michael@0 | 485 | DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() { |
michael@0 | 486 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 487 | |
michael@0 | 488 | nsString mime; |
michael@0 | 489 | CopyASCIItoUTF16(mMimeType, mime); |
michael@0 | 490 | |
michael@0 | 491 | nsString fullPath; |
michael@0 | 492 | mFile->GetFullPath(fullPath); |
michael@0 | 493 | nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(fullPath, mime, mLength, |
michael@0 | 494 | mFile->mFile, |
michael@0 | 495 | mLastModificationDate); |
michael@0 | 496 | |
michael@0 | 497 | ContentParent* cp = static_cast<ContentParent*>(mParent->Manager()); |
michael@0 | 498 | BlobParent* actor = cp->GetOrCreateActorForBlob(blob); |
michael@0 | 499 | if (!actor) { |
michael@0 | 500 | ErrorResponse response(NS_LITERAL_STRING(POST_ERROR_EVENT_UNKNOWN)); |
michael@0 | 501 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 502 | return NS_OK; |
michael@0 | 503 | } |
michael@0 | 504 | |
michael@0 | 505 | BlobResponse response; |
michael@0 | 506 | response.blobParent() = actor; |
michael@0 | 507 | |
michael@0 | 508 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 509 | return NS_OK; |
michael@0 | 510 | } |
michael@0 | 511 | |
michael@0 | 512 | DeviceStorageRequestParent::PostEnumerationSuccessEvent:: |
michael@0 | 513 | PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 514 | const nsAString& aStorageType, |
michael@0 | 515 | const nsAString& aRelPath, |
michael@0 | 516 | InfallibleTArray<DeviceStorageFileValue>& aPaths) |
michael@0 | 517 | : CancelableRunnable(aParent) |
michael@0 | 518 | , mStorageType(aStorageType) |
michael@0 | 519 | , mRelPath(aRelPath) |
michael@0 | 520 | , mPaths(aPaths) |
michael@0 | 521 | { |
michael@0 | 522 | } |
michael@0 | 523 | |
michael@0 | 524 | DeviceStorageRequestParent::PostEnumerationSuccessEvent:: |
michael@0 | 525 | ~PostEnumerationSuccessEvent() {} |
michael@0 | 526 | |
michael@0 | 527 | nsresult |
michael@0 | 528 | DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() { |
michael@0 | 529 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 530 | |
michael@0 | 531 | EnumerationResponse response(mStorageType, mRelPath, mPaths); |
michael@0 | 532 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 533 | return NS_OK; |
michael@0 | 534 | } |
michael@0 | 535 | |
michael@0 | 536 | DeviceStorageRequestParent::CreateFdEvent:: |
michael@0 | 537 | CreateFdEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 538 | DeviceStorageFile* aFile) |
michael@0 | 539 | : CancelableRunnable(aParent) |
michael@0 | 540 | , mFile(aFile) |
michael@0 | 541 | { |
michael@0 | 542 | } |
michael@0 | 543 | |
michael@0 | 544 | DeviceStorageRequestParent::CreateFdEvent::~CreateFdEvent() |
michael@0 | 545 | { |
michael@0 | 546 | } |
michael@0 | 547 | |
michael@0 | 548 | nsresult |
michael@0 | 549 | DeviceStorageRequestParent::CreateFdEvent::CancelableRun() |
michael@0 | 550 | { |
michael@0 | 551 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 552 | |
michael@0 | 553 | nsCOMPtr<nsIRunnable> r; |
michael@0 | 554 | |
michael@0 | 555 | bool check = false; |
michael@0 | 556 | mFile->mFile->Exists(&check); |
michael@0 | 557 | if (check) { |
michael@0 | 558 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS); |
michael@0 | 559 | return NS_DispatchToMainThread(r); |
michael@0 | 560 | } |
michael@0 | 561 | |
michael@0 | 562 | FileDescriptor fileDescriptor; |
michael@0 | 563 | nsresult rv = mFile->CreateFileDescriptor(fileDescriptor); |
michael@0 | 564 | if (NS_FAILED(rv)) { |
michael@0 | 565 | NS_WARNING("CreateFileDescriptor failed"); |
michael@0 | 566 | mFile->Dump("CreateFileDescriptor failed"); |
michael@0 | 567 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN); |
michael@0 | 568 | } |
michael@0 | 569 | else { |
michael@0 | 570 | r = new PostFileDescriptorResultEvent(mParent, fileDescriptor); |
michael@0 | 571 | } |
michael@0 | 572 | |
michael@0 | 573 | return NS_DispatchToMainThread(r); |
michael@0 | 574 | } |
michael@0 | 575 | |
michael@0 | 576 | DeviceStorageRequestParent::WriteFileEvent:: |
michael@0 | 577 | WriteFileEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 578 | DeviceStorageFile* aFile, |
michael@0 | 579 | nsIInputStream* aInputStream) |
michael@0 | 580 | : CancelableRunnable(aParent) |
michael@0 | 581 | , mFile(aFile) |
michael@0 | 582 | , mInputStream(aInputStream) |
michael@0 | 583 | { |
michael@0 | 584 | } |
michael@0 | 585 | |
michael@0 | 586 | DeviceStorageRequestParent::WriteFileEvent::~WriteFileEvent() |
michael@0 | 587 | { |
michael@0 | 588 | } |
michael@0 | 589 | |
michael@0 | 590 | nsresult |
michael@0 | 591 | DeviceStorageRequestParent::WriteFileEvent::CancelableRun() |
michael@0 | 592 | { |
michael@0 | 593 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 594 | |
michael@0 | 595 | nsCOMPtr<nsIRunnable> r; |
michael@0 | 596 | |
michael@0 | 597 | if (!mInputStream) { |
michael@0 | 598 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN); |
michael@0 | 599 | return NS_DispatchToMainThread(r); |
michael@0 | 600 | } |
michael@0 | 601 | |
michael@0 | 602 | bool check = false; |
michael@0 | 603 | mFile->mFile->Exists(&check); |
michael@0 | 604 | if (check) { |
michael@0 | 605 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS); |
michael@0 | 606 | return NS_DispatchToMainThread(r); |
michael@0 | 607 | } |
michael@0 | 608 | |
michael@0 | 609 | nsresult rv = mFile->Write(mInputStream); |
michael@0 | 610 | |
michael@0 | 611 | if (NS_FAILED(rv)) { |
michael@0 | 612 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN); |
michael@0 | 613 | } |
michael@0 | 614 | else { |
michael@0 | 615 | r = new PostPathResultEvent(mParent, mFile->mPath); |
michael@0 | 616 | } |
michael@0 | 617 | |
michael@0 | 618 | return NS_DispatchToMainThread(r); |
michael@0 | 619 | } |
michael@0 | 620 | |
michael@0 | 621 | DeviceStorageRequestParent::DeleteFileEvent:: |
michael@0 | 622 | DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile) |
michael@0 | 623 | : CancelableRunnable(aParent) |
michael@0 | 624 | , mFile(aFile) |
michael@0 | 625 | { |
michael@0 | 626 | } |
michael@0 | 627 | |
michael@0 | 628 | DeviceStorageRequestParent::DeleteFileEvent::~DeleteFileEvent() |
michael@0 | 629 | { |
michael@0 | 630 | } |
michael@0 | 631 | |
michael@0 | 632 | nsresult |
michael@0 | 633 | DeviceStorageRequestParent::DeleteFileEvent::CancelableRun() |
michael@0 | 634 | { |
michael@0 | 635 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 636 | |
michael@0 | 637 | mFile->Remove(); |
michael@0 | 638 | |
michael@0 | 639 | nsCOMPtr<nsIRunnable> r; |
michael@0 | 640 | |
michael@0 | 641 | bool check = false; |
michael@0 | 642 | mFile->mFile->Exists(&check); |
michael@0 | 643 | if (check) { |
michael@0 | 644 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN); |
michael@0 | 645 | } |
michael@0 | 646 | else { |
michael@0 | 647 | r = new PostPathResultEvent(mParent, mFile->mPath); |
michael@0 | 648 | } |
michael@0 | 649 | |
michael@0 | 650 | return NS_DispatchToMainThread(r); |
michael@0 | 651 | } |
michael@0 | 652 | |
michael@0 | 653 | DeviceStorageRequestParent::FreeSpaceFileEvent:: |
michael@0 | 654 | FreeSpaceFileEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 655 | DeviceStorageFile* aFile) |
michael@0 | 656 | : CancelableRunnable(aParent) |
michael@0 | 657 | , mFile(aFile) |
michael@0 | 658 | { |
michael@0 | 659 | } |
michael@0 | 660 | |
michael@0 | 661 | DeviceStorageRequestParent::FreeSpaceFileEvent::~FreeSpaceFileEvent() |
michael@0 | 662 | { |
michael@0 | 663 | } |
michael@0 | 664 | |
michael@0 | 665 | nsresult |
michael@0 | 666 | DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun() |
michael@0 | 667 | { |
michael@0 | 668 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 669 | |
michael@0 | 670 | int64_t freeSpace = 0; |
michael@0 | 671 | if (mFile) { |
michael@0 | 672 | mFile->GetDiskFreeSpace(&freeSpace); |
michael@0 | 673 | } |
michael@0 | 674 | |
michael@0 | 675 | nsCOMPtr<nsIRunnable> r; |
michael@0 | 676 | r = new PostFreeSpaceResultEvent(mParent, static_cast<uint64_t>(freeSpace)); |
michael@0 | 677 | return NS_DispatchToMainThread(r); |
michael@0 | 678 | } |
michael@0 | 679 | |
michael@0 | 680 | DeviceStorageRequestParent::UsedSpaceFileEvent:: |
michael@0 | 681 | UsedSpaceFileEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 682 | DeviceStorageFile* aFile) |
michael@0 | 683 | : CancelableRunnable(aParent) |
michael@0 | 684 | , mFile(aFile) |
michael@0 | 685 | { |
michael@0 | 686 | } |
michael@0 | 687 | |
michael@0 | 688 | DeviceStorageRequestParent::UsedSpaceFileEvent::~UsedSpaceFileEvent() |
michael@0 | 689 | { |
michael@0 | 690 | } |
michael@0 | 691 | |
michael@0 | 692 | nsresult |
michael@0 | 693 | DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun() |
michael@0 | 694 | { |
michael@0 | 695 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 696 | |
michael@0 | 697 | uint64_t picturesUsage = 0, videosUsage = 0, musicUsage = 0, totalUsage = 0; |
michael@0 | 698 | mFile->AccumDiskUsage(&picturesUsage, &videosUsage, |
michael@0 | 699 | &musicUsage, &totalUsage); |
michael@0 | 700 | nsCOMPtr<nsIRunnable> r; |
michael@0 | 701 | if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_PICTURES)) { |
michael@0 | 702 | r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, |
michael@0 | 703 | picturesUsage); |
michael@0 | 704 | } |
michael@0 | 705 | else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) { |
michael@0 | 706 | r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, videosUsage); |
michael@0 | 707 | } |
michael@0 | 708 | else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_MUSIC)) { |
michael@0 | 709 | r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, musicUsage); |
michael@0 | 710 | } else { |
michael@0 | 711 | r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, totalUsage); |
michael@0 | 712 | } |
michael@0 | 713 | return NS_DispatchToMainThread(r); |
michael@0 | 714 | } |
michael@0 | 715 | |
michael@0 | 716 | DeviceStorageRequestParent::ReadFileEvent:: |
michael@0 | 717 | ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile) |
michael@0 | 718 | : CancelableRunnable(aParent) |
michael@0 | 719 | , mFile(aFile) |
michael@0 | 720 | { |
michael@0 | 721 | nsCOMPtr<nsIMIMEService> mimeService |
michael@0 | 722 | = do_GetService(NS_MIMESERVICE_CONTRACTID); |
michael@0 | 723 | if (mimeService) { |
michael@0 | 724 | nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType); |
michael@0 | 725 | if (NS_FAILED(rv)) { |
michael@0 | 726 | mMimeType.Truncate(); |
michael@0 | 727 | } |
michael@0 | 728 | } |
michael@0 | 729 | } |
michael@0 | 730 | |
michael@0 | 731 | DeviceStorageRequestParent::ReadFileEvent::~ReadFileEvent() |
michael@0 | 732 | { |
michael@0 | 733 | } |
michael@0 | 734 | |
michael@0 | 735 | nsresult |
michael@0 | 736 | DeviceStorageRequestParent::ReadFileEvent::CancelableRun() |
michael@0 | 737 | { |
michael@0 | 738 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 739 | |
michael@0 | 740 | nsCOMPtr<nsIRunnable> r; |
michael@0 | 741 | bool check = false; |
michael@0 | 742 | mFile->mFile->Exists(&check); |
michael@0 | 743 | |
michael@0 | 744 | if (!check) { |
michael@0 | 745 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); |
michael@0 | 746 | return NS_DispatchToMainThread(r); |
michael@0 | 747 | } |
michael@0 | 748 | |
michael@0 | 749 | int64_t fileSize; |
michael@0 | 750 | nsresult rv = mFile->mFile->GetFileSize(&fileSize); |
michael@0 | 751 | if (NS_FAILED(rv)) { |
michael@0 | 752 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN); |
michael@0 | 753 | return NS_DispatchToMainThread(r); |
michael@0 | 754 | } |
michael@0 | 755 | |
michael@0 | 756 | PRTime modDate; |
michael@0 | 757 | rv = mFile->mFile->GetLastModifiedTime(&modDate); |
michael@0 | 758 | if (NS_FAILED(rv)) { |
michael@0 | 759 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_UNKNOWN); |
michael@0 | 760 | return NS_DispatchToMainThread(r); |
michael@0 | 761 | } |
michael@0 | 762 | |
michael@0 | 763 | r = new PostBlobSuccessEvent(mParent, mFile, static_cast<uint64_t>(fileSize), |
michael@0 | 764 | mMimeType, modDate); |
michael@0 | 765 | return NS_DispatchToMainThread(r); |
michael@0 | 766 | } |
michael@0 | 767 | |
michael@0 | 768 | DeviceStorageRequestParent::EnumerateFileEvent:: |
michael@0 | 769 | EnumerateFileEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 770 | DeviceStorageFile* aFile, |
michael@0 | 771 | uint64_t aSince) |
michael@0 | 772 | : CancelableRunnable(aParent) |
michael@0 | 773 | , mFile(aFile) |
michael@0 | 774 | , mSince(aSince) |
michael@0 | 775 | { |
michael@0 | 776 | } |
michael@0 | 777 | |
michael@0 | 778 | DeviceStorageRequestParent::EnumerateFileEvent::~EnumerateFileEvent() |
michael@0 | 779 | { |
michael@0 | 780 | } |
michael@0 | 781 | |
michael@0 | 782 | nsresult |
michael@0 | 783 | DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun() |
michael@0 | 784 | { |
michael@0 | 785 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 786 | |
michael@0 | 787 | nsCOMPtr<nsIRunnable> r; |
michael@0 | 788 | if (mFile->mFile) { |
michael@0 | 789 | bool check = false; |
michael@0 | 790 | mFile->mFile->Exists(&check); |
michael@0 | 791 | if (!check) { |
michael@0 | 792 | r = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST); |
michael@0 | 793 | return NS_DispatchToMainThread(r); |
michael@0 | 794 | } |
michael@0 | 795 | } |
michael@0 | 796 | |
michael@0 | 797 | nsTArray<nsRefPtr<DeviceStorageFile> > files; |
michael@0 | 798 | mFile->CollectFiles(files, mSince); |
michael@0 | 799 | |
michael@0 | 800 | InfallibleTArray<DeviceStorageFileValue> values; |
michael@0 | 801 | |
michael@0 | 802 | uint32_t count = files.Length(); |
michael@0 | 803 | for (uint32_t i = 0; i < count; i++) { |
michael@0 | 804 | DeviceStorageFileValue dsvf(files[i]->mStorageName, files[i]->mPath); |
michael@0 | 805 | values.AppendElement(dsvf); |
michael@0 | 806 | } |
michael@0 | 807 | |
michael@0 | 808 | r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType, |
michael@0 | 809 | mFile->mRootDir, values); |
michael@0 | 810 | return NS_DispatchToMainThread(r); |
michael@0 | 811 | } |
michael@0 | 812 | |
michael@0 | 813 | |
michael@0 | 814 | DeviceStorageRequestParent::PostPathResultEvent:: |
michael@0 | 815 | PostPathResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 816 | const nsAString& aPath) |
michael@0 | 817 | : CancelableRunnable(aParent) |
michael@0 | 818 | , mPath(aPath) |
michael@0 | 819 | { |
michael@0 | 820 | } |
michael@0 | 821 | |
michael@0 | 822 | DeviceStorageRequestParent::PostPathResultEvent::~PostPathResultEvent() |
michael@0 | 823 | { |
michael@0 | 824 | } |
michael@0 | 825 | |
michael@0 | 826 | nsresult |
michael@0 | 827 | DeviceStorageRequestParent::PostPathResultEvent::CancelableRun() |
michael@0 | 828 | { |
michael@0 | 829 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 830 | |
michael@0 | 831 | SuccessResponse response; |
michael@0 | 832 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 833 | return NS_OK; |
michael@0 | 834 | } |
michael@0 | 835 | |
michael@0 | 836 | DeviceStorageRequestParent::PostFileDescriptorResultEvent:: |
michael@0 | 837 | PostFileDescriptorResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 838 | const FileDescriptor& aFileDescriptor) |
michael@0 | 839 | : CancelableRunnable(aParent) |
michael@0 | 840 | , mFileDescriptor(aFileDescriptor) |
michael@0 | 841 | { |
michael@0 | 842 | } |
michael@0 | 843 | |
michael@0 | 844 | DeviceStorageRequestParent::PostFileDescriptorResultEvent:: |
michael@0 | 845 | ~PostFileDescriptorResultEvent() |
michael@0 | 846 | { |
michael@0 | 847 | } |
michael@0 | 848 | |
michael@0 | 849 | nsresult |
michael@0 | 850 | DeviceStorageRequestParent::PostFileDescriptorResultEvent::CancelableRun() |
michael@0 | 851 | { |
michael@0 | 852 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 853 | |
michael@0 | 854 | FileDescriptorResponse response(mFileDescriptor); |
michael@0 | 855 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 856 | return NS_OK; |
michael@0 | 857 | } |
michael@0 | 858 | |
michael@0 | 859 | DeviceStorageRequestParent::PostAvailableResultEvent:: |
michael@0 | 860 | PostAvailableResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 861 | DeviceStorageFile* aFile) |
michael@0 | 862 | : CancelableRunnable(aParent) |
michael@0 | 863 | , mFile(aFile) |
michael@0 | 864 | { |
michael@0 | 865 | } |
michael@0 | 866 | |
michael@0 | 867 | DeviceStorageRequestParent::PostAvailableResultEvent:: |
michael@0 | 868 | ~PostAvailableResultEvent() |
michael@0 | 869 | { |
michael@0 | 870 | } |
michael@0 | 871 | |
michael@0 | 872 | nsresult |
michael@0 | 873 | DeviceStorageRequestParent::PostAvailableResultEvent::CancelableRun() |
michael@0 | 874 | { |
michael@0 | 875 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 876 | |
michael@0 | 877 | nsString state = NS_LITERAL_STRING("unavailable"); |
michael@0 | 878 | if (mFile) { |
michael@0 | 879 | mFile->GetStatus(state); |
michael@0 | 880 | } |
michael@0 | 881 | |
michael@0 | 882 | AvailableStorageResponse response(state); |
michael@0 | 883 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 884 | return NS_OK; |
michael@0 | 885 | } |
michael@0 | 886 | |
michael@0 | 887 | DeviceStorageRequestParent::PostStatusResultEvent:: |
michael@0 | 888 | PostStatusResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 889 | DeviceStorageFile* aFile) |
michael@0 | 890 | : CancelableRunnable(aParent) |
michael@0 | 891 | , mFile(aFile) |
michael@0 | 892 | { |
michael@0 | 893 | } |
michael@0 | 894 | |
michael@0 | 895 | DeviceStorageRequestParent::PostStatusResultEvent:: |
michael@0 | 896 | ~PostStatusResultEvent() |
michael@0 | 897 | { |
michael@0 | 898 | } |
michael@0 | 899 | |
michael@0 | 900 | nsresult |
michael@0 | 901 | DeviceStorageRequestParent::PostStatusResultEvent::CancelableRun() |
michael@0 | 902 | { |
michael@0 | 903 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 904 | |
michael@0 | 905 | nsString state = NS_LITERAL_STRING("undefined"); |
michael@0 | 906 | if (mFile) { |
michael@0 | 907 | mFile->GetStorageStatus(state); |
michael@0 | 908 | } |
michael@0 | 909 | |
michael@0 | 910 | StorageStatusResponse response(state); |
michael@0 | 911 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 912 | return NS_OK; |
michael@0 | 913 | } |
michael@0 | 914 | |
michael@0 | 915 | DeviceStorageRequestParent::PostFormatResultEvent:: |
michael@0 | 916 | PostFormatResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 917 | DeviceStorageFile* aFile) |
michael@0 | 918 | : CancelableRunnable(aParent) |
michael@0 | 919 | , mFile(aFile) |
michael@0 | 920 | { |
michael@0 | 921 | } |
michael@0 | 922 | |
michael@0 | 923 | DeviceStorageRequestParent::PostFormatResultEvent:: |
michael@0 | 924 | ~PostFormatResultEvent() |
michael@0 | 925 | { |
michael@0 | 926 | } |
michael@0 | 927 | |
michael@0 | 928 | nsresult |
michael@0 | 929 | DeviceStorageRequestParent::PostFormatResultEvent::CancelableRun() |
michael@0 | 930 | { |
michael@0 | 931 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 932 | |
michael@0 | 933 | nsString state = NS_LITERAL_STRING("unavailable"); |
michael@0 | 934 | if (mFile) { |
michael@0 | 935 | mFile->DoFormat(state); |
michael@0 | 936 | } |
michael@0 | 937 | |
michael@0 | 938 | FormatStorageResponse response(state); |
michael@0 | 939 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 940 | return NS_OK; |
michael@0 | 941 | } |
michael@0 | 942 | |
michael@0 | 943 | DeviceStorageRequestParent::PostMountResultEvent:: |
michael@0 | 944 | PostMountResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 945 | DeviceStorageFile* aFile) |
michael@0 | 946 | : CancelableRunnable(aParent) |
michael@0 | 947 | , mFile(aFile) |
michael@0 | 948 | { |
michael@0 | 949 | } |
michael@0 | 950 | |
michael@0 | 951 | DeviceStorageRequestParent::PostMountResultEvent:: |
michael@0 | 952 | ~PostMountResultEvent() |
michael@0 | 953 | { |
michael@0 | 954 | } |
michael@0 | 955 | |
michael@0 | 956 | nsresult |
michael@0 | 957 | DeviceStorageRequestParent::PostMountResultEvent::CancelableRun() |
michael@0 | 958 | { |
michael@0 | 959 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 960 | |
michael@0 | 961 | nsString state = NS_LITERAL_STRING("unavailable"); |
michael@0 | 962 | if (mFile) { |
michael@0 | 963 | mFile->DoMount(state); |
michael@0 | 964 | } |
michael@0 | 965 | |
michael@0 | 966 | MountStorageResponse response(state); |
michael@0 | 967 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 968 | return NS_OK; |
michael@0 | 969 | } |
michael@0 | 970 | |
michael@0 | 971 | DeviceStorageRequestParent::PostUnmountResultEvent:: |
michael@0 | 972 | PostUnmountResultEvent(DeviceStorageRequestParent* aParent, |
michael@0 | 973 | DeviceStorageFile* aFile) |
michael@0 | 974 | : CancelableRunnable(aParent) |
michael@0 | 975 | , mFile(aFile) |
michael@0 | 976 | { |
michael@0 | 977 | } |
michael@0 | 978 | |
michael@0 | 979 | DeviceStorageRequestParent::PostUnmountResultEvent:: |
michael@0 | 980 | ~PostUnmountResultEvent() |
michael@0 | 981 | { |
michael@0 | 982 | } |
michael@0 | 983 | |
michael@0 | 984 | nsresult |
michael@0 | 985 | DeviceStorageRequestParent::PostUnmountResultEvent::CancelableRun() |
michael@0 | 986 | { |
michael@0 | 987 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 988 | |
michael@0 | 989 | nsString state = NS_LITERAL_STRING("unavailable"); |
michael@0 | 990 | if (mFile) { |
michael@0 | 991 | mFile->DoUnmount(state); |
michael@0 | 992 | } |
michael@0 | 993 | |
michael@0 | 994 | UnmountStorageResponse response(state); |
michael@0 | 995 | unused << mParent->Send__delete__(mParent, response); |
michael@0 | 996 | return NS_OK; |
michael@0 | 997 | } |
michael@0 | 998 | |
michael@0 | 999 | } // namespace devicestorage |
michael@0 | 1000 | } // namespace dom |
michael@0 | 1001 | } // namespace mozilla |