Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: Source/core/fileapi/File.h

Issue 157363003: Implement Blob.close(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/fileapi/Blob.idl ('k') | Source/core/fileapi/File.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 14 matching lines...) Expand all
25 25
26 #ifndef File_h 26 #ifndef File_h
27 #define File_h 27 #define File_h
28 28
29 #include "core/fileapi/Blob.h" 29 #include "core/fileapi/Blob.h"
30 #include "wtf/PassRefPtr.h" 30 #include "wtf/PassRefPtr.h"
31 #include "wtf/text/WTFString.h" 31 #include "wtf/text/WTFString.h"
32 32
33 namespace WebCore { 33 namespace WebCore {
34 34
35 class ExecutionContext;
35 struct FileMetadata; 36 struct FileMetadata;
36 class KURL; 37 class KURL;
37 38
38 class File FINAL : public Blob { 39 class File FINAL : public Blob {
39 public: 40 public:
40 // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could 41 // AllContentTypes should only be used when the full path/name are trusted; otherwise, it could
41 // allow arbitrary pages to determine what applications an user has installe d. 42 // allow arbitrary pages to determine what applications an user has installe d.
42 enum ContentTypeLookupPolicy { 43 enum ContentTypeLookupPolicy {
43 WellKnownContentTypes, 44 WellKnownContentTypes,
44 AllContentTypes, 45 AllContentTypes,
(...skipping 23 matching lines...) Expand all
68 static PassRefPtr<File> createForFileSystemFile(const String& name, const Fi leMetadata& metadata) 69 static PassRefPtr<File> createForFileSystemFile(const String& name, const Fi leMetadata& metadata)
69 { 70 {
70 return adoptRef(new File(name, metadata)); 71 return adoptRef(new File(name, metadata));
71 } 72 }
72 73
73 static PassRefPtr<File> createForFileSystemFile(const KURL& url, const FileM etadata& metadata) 74 static PassRefPtr<File> createForFileSystemFile(const KURL& url, const FileM etadata& metadata)
74 { 75 {
75 return adoptRef(new File(url, metadata)); 76 return adoptRef(new File(url, metadata));
76 } 77 }
77 78
78 KURL fileSystemURL() const { ASSERT(m_hasBackingFile); return m_fileSystemUR L; } 79 KURL fileSystemURL() const { ASSERT(hasValidFileSystemURL()); return m_fileS ystemURL; }
79 80
80 // Create a file with a name exposed to the author (via File.name and associ ated DOM properties) that differs from the one provided in the path. 81 // Create a file with a name exposed to the author (via File.name and associ ated DOM properties) that differs from the one provided in the path.
81 static PassRefPtr<File> createWithName(const String& path, const String& nam e, ContentTypeLookupPolicy policy = WellKnownContentTypes) 82 static PassRefPtr<File> createWithName(const String& path, const String& nam e, ContentTypeLookupPolicy policy = WellKnownContentTypes)
82 { 83 {
83 if (name.isEmpty()) 84 if (name.isEmpty())
84 return adoptRef(new File(path, policy)); 85 return adoptRef(new File(path, policy));
85 return adoptRef(new File(path, name, policy)); 86 return adoptRef(new File(path, name, policy));
86 } 87 }
87 88
88 virtual unsigned long long size() const OVERRIDE; 89 virtual unsigned long long size() const OVERRIDE;
89 virtual PassRefPtr<Blob> slice(long long start = 0, long long end = std::num eric_limits<long long>::max(), const String& contentType = String()) const OVERR IDE; 90 virtual PassRefPtr<Blob> slice(long long start = 0, long long end = std::num eric_limits<long long>::max(), const String& contentType = String()) const OVERR IDE;
91 virtual void close(ExecutionContext*) OVERRIDE;
90 92
91 virtual bool isFile() const OVERRIDE { return true; } 93 virtual bool isFile() const OVERRIDE { return true; }
92 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; } 94 virtual bool hasBackingFile() const OVERRIDE { return m_hasBackingFile; }
93 95
94 virtual void appendTo(BlobData&) const OVERRIDE; 96 virtual void appendTo(BlobData&) const OVERRIDE;
95 97
96 const String& path() const { ASSERT(m_hasBackingFile); return m_path; } 98 const String& path() const { ASSERT(hasValidFilePath()); return m_path; }
97 const String& name() const { return m_name; } 99 const String name() const { return m_name; }
98 100
99 // This returns the current date and time if the file's last modifiecation d ate is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate). 101 // This returns the current date and time if the file's last modification da te is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate).
100 double lastModifiedDate() const; 102 double lastModifiedDate() const;
101 103
102 // Returns the relative path of this file in the context of a directory sele ction. 104 // Returns the relative path of this file in the context of a directory sele ction.
103 const String& webkitRelativePath() const { return m_relativePath; } 105 const String& webkitRelativePath() const { return m_relativePath; }
104 106
105 // Note that this involves synchronous file operation. Think twice before ca lling this function. 107 // Note that this involves synchronous file operation. Think twice before ca lling this function.
106 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const; 108 void captureSnapshot(long long& snapshotSize, double& snapshotModificationTi me) const;
107 109
108 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0). 110 // Returns true if this has a valid snapshot metadata (i.e. m_snapshotSize > = 0).
109 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; } 111 bool hasValidSnapshotMetadata() const { return m_snapshotSize >= 0; }
110 112
111 private: 113 private:
112 File(const String& path, ContentTypeLookupPolicy); 114 File(const String& path, ContentTypeLookupPolicy);
113 File(const String& path, const String& name, ContentTypeLookupPolicy); 115 File(const String& path, const String& name, ContentTypeLookupPolicy);
114 File(const String& path, const String& name, const String& relativePath, boo l hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> ); 116 File(const String& path, const String& name, const String& relativePath, boo l hasSnaphotData, uint64_t size, double lastModified, PassRefPtr<BlobDataHandle> );
115 File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> ); 117 File(const String& name, double modificationTime, PassRefPtr<BlobDataHandle> );
116 File(const String& name, const FileMetadata&); 118 File(const String& name, const FileMetadata&);
117 File(const KURL& fileSystemURL, const FileMetadata&); 119 File(const KURL& fileSystemURL, const FileMetadata&);
118 120
121 void invalidateSnapshotMetadata() { m_snapshotSize = -1; }
122
123 #ifndef NDEBUG
124 bool hasValidFileSystemURL() const { return hasBackingFile(); }
125 // Instances not backed by a file must have an empty path set.
126 bool hasValidFilePath() const { return hasBackingFile() || m_path.isEmpty(); }
127 #endif
128
119 bool m_hasBackingFile; 129 bool m_hasBackingFile;
120 String m_path; 130 String m_path;
121 String m_name; 131 String m_name;
122 132
123 KURL m_fileSystemURL; 133 KURL m_fileSystemURL;
124 134
125 // If m_snapshotSize is negative (initialized to -1 by default), the snapsho t metadata is invalid and we retrieve the latest metadata synchronously in size( ), lastModifiedTime() and slice(). 135 // If m_snapshotSize is negative (initialized to -1 by default), the snapsho t metadata is invalid and we retrieve the latest metadata synchronously in size( ), lastModifiedTime() and slice().
126 // Otherwise, the snapshot metadata are used directly in those methods. 136 // Otherwise, the snapshot metadata are used directly in those methods.
127 const long long m_snapshotSize; 137 long long m_snapshotSize;
128 const double m_snapshotModificationTime; 138 const double m_snapshotModificationTime;
129 139
130 String m_relativePath; 140 String m_relativePath;
131 }; 141 };
132 142
133 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile()); 143 DEFINE_TYPE_CASTS(File, Blob, blob, blob->isFile(), blob.isFile());
134 144
135 } // namespace WebCore 145 } // namespace WebCore
136 146
137 #endif // File_h 147 #endif // File_h
OLDNEW
« no previous file with comments | « Source/core/fileapi/Blob.idl ('k') | Source/core/fileapi/File.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698