1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/file/MetadataHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_file_metadatahelper_h__ 1.11 +#define mozilla_dom_file_metadatahelper_h__ 1.12 + 1.13 +#include "mozilla/Attributes.h" 1.14 +#include "FileCommon.h" 1.15 + 1.16 +#include "nsIFileStreams.h" 1.17 + 1.18 +#include "AsyncHelper.h" 1.19 +#include "FileHelper.h" 1.20 + 1.21 +class nsIFileStream; 1.22 + 1.23 +BEGIN_FILE_NAMESPACE 1.24 + 1.25 +class MetadataHelper; 1.26 + 1.27 +class MetadataParameters MOZ_FINAL 1.28 +{ 1.29 + friend class MetadataHelper; 1.30 + 1.31 +public: 1.32 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MetadataParameters) 1.33 + 1.34 + MetadataParameters(bool aSizeRequested, bool aLastModifiedRequested) 1.35 + : mSizeRequested(aSizeRequested) 1.36 + , mLastModifiedRequested(aLastModifiedRequested) 1.37 + { 1.38 + } 1.39 + 1.40 + bool 1.41 + IsConfigured() const 1.42 + { 1.43 + return mSizeRequested || mLastModifiedRequested; 1.44 + } 1.45 + 1.46 + bool 1.47 + SizeRequested() const 1.48 + { 1.49 + return mSizeRequested; 1.50 + } 1.51 + 1.52 + bool 1.53 + LastModifiedRequested() const 1.54 + { 1.55 + return mLastModifiedRequested; 1.56 + } 1.57 + 1.58 + uint64_t 1.59 + Size() const 1.60 + { 1.61 + return mSize; 1.62 + } 1.63 + 1.64 + int64_t 1.65 + LastModified() const 1.66 + { 1.67 + return mLastModified; 1.68 + } 1.69 + 1.70 +private: 1.71 + // Private destructor, to discourage deletion outside of Release(): 1.72 + ~MetadataParameters() 1.73 + { 1.74 + } 1.75 + 1.76 + uint64_t mSize; 1.77 + int64_t mLastModified; 1.78 + bool mSizeRequested; 1.79 + bool mLastModifiedRequested; 1.80 +}; 1.81 + 1.82 +class MetadataHelper : public FileHelper 1.83 +{ 1.84 +public: 1.85 + MetadataHelper(LockedFile* aLockedFile, 1.86 + FileRequest* aFileRequest, 1.87 + MetadataParameters* aParams) 1.88 + : FileHelper(aLockedFile, aFileRequest), 1.89 + mParams(aParams) 1.90 + { } 1.91 + 1.92 + nsresult 1.93 + DoAsyncRun(nsISupports* aStream) MOZ_OVERRIDE; 1.94 + 1.95 + nsresult 1.96 + GetSuccessResult(JSContext* aCx, 1.97 + JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE; 1.98 + 1.99 +protected: 1.100 + class AsyncMetadataGetter : public AsyncHelper 1.101 + { 1.102 + public: 1.103 + AsyncMetadataGetter(nsISupports* aStream, MetadataParameters* aParams, 1.104 + bool aReadWrite) 1.105 + : AsyncHelper(aStream), 1.106 + mParams(aParams), mReadWrite(aReadWrite) 1.107 + { } 1.108 + 1.109 + protected: 1.110 + nsresult 1.111 + DoStreamWork(nsISupports* aStream) MOZ_OVERRIDE; 1.112 + 1.113 + private: 1.114 + nsRefPtr<MetadataParameters> mParams; 1.115 + bool mReadWrite; 1.116 + }; 1.117 + 1.118 + nsRefPtr<MetadataParameters> mParams; 1.119 +}; 1.120 + 1.121 +END_FILE_NAMESPACE 1.122 + 1.123 +#endif // mozilla_dom_file_metadatahelper_h__