OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PROXY_MESSAGE_READER_H_ |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PROXY_MESSAGE_READER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 // This class handles reading bits and pieces of input data and assembling them |
| 13 // into a set of newline-delimited lines. Each message is terminated by a blank |
| 14 // line. (Think HTTP, SMTP, etc.) |
| 15 // It is used in the (tiny) helper binary as well as the browser process, so it |
| 16 // must not have any dependencies beyond standard libraries. |
| 17 class MessageReader { |
| 18 public: |
| 19 MessageReader() : is_complete_(false) { lines_.resize(1); } |
| 20 |
| 21 // Returns the number of characters actually used; on end-of-message, |
| 22 // this may be smaller than |size|, but should otherwise be equal. |
| 23 // It is an error to call HandleData() if is_complete() would return true. |
| 24 size_t HandleData(const char* data, size_t size); |
| 25 |
| 26 bool is_complete() const { return is_complete_; } |
| 27 const std::vector<std::string>& lines() const { return lines_; } |
| 28 |
| 29 // Resets internal state so the reader will be ready for another message. |
| 30 void Reset() { |
| 31 lines_.clear(); |
| 32 lines_.resize(1); |
| 33 is_complete_ = false; |
| 34 } |
| 35 |
| 36 private: |
| 37 bool is_complete_; |
| 38 std::vector<std::string> lines_; |
| 39 }; |
| 40 |
| 41 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PROXY_MESSAGE_READER_H_ |
OLD | NEW |