OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "public/platform/WebFileSystemCallbacks.h" | 31 #include "public/platform/WebFileSystemCallbacks.h" |
32 | 32 |
33 #include "platform/AsyncFileSystemCallbacks.h" | 33 #include "platform/AsyncFileSystemCallbacks.h" |
34 #include "platform/FileMetadata.h" | 34 #include "platform/FileMetadata.h" |
35 #include "public/platform/WebFileInfo.h" | 35 #include "public/platform/WebFileInfo.h" |
36 #include "public/platform/WebFileSystem.h" | 36 #include "public/platform/WebFileSystem.h" |
37 #include "public/platform/WebFileSystemEntry.h" | 37 #include "public/platform/WebFileSystemEntry.h" |
38 #include "public/platform/WebFileWriter.h" | 38 #include "public/platform/WebFileWriter.h" |
39 #include "public/platform/WebString.h" | 39 #include "public/platform/WebString.h" |
40 #include "wtf/PassOwnPtr.h" | |
41 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
| 41 #include "wtf/PtrUtil.h" |
42 #include "wtf/RefCounted.h" | 42 #include "wtf/RefCounted.h" |
| 43 #include <memory> |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 class WebFileSystemCallbacksPrivate : public RefCounted<WebFileSystemCallbacksPr
ivate> { | 47 class WebFileSystemCallbacksPrivate : public RefCounted<WebFileSystemCallbacksPr
ivate> { |
47 public: | 48 public: |
48 static PassRefPtr<WebFileSystemCallbacksPrivate> create(PassOwnPtr<AsyncFile
SystemCallbacks> callbacks) | 49 static PassRefPtr<WebFileSystemCallbacksPrivate> create(std::unique_ptr<Asyn
cFileSystemCallbacks> callbacks) |
49 { | 50 { |
50 return adoptRef(new WebFileSystemCallbacksPrivate(std::move(callbacks)))
; | 51 return adoptRef(new WebFileSystemCallbacksPrivate(std::move(callbacks)))
; |
51 } | 52 } |
52 | 53 |
53 AsyncFileSystemCallbacks* callbacks() { return m_callbacks.get(); } | 54 AsyncFileSystemCallbacks* callbacks() { return m_callbacks.get(); } |
54 | 55 |
55 private: | 56 private: |
56 WebFileSystemCallbacksPrivate(PassOwnPtr<AsyncFileSystemCallbacks> callbacks
) : m_callbacks(std::move(callbacks)) { } | 57 WebFileSystemCallbacksPrivate(std::unique_ptr<AsyncFileSystemCallbacks> call
backs) : m_callbacks(std::move(callbacks)) { } |
57 OwnPtr<AsyncFileSystemCallbacks> m_callbacks; | 58 std::unique_ptr<AsyncFileSystemCallbacks> m_callbacks; |
58 }; | 59 }; |
59 | 60 |
60 WebFileSystemCallbacks::WebFileSystemCallbacks(PassOwnPtr<AsyncFileSystemCallbac
ks>&& callbacks) | 61 WebFileSystemCallbacks::WebFileSystemCallbacks(std::unique_ptr<AsyncFileSystemCa
llbacks>&& callbacks) |
61 { | 62 { |
62 m_private = WebFileSystemCallbacksPrivate::create(std::move(callbacks)); | 63 m_private = WebFileSystemCallbacksPrivate::create(std::move(callbacks)); |
63 } | 64 } |
64 | 65 |
65 void WebFileSystemCallbacks::reset() | 66 void WebFileSystemCallbacks::reset() |
66 { | 67 { |
67 m_private.reset(); | 68 m_private.reset(); |
68 } | 69 } |
69 | 70 |
70 void WebFileSystemCallbacks::assign(const WebFileSystemCallbacks& other) | 71 void WebFileSystemCallbacks::assign(const WebFileSystemCallbacks& other) |
(...skipping 18 matching lines...) Expand all Loading... |
89 fileMetadata.platformPath = webFileInfo.platformPath; | 90 fileMetadata.platformPath = webFileInfo.platformPath; |
90 m_private->callbacks()->didReadMetadata(fileMetadata); | 91 m_private->callbacks()->didReadMetadata(fileMetadata); |
91 m_private.reset(); | 92 m_private.reset(); |
92 } | 93 } |
93 | 94 |
94 void WebFileSystemCallbacks::didCreateSnapshotFile(const WebFileInfo& webFileInf
o) | 95 void WebFileSystemCallbacks::didCreateSnapshotFile(const WebFileInfo& webFileInf
o) |
95 { | 96 { |
96 ASSERT(!m_private.isNull()); | 97 ASSERT(!m_private.isNull()); |
97 // It's important to create a BlobDataHandle that refers to the platform fil
e path prior | 98 // It's important to create a BlobDataHandle that refers to the platform fil
e path prior |
98 // to return from this method so the underlying file will not be deleted. | 99 // to return from this method so the underlying file will not be deleted. |
99 OwnPtr<BlobData> blobData = BlobData::create(); | 100 std::unique_ptr<BlobData> blobData = BlobData::create(); |
100 blobData->appendFile(webFileInfo.platformPath, 0, webFileInfo.length, invali
dFileTime()); | 101 blobData->appendFile(webFileInfo.platformPath, 0, webFileInfo.length, invali
dFileTime()); |
101 RefPtr<BlobDataHandle> snapshotBlob = BlobDataHandle::create(std::move(blobD
ata), webFileInfo.length); | 102 RefPtr<BlobDataHandle> snapshotBlob = BlobDataHandle::create(std::move(blobD
ata), webFileInfo.length); |
102 | 103 |
103 FileMetadata fileMetadata; | 104 FileMetadata fileMetadata; |
104 fileMetadata.modificationTime = webFileInfo.modificationTime; | 105 fileMetadata.modificationTime = webFileInfo.modificationTime; |
105 fileMetadata.length = webFileInfo.length; | 106 fileMetadata.length = webFileInfo.length; |
106 fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type); | 107 fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type); |
107 fileMetadata.platformPath = webFileInfo.platformPath; | 108 fileMetadata.platformPath = webFileInfo.platformPath; |
108 m_private->callbacks()->didCreateSnapshotFile(fileMetadata, snapshotBlob); | 109 m_private->callbacks()->didCreateSnapshotFile(fileMetadata, snapshotBlob); |
109 m_private.reset(); | 110 m_private.reset(); |
(...skipping 18 matching lines...) Expand all Loading... |
128 void WebFileSystemCallbacks::didResolveURL(const WebString& name, const WebURL&
rootURL, WebFileSystemType type, const WebString& filePath, bool isDirectory) | 129 void WebFileSystemCallbacks::didResolveURL(const WebString& name, const WebURL&
rootURL, WebFileSystemType type, const WebString& filePath, bool isDirectory) |
129 { | 130 { |
130 ASSERT(!m_private.isNull()); | 131 ASSERT(!m_private.isNull()); |
131 m_private->callbacks()->didResolveURL(name, rootURL, static_cast<FileSystemT
ype>(type), filePath, isDirectory); | 132 m_private->callbacks()->didResolveURL(name, rootURL, static_cast<FileSystemT
ype>(type), filePath, isDirectory); |
132 m_private.reset(); | 133 m_private.reset(); |
133 } | 134 } |
134 | 135 |
135 void WebFileSystemCallbacks::didCreateFileWriter(WebFileWriter* webFileWriter, l
ong long length) | 136 void WebFileSystemCallbacks::didCreateFileWriter(WebFileWriter* webFileWriter, l
ong long length) |
136 { | 137 { |
137 ASSERT(!m_private.isNull()); | 138 ASSERT(!m_private.isNull()); |
138 m_private->callbacks()->didCreateFileWriter(adoptPtr(webFileWriter), length)
; | 139 m_private->callbacks()->didCreateFileWriter(wrapUnique(webFileWriter), lengt
h); |
139 m_private.reset(); | 140 m_private.reset(); |
140 } | 141 } |
141 | 142 |
142 void WebFileSystemCallbacks::didFail(WebFileError error) | 143 void WebFileSystemCallbacks::didFail(WebFileError error) |
143 { | 144 { |
144 ASSERT(!m_private.isNull()); | 145 ASSERT(!m_private.isNull()); |
145 m_private->callbacks()->didFail(error); | 146 m_private->callbacks()->didFail(error); |
146 m_private.reset(); | 147 m_private.reset(); |
147 } | 148 } |
148 | 149 |
149 bool WebFileSystemCallbacks::shouldBlockUntilCompletion() const | 150 bool WebFileSystemCallbacks::shouldBlockUntilCompletion() const |
150 { | 151 { |
151 ASSERT(!m_private.isNull()); | 152 ASSERT(!m_private.isNull()); |
152 return m_private->callbacks()->shouldBlockUntilCompletion(); | 153 return m_private->callbacks()->shouldBlockUntilCompletion(); |
153 } | 154 } |
154 | 155 |
155 } // namespace blink | 156 } // namespace blink |
OLD | NEW |