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

Side by Side Diff: chrome/browser/extensions/api/web_request/upload_data_presenter.cc

Issue 11419034: net: Move ownership of UploadDataStream from URLRequestHttpJob to URLRequest (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix ASAN Created 8 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" 5 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/web_request/form_data_parser.h" 10 #include "chrome/browser/extensions/api/web_request/form_data_parser.h"
11 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" 11 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h"
12 #include "net/base/upload_element.h" 12 #include "net/base/upload_bytes_element_reader.h"
13 #include "net/base/upload_file_element_reader.h"
13 #include "net/url_request/url_request.h" 14 #include "net/url_request/url_request.h"
14 15
15 using base::BinaryValue; 16 using base::BinaryValue;
16 using base::DictionaryValue; 17 using base::DictionaryValue;
17 using base::ListValue; 18 using base::ListValue;
18 using base::StringValue; 19 using base::StringValue;
19 using base::Value; 20 using base::Value;
20 21
21 namespace keys = extension_web_request_api_constants; 22 namespace keys = extension_web_request_api_constants;
22 23
(...skipping 30 matching lines...) Expand all
53 UploadDataPresenter::~UploadDataPresenter() {} 54 UploadDataPresenter::~UploadDataPresenter() {}
54 55
55 // Implementation of RawDataPresenter. 56 // Implementation of RawDataPresenter.
56 57
57 RawDataPresenter::RawDataPresenter() 58 RawDataPresenter::RawDataPresenter()
58 : success_(true), 59 : success_(true),
59 list_(new base::ListValue) { 60 list_(new base::ListValue) {
60 } 61 }
61 RawDataPresenter::~RawDataPresenter() {} 62 RawDataPresenter::~RawDataPresenter() {}
62 63
63 void RawDataPresenter::FeedNext(const net::UploadElement& element) { 64 void RawDataPresenter::FeedNext(const net::UploadElementReader& reader) {
64 if (!success_) 65 if (!success_)
65 return; 66 return;
66 67
67 switch (element.type()) { 68 if (reader.AsBytesReader()) {
68 case net::UploadElement::TYPE_BYTES: 69 const net::UploadBytesElementReader* bytes_reader = reader.AsBytesReader();
69 FeedNextBytes(element.bytes(), element.bytes_length()); 70 FeedNextBytes(bytes_reader->bytes(), bytes_reader->length());
70 break; 71 } else if (reader.AsFileReader()) {
71 case net::UploadElement::TYPE_FILE: 72 // Insert the file path instead of the contents, which may be too large.
72 // Insert the file path instead of the contents, which may be too large. 73 const net::UploadFileElementReader* file_reader = reader.AsFileReader();
73 FeedNextFile(element.file_path().AsUTF8Unsafe()); 74 FeedNextFile(file_reader->path().AsUTF8Unsafe());
74 break; 75 } else {
76 NOTIMPLEMENTED();
75 } 77 }
76 } 78 }
77 79
78 bool RawDataPresenter::Succeeded() { 80 bool RawDataPresenter::Succeeded() {
79 return success_; 81 return success_;
80 } 82 }
81 83
82 scoped_ptr<Value> RawDataPresenter::Result() { 84 scoped_ptr<Value> RawDataPresenter::Result() {
83 if (!success_) 85 if (!success_)
84 return scoped_ptr<Value>(); 86 return scoped_ptr<Value>();
(...skipping 22 matching lines...) Expand all
107 // Implementation of ParsedDataPresenter. 109 // Implementation of ParsedDataPresenter.
108 110
109 ParsedDataPresenter::ParsedDataPresenter(const net::URLRequest& request) 111 ParsedDataPresenter::ParsedDataPresenter(const net::URLRequest& request)
110 : parser_(FormDataParser::Create(request)), 112 : parser_(FormDataParser::Create(request)),
111 success_(parser_.get() != NULL), 113 success_(parser_.get() != NULL),
112 dictionary_(success_ ? new DictionaryValue() : NULL) { 114 dictionary_(success_ ? new DictionaryValue() : NULL) {
113 } 115 }
114 116
115 ParsedDataPresenter::~ParsedDataPresenter() {} 117 ParsedDataPresenter::~ParsedDataPresenter() {}
116 118
117 void ParsedDataPresenter::FeedNext(const net::UploadElement& element) { 119 void ParsedDataPresenter::FeedNext(const net::UploadElementReader& reader) {
118 if (!success_) 120 if (!success_)
119 return; 121 return;
120 122
121 if (element.type() != net::UploadElement::TYPE_BYTES) { 123 const net::UploadBytesElementReader* bytes_reader = reader.AsBytesReader();
124 if (!bytes_reader) {
122 return; 125 return;
123 } 126 }
124 if (!parser_->SetSource(base::StringPiece(element.bytes(), 127 if (!parser_->SetSource(base::StringPiece(bytes_reader->bytes(),
125 element.bytes_length()))) { 128 bytes_reader->length()))) {
126 Abort(); 129 Abort();
127 return; 130 return;
128 } 131 }
129 132
130 FormDataParser::Result result; 133 FormDataParser::Result result;
131 while (parser_->GetNextNameValue(&result)) { 134 while (parser_->GetNextNameValue(&result)) {
132 GetOrCreateList(dictionary_.get(), result.name())->Append( 135 GetOrCreateList(dictionary_.get(), result.name())->Append(
133 new StringValue(result.value())); 136 new StringValue(result.value()));
134 } 137 }
135 } 138 }
(...skipping 23 matching lines...) Expand all
159 dictionary_(success_ ? new DictionaryValue() : NULL) { 162 dictionary_(success_ ? new DictionaryValue() : NULL) {
160 } 163 }
161 164
162 void ParsedDataPresenter::Abort() { 165 void ParsedDataPresenter::Abort() {
163 success_ = false; 166 success_ = false;
164 dictionary_.reset(); 167 dictionary_.reset();
165 parser_.reset(); 168 parser_.reset();
166 } 169 }
167 170
168 } // namespace extensions 171 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698