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 #include "chrome/browser/password_manager/keyring_proxy/message_reader.h" |
| 6 |
| 7 // This library is part of a very small helper binary that runs without any |
| 8 // dependencies on base. Thus we can't use normal logging; we use assert. |
| 9 #include <assert.h> |
| 10 |
| 11 namespace keyring_proxy { |
| 12 |
| 13 size_t MessageReader::HandleData(const char* data, size_t size) { |
| 14 assert(!is_complete_); |
| 15 size_t used = 0; |
| 16 while (used < size) { |
| 17 size_t end; |
| 18 for (end = used; end < size && data[end] != '\n'; ++end) {} |
| 19 lines_.back().append(&data[used], end - used); |
| 20 if (end < size) { |
| 21 // We found a newline. Skip past it and figure out what to do. |
| 22 used = end + 1; |
| 23 if (lines_.back().size() > 0) { |
| 24 // The previous line was not empty. Start a new one. |
| 25 lines_.resize(lines_.size() + 1); |
| 26 } else { |
| 27 // If the previous line was empty, this message is complete. |
| 28 lines_.resize(lines_.size() - 1); |
| 29 is_complete_ = true; |
| 30 break; |
| 31 } |
| 32 } else { |
| 33 // There was no newline, just the end of the input. Skip to the end. |
| 34 used = end; |
| 35 } |
| 36 } |
| 37 return used; |
| 38 } |
| 39 |
| 40 } // namespace keyring_proxy |
OLD | NEW |