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

Unified Diff: net/base/upload_data_stream.h

Issue 10913179: net: Make UploadDataStream::Init() asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ Created 8 years, 3 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: net/base/upload_data_stream.h
diff --git a/net/base/upload_data_stream.h b/net/base/upload_data_stream.h
index 73c93594106356497b98733baa3c25d14d5f749f..6f5ade26820c3063644fde599b378c4fb10620be 100644
--- a/net/base/upload_data_stream.h
+++ b/net/base/upload_data_stream.h
@@ -7,6 +7,8 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
+#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
#include "net/base/upload_data.h"
@@ -24,10 +26,17 @@ class NET_EXPORT UploadDataStream {
// before calling any other method. It is not valid to call any method
// (other than the destructor) if Init() returns a failure.
//
+ // Does the initialization synchronously and returns the result if possible,
+ // otherwise returns ERR_IO_PENDING and runs the callback with the result.
+ //
// Returns OK on success. Returns ERR_UPLOAD_FILE_CHANGED if the expected
// file modification time is set (usually not set, but set for sliced
// files) and the target file is changed.
- int Init();
+ int Init(const CompletionCallback& callback);
+
+ // Initializes the stream synchronously.
+ // Use this method only in tests and Chrome Frame.
+ int InitSync();
// Reads up to |buf_len| bytes from the upload data stream to |buf|. The
// number of bytes read is returned. Partial reads are allowed. Zero is
@@ -71,6 +80,16 @@ class NET_EXPORT UploadDataStream {
friend class SpdyNetworkTransactionSpdy2Test;
friend class SpdyNetworkTransactionSpdy3Test;
+ // Runs Init() for all element readers.
+ // This method is used to implement Init().
+ void InitInternal(const CompletionCallback& callback,
+ int index,
+ int last_result);
+
+ // Finalizes the initialization process.
+ // This method is used to implement Init().
+ void FinalizeInitialization();
+
// These methods are provided only to be used by unit tests.
static void ResetMergeChunks();
static void set_merge_chunks(bool merge) { merge_chunks_ = merge; }
@@ -90,6 +109,8 @@ class NET_EXPORT UploadDataStream {
// True if the initialization was successful.
bool initialized_successfully_;
+ base::WeakPtrFactory<UploadDataStream> weak_ptr_factory_;
+
// TODO(satish): Remove this once we have a better way to unit test POST
// requests with chunked uploads.
static bool merge_chunks_;

Powered by Google App Engine
This is Rietveld 408576698