OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ | 5 #ifndef CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ |
6 #define CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ | 6 #define CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
10 #include "base/id_map.h" | |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
13 #include "third_party/WebKit/public/platform/WebFileSystem.h" | 14 #include "third_party/WebKit/public/platform/WebFileSystem.h" |
14 #include "webkit/child/worker_task_runner.h" | 15 #include "webkit/child/worker_task_runner.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class MessageLoopProxy; | 18 class MessageLoopProxy; |
18 } | 19 } |
19 | 20 |
20 namespace WebKit { | 21 namespace WebKit { |
21 class WebURL; | 22 class WebURL; |
22 class WebFileWriter; | 23 class WebFileWriter; |
23 class WebFileWriterClient; | 24 class WebFileWriterClient; |
24 } | 25 } |
25 | 26 |
| 27 // TODO(kinuko): Remove this hack after the two-sided patch lands. |
| 28 #ifdef NON_SELFDESTRUCT_WEBFILESYSTEMCALLBACKS |
| 29 typedef WebKit::WebFileSystemCallbacks WebFileSystemCallbacksType; |
| 30 #else |
| 31 typedef WebKit::WebFileSystemCallbacks* WebFileSystemCallbacksType; |
| 32 #endif |
| 33 |
26 namespace content { | 34 namespace content { |
27 | 35 |
28 class WebFileSystemImpl | 36 class WebFileSystemImpl |
29 : public WebKit::WebFileSystem, | 37 : public WebKit::WebFileSystem, |
30 public webkit_glue::WorkerTaskRunner::Observer, | 38 public webkit_glue::WorkerTaskRunner::Observer, |
31 public base::NonThreadSafe { | 39 public base::NonThreadSafe { |
32 public: | 40 public: |
33 // Returns thread-specific instance. If non-null |main_thread_loop| | 41 // Returns thread-specific instance. If non-null |main_thread_loop| |
34 // is given and no thread-specific instance has been created it may | 42 // is given and no thread-specific instance has been created it may |
35 // create a new instance. | 43 // create a new instance. |
36 static WebFileSystemImpl* ThreadSpecificInstance( | 44 static WebFileSystemImpl* ThreadSpecificInstance( |
37 base::MessageLoopProxy* main_thread_loop); | 45 base::MessageLoopProxy* main_thread_loop); |
38 | 46 |
39 // Deletes thread-specific instance (if exists). For workers it deletes | 47 // Deletes thread-specific instance (if exists). For workers it deletes |
40 // itself in OnWorkerRunLoopStopped(), but for an instance created on the | 48 // itself in OnWorkerRunLoopStopped(), but for an instance created on the |
41 // main thread this method must be called. | 49 // main thread this method must be called. |
42 static void DeleteThreadSpecificInstance(); | 50 static void DeleteThreadSpecificInstance(); |
43 | 51 |
44 explicit WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop); | 52 explicit WebFileSystemImpl(base::MessageLoopProxy* main_thread_loop); |
45 virtual ~WebFileSystemImpl(); | 53 virtual ~WebFileSystemImpl(); |
46 | 54 |
47 // webkit_glue::WorkerTaskRunner::Observer implementation. | 55 // webkit_glue::WorkerTaskRunner::Observer implementation. |
48 virtual void OnWorkerRunLoopStopped() OVERRIDE; | 56 virtual void OnWorkerRunLoopStopped() OVERRIDE; |
49 | 57 |
50 // WebFileSystem implementation. | 58 // WebFileSystem implementation. |
51 virtual void openFileSystem( | 59 virtual void openFileSystem( |
52 const WebKit::WebURL& storage_partition, | 60 const WebKit::WebURL& storage_partition, |
53 const WebKit::WebFileSystemType type, | 61 const WebKit::WebFileSystemType type, |
54 bool create, | 62 bool create, |
55 WebKit::WebFileSystemCallbacks*); | 63 WebFileSystemCallbacksType); |
56 virtual void deleteFileSystem( | 64 virtual void deleteFileSystem( |
57 const WebKit::WebURL& storage_partition, | 65 const WebKit::WebURL& storage_partition, |
58 const WebKit::WebFileSystemType type, | 66 const WebKit::WebFileSystemType type, |
59 WebKit::WebFileSystemCallbacks*); | 67 WebFileSystemCallbacksType); |
60 virtual void move( | 68 virtual void move( |
61 const WebKit::WebURL& src_path, | 69 const WebKit::WebURL& src_path, |
62 const WebKit::WebURL& dest_path, | 70 const WebKit::WebURL& dest_path, |
63 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 71 WebFileSystemCallbacksType) OVERRIDE; |
64 virtual void copy( | 72 virtual void copy( |
65 const WebKit::WebURL& src_path, | 73 const WebKit::WebURL& src_path, |
66 const WebKit::WebURL& dest_path, | 74 const WebKit::WebURL& dest_path, |
67 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 75 WebFileSystemCallbacksType) OVERRIDE; |
68 virtual void remove( | 76 virtual void remove( |
69 const WebKit::WebURL& path, | 77 const WebKit::WebURL& path, |
70 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 78 WebFileSystemCallbacksType) OVERRIDE; |
71 virtual void removeRecursively( | 79 virtual void removeRecursively( |
72 const WebKit::WebURL& path, | 80 const WebKit::WebURL& path, |
73 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 81 WebFileSystemCallbacksType) OVERRIDE; |
74 virtual void readMetadata( | 82 virtual void readMetadata( |
75 const WebKit::WebURL& path, | 83 const WebKit::WebURL& path, |
76 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 84 WebFileSystemCallbacksType) OVERRIDE; |
77 virtual void createFile( | 85 virtual void createFile( |
78 const WebKit::WebURL& path, | 86 const WebKit::WebURL& path, |
79 bool exclusive, | 87 bool exclusive, |
80 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 88 WebFileSystemCallbacksType) OVERRIDE; |
81 virtual void createDirectory( | 89 virtual void createDirectory( |
82 const WebKit::WebURL& path, | 90 const WebKit::WebURL& path, |
83 bool exclusive, | 91 bool exclusive, |
84 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 92 WebFileSystemCallbacksType) OVERRIDE; |
85 virtual void fileExists( | 93 virtual void fileExists( |
86 const WebKit::WebURL& path, | 94 const WebKit::WebURL& path, |
87 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 95 WebFileSystemCallbacksType) OVERRIDE; |
88 virtual void directoryExists( | 96 virtual void directoryExists( |
89 const WebKit::WebURL& path, | 97 const WebKit::WebURL& path, |
90 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 98 WebFileSystemCallbacksType) OVERRIDE; |
91 virtual void readDirectory( | 99 virtual void readDirectory( |
92 const WebKit::WebURL& path, | 100 const WebKit::WebURL& path, |
93 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 101 WebFileSystemCallbacksType) OVERRIDE; |
94 virtual WebKit::WebFileWriter* createFileWriter( | 102 virtual WebKit::WebFileWriter* createFileWriter( |
95 const WebKit::WebURL& path, WebKit::WebFileWriterClient*) OVERRIDE; | 103 const WebKit::WebURL& path, |
| 104 WebKit::WebFileWriterClient*); |
96 virtual void createFileWriter( | 105 virtual void createFileWriter( |
97 const WebKit::WebURL& path, | 106 const WebKit::WebURL& path, |
98 WebKit::WebFileWriterClient*, | 107 WebKit::WebFileWriterClient*, |
99 WebKit::WebFileSystemCallbacks*) OVERRIDE; | 108 WebFileSystemCallbacksType) OVERRIDE; |
100 virtual void createSnapshotFileAndReadMetadata( | 109 virtual void createSnapshotFileAndReadMetadata( |
101 const WebKit::WebURL& path, | 110 const WebKit::WebURL& path, |
102 WebKit::WebFileSystemCallbacks*); | 111 WebFileSystemCallbacksType); |
103 | 112 |
104 int RegisterCallbacks(WebKit::WebFileSystemCallbacks* callbacks); | 113 int RegisterCallbacks(WebFileSystemCallbacksType callbacks); |
105 WebKit::WebFileSystemCallbacks* GetAndUnregisterCallbacks( | 114 WebFileSystemCallbacksType GetAndUnregisterCallbacks( |
106 int callbacks_id); | 115 int callbacks_id); |
107 | 116 |
108 private: | 117 private: |
| 118 typedef std::map<int, WebFileSystemCallbacksType> CallbacksMap; |
| 119 |
109 scoped_refptr<base::MessageLoopProxy> main_thread_loop_; | 120 scoped_refptr<base::MessageLoopProxy> main_thread_loop_; |
110 IDMap<WebKit::WebFileSystemCallbacks> callbacks_; | 121 |
| 122 CallbacksMap callbacks_; |
| 123 int next_callbacks_id_; |
111 | 124 |
112 DISALLOW_COPY_AND_ASSIGN(WebFileSystemImpl); | 125 DISALLOW_COPY_AND_ASSIGN(WebFileSystemImpl); |
113 }; | 126 }; |
114 | 127 |
115 } // namespace content | 128 } // namespace content |
116 | 129 |
117 #endif // CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ | 130 #endif // CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_ |
OLD | NEW |