Index: chrome/browser/extensions/api/web_request/upload_data_presenter.h |
diff --git a/chrome/browser/extensions/api/web_request/upload_data_presenter.h b/chrome/browser/extensions/api/web_request/upload_data_presenter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..53fea29b34251cc59f91acf730333787659f5633 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/web_request/upload_data_presenter.h |
@@ -0,0 +1,113 @@ |
+// Copyright (c) 2012 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_EXTENSIONS_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ |
+#define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+// Need to include this, because UploadData::Element cannot be forward declared. |
+#include "net/base/upload_data.h" |
+ |
+namespace base { |
+class DictionaryValue; |
+class ListValue; |
+class Value; |
+} |
+ |
+namespace extensions { |
+class FormDataParser; |
+} |
+ |
+namespace net { |
+class URLRequest; |
+} |
+ |
+namespace extensions { |
+ |
+// UploadDataPresenter is an interface for objects capable to be consume |
battre
2012/08/16 19:18:03
-be
vabr (Chromium)
2012/08/17 18:29:57
Done.
|
+// a series of UploadData::Element and represent this data as a base:Value. |
+// |
+// Workflow for objects implementing this interface: |
+// 1. Call object->FeedNext(element) for each element from the request's body. |
+// 2. Check if object->Succeeded(). |
+// 3. If that check passed then retrieve object->Result(). |
+class UploadDataPresenter { |
+ public: |
+ virtual ~UploadDataPresenter(); |
+ virtual void FeedNext(const net::UploadData::Element& element) = 0; |
+ virtual bool Succeeded() = 0; |
+ virtual scoped_ptr<base::Value> Result() = 0; |
+ |
+ protected: |
+ UploadDataPresenter() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(UploadDataPresenter); |
+}; |
+ |
+// This class checks that chunked transfer encoding (defined in RFC 2616) |
+// is not used. If it is, an error string is generated. |
+class ChunkedErrorPresenter : public UploadDataPresenter { |
+ public: |
+ explicit ChunkedErrorPresenter(const net::URLRequest* request); |
+ virtual ~ChunkedErrorPresenter(); |
+ |
+ // Tests the headers of |request| for transfer encoding. |
+ static bool TransferEncodingChunked(const net::URLRequest* request); |
battre
2012/08/16 19:18:03
Put a verb ("Is") to the beginning of method name?
vabr (Chromium)
2012/08/17 18:29:57
Done.
|
+ |
+ // Implementation of UploadDataPresenter. |
+ virtual void FeedNext(const net::UploadData::Element& element) OVERRIDE; |
+ virtual bool Succeeded() OVERRIDE; |
+ virtual scoped_ptr<base::Value> Result() OVERRIDE; |
+ |
+ private: |
+ bool chunks_found_; |
+}; |
+ |
+class RawDataPresenter : public UploadDataPresenter { |
battre
2012/08/16 19:18:03
Can you please add a high level description for th
vabr (Chromium)
2012/08/17 18:29:57
Done.
|
+ public: |
+ RawDataPresenter(); |
+ virtual ~RawDataPresenter(); |
+ |
+ // Implementation of UploadDataPresenter. |
+ virtual void FeedNext(const net::UploadData::Element& element) OVERRIDE; |
+ virtual bool Succeeded() OVERRIDE; |
+ virtual scoped_ptr<base::Value> Result() OVERRIDE; |
+ |
+ private: |
+ // Clears resources and the success flag. |
+ void Abort(); |
+ |
+ void FeedNextBytes(const std::vector<char>& bytes); |
+ void FeedNextFile(const std::string& filename); |
+ FRIEND_TEST_ALL_PREFIXES(WebRequestUploadDataPresenterTest, RawData); |
+ |
+ bool success_; |
+ scoped_ptr<base::ListValue> list_; |
+}; |
+ |
+class ParsedDataPresenter : public UploadDataPresenter { |
battre
2012/08/16 19:18:03
Can you please add a high level description for th
vabr (Chromium)
2012/08/17 18:29:57
Done.
|
+ public: |
+ explicit ParsedDataPresenter(const net::URLRequest* request); |
+ virtual ~ParsedDataPresenter(); |
+ |
+ // Implementation of UploadDataPresenter. |
+ virtual void FeedNext(const net::UploadData::Element& element) OVERRIDE; |
+ virtual bool Succeeded() OVERRIDE; |
+ virtual scoped_ptr<base::Value> Result() OVERRIDE; |
+ |
+ private: |
+ // Clears resources and the success flag. |
+ void Abort(); |
+ scoped_ptr<FormDataParser> parser_; |
+ bool success_; |
+ scoped_ptr<base::DictionaryValue> dictionary_; |
+}; |
+ |
+} // namespace extensions |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_UPLOAD_DATA_PRESENTER_H_ |