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
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_
6 #define CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "third_party/WebKit/public/platform/WebFileSystem.h"
15 #include "webkit/child/worker_task_runner.h"
18 class MessageLoopProxy
;
24 class WebFileWriterClient
;
29 class WebFileSystemImpl
30 : public blink::WebFileSystem
,
31 public webkit_glue::WorkerTaskRunner::Observer
,
32 public base::NonThreadSafe
{
34 // Returns thread-specific instance. If non-null |main_thread_loop|
35 // is given and no thread-specific instance has been created it may
36 // create a new instance.
37 static WebFileSystemImpl
* ThreadSpecificInstance(
38 base::MessageLoopProxy
* main_thread_loop
);
40 // Deletes thread-specific instance (if exists). For workers it deletes
41 // itself in OnWorkerRunLoopStopped(), but for an instance created on the
42 // main thread this method must be called.
43 static void DeleteThreadSpecificInstance();
45 explicit WebFileSystemImpl(base::MessageLoopProxy
* main_thread_loop
);
46 virtual ~WebFileSystemImpl();
48 // webkit_glue::WorkerTaskRunner::Observer implementation.
49 virtual void OnWorkerRunLoopStopped() OVERRIDE
;
51 // WebFileSystem implementation.
52 virtual void openFileSystem(
53 const blink::WebURL
& storage_partition
,
54 const blink::WebFileSystemType type
,
55 blink::WebFileSystemCallbacks
);
56 virtual void resolveURL(
57 const blink::WebURL
& filesystem_url
,
58 blink::WebFileSystemCallbacks
) OVERRIDE
;
59 virtual void deleteFileSystem(
60 const blink::WebURL
& storage_partition
,
61 const blink::WebFileSystemType type
,
62 blink::WebFileSystemCallbacks
);
64 const blink::WebURL
& src_path
,
65 const blink::WebURL
& dest_path
,
66 blink::WebFileSystemCallbacks
) OVERRIDE
;
68 const blink::WebURL
& src_path
,
69 const blink::WebURL
& dest_path
,
70 blink::WebFileSystemCallbacks
) OVERRIDE
;
72 const blink::WebURL
& path
,
73 blink::WebFileSystemCallbacks
) OVERRIDE
;
74 virtual void removeRecursively(
75 const blink::WebURL
& path
,
76 blink::WebFileSystemCallbacks
) OVERRIDE
;
77 virtual void readMetadata(
78 const blink::WebURL
& path
,
79 blink::WebFileSystemCallbacks
) OVERRIDE
;
80 virtual void createFile(
81 const blink::WebURL
& path
,
83 blink::WebFileSystemCallbacks
) OVERRIDE
;
84 virtual void createDirectory(
85 const blink::WebURL
& path
,
87 blink::WebFileSystemCallbacks
) OVERRIDE
;
88 virtual void fileExists(
89 const blink::WebURL
& path
,
90 blink::WebFileSystemCallbacks
) OVERRIDE
;
91 virtual void directoryExists(
92 const blink::WebURL
& path
,
93 blink::WebFileSystemCallbacks
) OVERRIDE
;
94 virtual void readDirectory(
95 const blink::WebURL
& path
,
96 blink::WebFileSystemCallbacks
) OVERRIDE
;
97 virtual void createFileWriter(
98 const blink::WebURL
& path
,
99 blink::WebFileWriterClient
*,
100 blink::WebFileSystemCallbacks
) OVERRIDE
;
101 virtual void createSnapshotFileAndReadMetadata(
102 const blink::WebURL
& path
,
103 blink::WebFileSystemCallbacks
);
105 int RegisterCallbacks(const blink::WebFileSystemCallbacks
& callbacks
);
106 blink::WebFileSystemCallbacks
GetAndUnregisterCallbacks(
110 typedef std::map
<int, blink::WebFileSystemCallbacks
> CallbacksMap
;
112 scoped_refptr
<base::MessageLoopProxy
> main_thread_loop_
;
114 CallbacksMap callbacks_
;
115 int next_callbacks_id_
;
117 DISALLOW_COPY_AND_ASSIGN(WebFileSystemImpl
);
120 } // namespace content
122 #endif // CONTENT_CHILD_FILEAPI_WEBFILESYSTEM_IMPL_H_