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

Unified Diff: chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_reader.h

Issue 318563002: [fsp] Introduce BufferingFileStreamReader to read files in bigger chunks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed a test. Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_reader.h
diff --git a/chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_reader.h b/chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..13dc5afb29fb987de6bdbd7433636549c9a08f77
--- /dev/null
+++ b/chrome/browser/chromeos/file_system_provider/fileapi/buffering_file_stream_reader.h
@@ -0,0 +1,69 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STREAM_READER_H_
+#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STREAM_READER_H_
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "net/base/io_buffer.h"
hashimoto 2014/06/05 03:18:36 nit: forward declaration is enough.
mtomasz 2014/06/05 09:22:27 Done.
+#include "webkit/browser/blob/file_stream_reader.h"
+
+namespace fileapi {
+class AsyncFileUtil;
hashimoto 2014/06/05 03:18:36 nit: unused forward declaration.
mtomasz 2014/06/05 09:22:27 Done.
+} // namespace fileapi
+
+namespace chromeos {
+namespace file_system_provider {
+
+// Wraps the file stream reader implementation with a prefetching buffer. This
+// limits number of IPC to providing extensions significantly. For remote (HTTP
+// base) file systems, this also reduces overhead when creating HTTP requests
+// for each chunk. The chunks are bigger, so number of requests is smaller.
+class BufferingFileStreamReader : public webkit_blob::FileStreamReader {
+ public:
+ explicit BufferingFileStreamReader(
hashimoto 2014/06/05 03:18:36 nit: "explicit" unneeded.
mtomasz 2014/06/05 09:22:27 Done.
+ scoped_ptr<webkit_blob::FileStreamReader> file_stream_reader,
+ int buffer_size);
+
+ virtual ~BufferingFileStreamReader();
+
+ // webkit_blob::FileStreamReader overrides.
+ virtual int Read(net::IOBuffer* buf,
+ int buf_len,
+ const net::CompletionCallback& callback) OVERRIDE;
+ virtual int64 GetLength(
+ const net::Int64CompletionCallback& callback) OVERRIDE;
+
+ private:
+ // Copies data from the preloading buffer and updates the internal iterator.
+ // Returns number of bytes successfully copied.
+ int CopyFromBuffer(scoped_refptr<net::IOBuffer> buffer, int buffer_length);
+
+ // Preloads data from the internal stream reader and calls the |callback|.
+ void Preload(const net::CompletionCallback& callback);
+
+ // Called when preloading of a buffer chunk is finished. Updates state of the
+ // preloading buffer and copied requested data to the |buffer|.
+ void OnPreloadCompleted(scoped_refptr<net::IOBuffer> buffer,
+ int buffer_length,
+ const net::CompletionCallback& callback,
+ int result);
+
+ scoped_ptr<webkit_blob::FileStreamReader> file_stream_reader_;
+ int buffer_size_;
+ scoped_refptr<net::IOBuffer> preloading_buffer_;
hashimoto 2014/06/05 03:18:36 How about using DrainableIOBuffer?
mtomasz 2014/06/05 09:22:27 Net::DrainableIOBuffer works well if the buffer is
hashimoto 2014/06/05 10:07:10 I meant by using DrailableIOBuffer there is no nee
mtomasz 2014/06/05 11:27:43 This won't work since the buffer is not always ful
hashimoto 2014/06/05 12:31:09 You don't need BytesRemaining(). What I suggested
mtomasz 2014/06/06 01:31:02 DrailableIOBuffer is designed for fully filled out
+ int preloading_buffer_offset_;
+ int buffered_bytes_;
+
+ base::WeakPtrFactory<BufferingFileStreamReader> weak_ptr_factory_;
+ DISALLOW_COPY_AND_ASSIGN(BufferingFileStreamReader);
+};
+
+} // namespace file_system_provider
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_BUFFERING_FILE_STREAM_READER_H_

Powered by Google App Engine
This is Rietveld 408576698