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/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "extensions/browser/api/web_request/form_data_parser.h" | 13 #include "extensions/browser/api/web_request/form_data_parser.h" |
13 #include "extensions/browser/api/web_request/web_request_api_constants.h" | 14 #include "extensions/browser/api/web_request/web_request_api_constants.h" |
14 #include "net/base/upload_bytes_element_reader.h" | 15 #include "net/base/upload_bytes_element_reader.h" |
15 #include "net/base/upload_file_element_reader.h" | 16 #include "net/base/upload_file_element_reader.h" |
16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
17 | 18 |
18 using base::BinaryValue; | 19 using base::BinaryValue; |
19 using base::DictionaryValue; | 20 using base::DictionaryValue; |
(...skipping 17 matching lines...) Expand all Loading... |
37 return list; | 38 return list; |
38 } | 39 } |
39 | 40 |
40 } // namespace | 41 } // namespace |
41 | 42 |
42 namespace extensions { | 43 namespace extensions { |
43 | 44 |
44 namespace subtle { | 45 namespace subtle { |
45 | 46 |
46 void AppendKeyValuePair(const char* key, | 47 void AppendKeyValuePair(const char* key, |
47 base::Value* value, | 48 std::unique_ptr<base::Value> value, |
48 base::ListValue* list) { | 49 base::ListValue* list) { |
49 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 50 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
50 dictionary->SetWithoutPathExpansion(key, value); | 51 dictionary->SetWithoutPathExpansion(key, std::move(value)); |
51 list->Append(std::move(dictionary)); | 52 list->Append(std::move(dictionary)); |
52 } | 53 } |
53 | 54 |
54 } // namespace subtle | 55 } // namespace subtle |
55 | 56 |
56 UploadDataPresenter::~UploadDataPresenter() {} | 57 UploadDataPresenter::~UploadDataPresenter() {} |
57 | 58 |
58 RawDataPresenter::RawDataPresenter() | 59 RawDataPresenter::RawDataPresenter() |
59 : success_(true), | 60 : success_(true), |
60 list_(new base::ListValue) { | 61 list_(new base::ListValue) { |
(...skipping 29 matching lines...) Expand all Loading... |
90 | 91 |
91 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { | 92 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { |
92 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, | 93 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, |
93 BinaryValue::CreateWithCopiedBuffer(bytes, size), | 94 BinaryValue::CreateWithCopiedBuffer(bytes, size), |
94 list_.get()); | 95 list_.get()); |
95 } | 96 } |
96 | 97 |
97 void RawDataPresenter::FeedNextFile(const std::string& filename) { | 98 void RawDataPresenter::FeedNextFile(const std::string& filename) { |
98 // Insert the file path instead of the contents, which may be too large. | 99 // Insert the file path instead of the contents, which may be too large. |
99 subtle::AppendKeyValuePair(keys::kRequestBodyRawFileKey, | 100 subtle::AppendKeyValuePair(keys::kRequestBodyRawFileKey, |
100 new base::StringValue(filename), | 101 base::MakeUnique<base::StringValue>(filename), |
101 list_.get()); | 102 list_.get()); |
102 } | 103 } |
103 | 104 |
104 ParsedDataPresenter::ParsedDataPresenter(const net::URLRequest& request) | 105 ParsedDataPresenter::ParsedDataPresenter(const net::URLRequest& request) |
105 : parser_(FormDataParser::Create(request)), | 106 : parser_(FormDataParser::Create(request)), |
106 success_(parser_.get() != NULL), | 107 success_(parser_.get() != NULL), |
107 dictionary_(success_ ? new base::DictionaryValue() : NULL) { | 108 dictionary_(success_ ? new base::DictionaryValue() : NULL) { |
108 } | 109 } |
109 | 110 |
110 ParsedDataPresenter::~ParsedDataPresenter() {} | 111 ParsedDataPresenter::~ParsedDataPresenter() {} |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 dictionary_(success_ ? new base::DictionaryValue() : NULL) { | 157 dictionary_(success_ ? new base::DictionaryValue() : NULL) { |
157 } | 158 } |
158 | 159 |
159 void ParsedDataPresenter::Abort() { | 160 void ParsedDataPresenter::Abort() { |
160 success_ = false; | 161 success_ = false; |
161 dictionary_.reset(); | 162 dictionary_.reset(); |
162 parser_.reset(); | 163 parser_.reset(); |
163 } | 164 } |
164 | 165 |
165 } // namespace extensions | 166 } // namespace extensions |
OLD | NEW |