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