dom/file/MetadataHelper.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:558059471bb6
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/. */
6
7 #ifndef mozilla_dom_file_metadatahelper_h__
8 #define mozilla_dom_file_metadatahelper_h__
9
10 #include "mozilla/Attributes.h"
11 #include "FileCommon.h"
12
13 #include "nsIFileStreams.h"
14
15 #include "AsyncHelper.h"
16 #include "FileHelper.h"
17
18 class nsIFileStream;
19
20 BEGIN_FILE_NAMESPACE
21
22 class MetadataHelper;
23
24 class MetadataParameters MOZ_FINAL
25 {
26 friend class MetadataHelper;
27
28 public:
29 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MetadataParameters)
30
31 MetadataParameters(bool aSizeRequested, bool aLastModifiedRequested)
32 : mSizeRequested(aSizeRequested)
33 , mLastModifiedRequested(aLastModifiedRequested)
34 {
35 }
36
37 bool
38 IsConfigured() const
39 {
40 return mSizeRequested || mLastModifiedRequested;
41 }
42
43 bool
44 SizeRequested() const
45 {
46 return mSizeRequested;
47 }
48
49 bool
50 LastModifiedRequested() const
51 {
52 return mLastModifiedRequested;
53 }
54
55 uint64_t
56 Size() const
57 {
58 return mSize;
59 }
60
61 int64_t
62 LastModified() const
63 {
64 return mLastModified;
65 }
66
67 private:
68 // Private destructor, to discourage deletion outside of Release():
69 ~MetadataParameters()
70 {
71 }
72
73 uint64_t mSize;
74 int64_t mLastModified;
75 bool mSizeRequested;
76 bool mLastModifiedRequested;
77 };
78
79 class MetadataHelper : public FileHelper
80 {
81 public:
82 MetadataHelper(LockedFile* aLockedFile,
83 FileRequest* aFileRequest,
84 MetadataParameters* aParams)
85 : FileHelper(aLockedFile, aFileRequest),
86 mParams(aParams)
87 { }
88
89 nsresult
90 DoAsyncRun(nsISupports* aStream) MOZ_OVERRIDE;
91
92 nsresult
93 GetSuccessResult(JSContext* aCx,
94 JS::MutableHandle<JS::Value> aVal) MOZ_OVERRIDE;
95
96 protected:
97 class AsyncMetadataGetter : public AsyncHelper
98 {
99 public:
100 AsyncMetadataGetter(nsISupports* aStream, MetadataParameters* aParams,
101 bool aReadWrite)
102 : AsyncHelper(aStream),
103 mParams(aParams), mReadWrite(aReadWrite)
104 { }
105
106 protected:
107 nsresult
108 DoStreamWork(nsISupports* aStream) MOZ_OVERRIDE;
109
110 private:
111 nsRefPtr<MetadataParameters> mParams;
112 bool mReadWrite;
113 };
114
115 nsRefPtr<MetadataParameters> mParams;
116 };
117
118 END_FILE_NAMESPACE
119
120 #endif // mozilla_dom_file_metadatahelper_h__

mercurial