OLD | NEW |
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 "extensions/browser/api/web_request/upload_data_presenter.h" | 5 #include "extensions/browser/api/web_request/upload_data_presenter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "extensions/browser/api/web_request/form_data_parser.h" | 13 #include "extensions/browser/api/web_request/form_data_parser.h" |
14 #include "extensions/browser/api/web_request/web_request_api_constants.h" | 14 #include "extensions/browser/api/web_request/web_request_api_constants.h" |
15 #include "net/base/upload_bytes_element_reader.h" | 15 #include "net/base/upload_bytes_element_reader.h" |
16 #include "net/base/upload_file_element_reader.h" | 16 #include "net/base/upload_file_element_reader.h" |
17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
18 | 18 |
19 using base::BinaryValue; | |
20 using base::DictionaryValue; | 19 using base::DictionaryValue; |
21 using base::ListValue; | 20 using base::ListValue; |
22 using base::Value; | 21 using base::Value; |
23 | 22 |
24 namespace keys = extension_web_request_api_constants; | 23 namespace keys = extension_web_request_api_constants; |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 // Takes |dictionary| of <string, list of strings> pairs, and gets the list | 27 // Takes |dictionary| of <string, list of strings> pairs, and gets the list |
29 // for |key|, creating it if necessary. | 28 // for |key|, creating it if necessary. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 82 |
84 std::unique_ptr<base::Value> RawDataPresenter::Result() { | 83 std::unique_ptr<base::Value> RawDataPresenter::Result() { |
85 if (!success_) | 84 if (!success_) |
86 return nullptr; | 85 return nullptr; |
87 | 86 |
88 return std::move(list_); | 87 return std::move(list_); |
89 } | 88 } |
90 | 89 |
91 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { | 90 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { |
92 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, | 91 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, |
93 BinaryValue::CreateWithCopiedBuffer(bytes, size), | 92 Value::CreateWithCopiedBuffer(bytes, size), |
94 list_.get()); | 93 list_.get()); |
95 } | 94 } |
96 | 95 |
97 void RawDataPresenter::FeedNextFile(const std::string& filename) { | 96 void RawDataPresenter::FeedNextFile(const std::string& filename) { |
98 // Insert the file path instead of the contents, which may be too large. | 97 // Insert the file path instead of the contents, which may be too large. |
99 subtle::AppendKeyValuePair(keys::kRequestBodyRawFileKey, | 98 subtle::AppendKeyValuePair(keys::kRequestBodyRawFileKey, |
100 base::MakeUnique<base::Value>(filename), | 99 base::MakeUnique<base::Value>(filename), |
101 list_.get()); | 100 list_.get()); |
102 } | 101 } |
103 | 102 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 dictionary_(success_ ? new base::DictionaryValue() : NULL) { | 155 dictionary_(success_ ? new base::DictionaryValue() : NULL) { |
157 } | 156 } |
158 | 157 |
159 void ParsedDataPresenter::Abort() { | 158 void ParsedDataPresenter::Abort() { |
160 success_ = false; | 159 success_ = false; |
161 dictionary_.reset(); | 160 dictionary_.reset(); |
162 parser_.reset(); | 161 parser_.reset(); |
163 } | 162 } |
164 | 163 |
165 } // namespace extensions | 164 } // namespace extensions |
OLD | NEW |