| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 FeedNextFile(file_reader->path().AsUTF8Unsafe()); | 74 FeedNextFile(file_reader->path().AsUTF8Unsafe()); |
| 75 } else { | 75 } else { |
| 76 NOTIMPLEMENTED(); | 76 NOTIMPLEMENTED(); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool RawDataPresenter::Succeeded() { | 80 bool RawDataPresenter::Succeeded() { |
| 81 return success_; | 81 return success_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 scoped_ptr<base::Value> RawDataPresenter::Result() { | 84 std::unique_ptr<base::Value> RawDataPresenter::Result() { |
| 85 if (!success_) | 85 if (!success_) |
| 86 return nullptr; | 86 return nullptr; |
| 87 | 87 |
| 88 return std::move(list_); | 88 return std::move(list_); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { | 91 void RawDataPresenter::FeedNextBytes(const char* bytes, size_t size) { |
| 92 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, | 92 subtle::AppendKeyValuePair(keys::kRequestBodyRawBytesKey, |
| 93 BinaryValue::CreateWithCopiedBuffer(bytes, size), | 93 BinaryValue::CreateWithCopiedBuffer(bytes, size), |
| 94 list_.get()); | 94 list_.get()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 new base::StringValue(result.value())); | 129 new base::StringValue(result.value())); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool ParsedDataPresenter::Succeeded() { | 133 bool ParsedDataPresenter::Succeeded() { |
| 134 if (success_ && !parser_->AllDataReadOK()) | 134 if (success_ && !parser_->AllDataReadOK()) |
| 135 Abort(); | 135 Abort(); |
| 136 return success_; | 136 return success_; |
| 137 } | 137 } |
| 138 | 138 |
| 139 scoped_ptr<base::Value> ParsedDataPresenter::Result() { | 139 std::unique_ptr<base::Value> ParsedDataPresenter::Result() { |
| 140 if (!success_) | 140 if (!success_) |
| 141 return nullptr; | 141 return nullptr; |
| 142 | 142 |
| 143 return std::move(dictionary_); | 143 return std::move(dictionary_); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // static | 146 // static |
| 147 scoped_ptr<ParsedDataPresenter> ParsedDataPresenter::CreateForTests() { | 147 std::unique_ptr<ParsedDataPresenter> ParsedDataPresenter::CreateForTests() { |
| 148 const std::string form_type("application/x-www-form-urlencoded"); | 148 const std::string form_type("application/x-www-form-urlencoded"); |
| 149 return scoped_ptr<ParsedDataPresenter>(new ParsedDataPresenter(form_type)); | 149 return std::unique_ptr<ParsedDataPresenter>( |
| 150 new ParsedDataPresenter(form_type)); |
| 150 } | 151 } |
| 151 | 152 |
| 152 ParsedDataPresenter::ParsedDataPresenter(const std::string& form_type) | 153 ParsedDataPresenter::ParsedDataPresenter(const std::string& form_type) |
| 153 : parser_(FormDataParser::CreateFromContentTypeHeader(&form_type)), | 154 : parser_(FormDataParser::CreateFromContentTypeHeader(&form_type)), |
| 154 success_(parser_.get() != NULL), | 155 success_(parser_.get() != NULL), |
| 155 dictionary_(success_ ? new base::DictionaryValue() : NULL) { | 156 dictionary_(success_ ? new base::DictionaryValue() : NULL) { |
| 156 } | 157 } |
| 157 | 158 |
| 158 void ParsedDataPresenter::Abort() { | 159 void ParsedDataPresenter::Abort() { |
| 159 success_ = false; | 160 success_ = false; |
| 160 dictionary_.reset(); | 161 dictionary_.reset(); |
| 161 parser_.reset(); | 162 parser_.reset(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 } // namespace extensions | 165 } // namespace extensions |
| OLD | NEW |