Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
|
jsbell
2014/03/20 16:00:46
Use short copyright declaration
ericu
2014/03/25 00:00:26
Done.
| |
| 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef V8GarbageCollected_h | 31 #ifndef BlobInfo_h |
| 32 #define V8GarbageCollected_h | 32 #define BlobInfo_h |
| 33 | 33 |
| 34 #include <v8.h> | 34 #include "wtf/text/WTFString.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 template<typename T> | 38 class BlobInfo { |
| 39 class V8GarbageCollected { | |
| 40 WTF_MAKE_NONCOPYABLE(V8GarbageCollected); | |
| 41 public: | 39 public: |
| 42 static T* Cast(v8::Handle<v8::Value> value) | 40 BlobInfo() |
| 41 : m_isFile(false) | |
| 42 , m_size(-1) | |
|
cmumford
2014/03/20 18:22:32
Should initialize m_lastModified.
ericu
2014/03/25 00:00:26
Done.
| |
| 43 { | 43 { |
| 44 ASSERT(value->IsExternal()); | |
| 45 T* result = static_cast<T*>(value.As<v8::External>()->Value()); | |
| 46 RELEASE_ASSERT(result->m_handle == value); | |
| 47 return result; | |
| 48 } | 44 } |
| 49 | 45 BlobInfo(const String& uuid, const String& type, long long size) |
| 50 protected: | 46 : m_isFile(false) |
| 51 V8GarbageCollected(v8::Isolate* isolate) | 47 , m_uuid(uuid) |
| 52 : m_isolate(isolate) | 48 , m_type(type) |
| 53 , m_handle(isolate, v8::External::New(isolate, static_cast<T*>(this))) | 49 , m_size(size) |
| 50 , m_lastModified(0) | |
| 51 { | |
| 52 } | |
| 53 BlobInfo(const String& uuid, const String& filePath, const String& fileName, const String& type, double lastModified, long long size) | |
| 54 : m_isFile(true) | |
| 55 , m_uuid(uuid) | |
| 56 , m_type(type) | |
| 57 , m_size(size) | |
| 58 , m_filePath(filePath) | |
| 59 , m_fileName(fileName) | |
| 60 , m_lastModified(lastModified) | |
| 61 { | |
| 62 } | |
| 63 BlobInfo(const String& uuid, const String& filePath, const String& fileName, const String& type) | |
| 64 : m_isFile(true) | |
| 65 , m_uuid(uuid) | |
| 66 , m_type(type) | |
| 67 , m_size(-1) | |
|
jsbell
2014/03/20 16:00:46
Is there any consistency checking we should do whe
ericu
2014/03/25 00:00:26
It's used to indicate that it's a File, but that w
| |
| 68 , m_filePath(filePath) | |
| 69 , m_fileName(fileName) | |
| 70 , m_lastModified(0) | |
| 54 { | 71 { |
| 55 } | 72 } |
| 56 | 73 |
| 57 v8::Handle<v8::External> releaseToV8GarbageCollector() | 74 bool isFile() const { return m_isFile; } |
| 58 { | 75 const String& uuid() const { return m_uuid; } |
| 59 ASSERT(!m_handle.isWeak()); // Call this exactly once. | 76 const String& type() const { return m_type; } |
| 60 v8::Handle<v8::External> result = m_handle.newLocal(m_isolate); | 77 long long size() const { return m_size; } |
| 61 m_handle.setWeak(static_cast<T*>(this), &weakCallback); | 78 const String& filePath() const { return m_filePath; } |
| 62 return result; | 79 const String& fileName() const { return m_fileName; } |
| 63 } | 80 double lastModified() const { return m_lastModified; } |
| 64 | |
| 65 ~V8GarbageCollected() | |
| 66 { | |
| 67 ASSERT(m_handle.isEmpty()); | |
| 68 } | |
| 69 | |
| 70 v8::Isolate* isolate() { return m_isolate; } | |
| 71 | 81 |
| 72 private: | 82 private: |
| 73 static void weakCallback(const v8::WeakCallbackData<v8::External, T>& data) | 83 bool m_isFile; |
| 74 { | 84 String m_uuid; |
| 75 T* self = data.GetParameter(); | 85 String m_type; // mime type |
|
jsbell
2014/03/20 16:00:46
Nit: Capitalize
cmumford
2014/03/20 18:22:32
Why not call this m_MimeType instead of m_Type?
jsbell
2014/03/20 18:30:29
Sorry, I meant: capitalize the comment (here and b
cmumford
2014/03/24 23:17:46
Well being more naive than you I'd prefer the more
ericu
2014/03/25 00:00:26
Done.
I left it as type for consistency with Blob
| |
| 76 self->m_handle.clear(); | 86 long long m_size; |
| 77 delete self; | 87 String m_filePath; // only for File |
|
jsbell
2014/03/20 16:00:46
Nit: ditto
ericu
2014/03/25 00:00:26
Done.
| |
| 78 } | 88 String m_fileName; // only for File |
| 79 | 89 double m_lastModified; // only for File |
| 80 v8::Isolate* m_isolate; | |
| 81 ScopedPersistent<v8::External> m_handle; | |
| 82 }; | 90 }; |
| 83 | 91 |
| 84 } // namespace WebCore | 92 } // namespace WebCore |
| 85 | 93 |
| 86 #endif // V8GarbageCollected_h | 94 #endif // BlobInfo_h |
| OLD | NEW |