net: Make UploadDataStream::Read() asynchronous

Rename existing Read() to ReadSync()
Change type of |buf| from char* to scoped_refptr<IOBuffer> so that async operation is always performed safely
Add an asynchronous implementation, Read()
The newly added Read() is not used yet, all users still use the old version ReadSync()

BUG=72001
TEST=net_unittests

Review URL: https://chromiumcodereview.appspot.com/10910268

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162343 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/base/upload_element_reader.h b/net/base/upload_element_reader.h
index acb1eca..4ba973d 100644
--- a/net/base/upload_element_reader.h
+++ b/net/base/upload_element_reader.h
@@ -11,6 +11,7 @@
 
 namespace net {
 
+class IOBuffer;
 class UploadElement;
 
 // An interface to read an upload data element.
@@ -41,11 +42,18 @@
   // The default implementation returns false.
   virtual bool IsInMemory() const;
 
-  // Reads up to |buf_length| bytes synchronously. Returns the number of bytes
-  // read. This function never fails. If there's less data to read than we
-  // initially observed, then pad with zero (this can happen with files).
-  // |buf_length| must be greater than 0.
-  virtual int ReadSync(char* buf, int buf_length) = 0;
+  // Reads up to |buf_length| bytes synchronously and returns the number of
+  // bytes read when possible, otherwise, returns ERR_IO_PENDING and runs
+  // |callback| with the result. This function never fails. If there's less data
+  // to read than we initially observed, then pad with zero (this can happen
+  // with files). |buf_length| must be greater than 0.
+  virtual int Read(IOBuffer* buf,
+                   int buf_length,
+                   const CompletionCallback& callback) = 0;
+
+  // Reads the data always synchronously.
+  // Use this method only if the thread is IO allowed or the data is in-memory.
+  virtual int ReadSync(IOBuffer* buf, int buf_length);
 
  private:
   DISALLOW_COPY_AND_ASSIGN(UploadElementReader);