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 "chrome/browser/sessions/compress_data_helper.h" | 5 #include "chrome/browser/sessions/compress_data_helper.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 | 9 |
10 #if defined(USE_SYSTEM_LIBBZ2) | 10 #if defined(USE_SYSTEM_LIBBZ2) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 if (!written) { | 77 if (!written) { |
78 // We cannot write any data. Write only the data size (0). The reading part | 78 // We cannot write any data. Write only the data size (0). The reading part |
79 // will not try to read any data after seeing the size 0. | 79 // will not try to read any data after seeing the size 0. |
80 pickle->WriteInt(0); | 80 pickle->WriteInt(0); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 // static | 84 // static |
85 bool CompressDataHelper::ReadAndDecompressStringFromPickle(const Pickle& pickle, | 85 bool CompressDataHelper::ReadAndDecompressStringFromPickle(const Pickle& pickle, |
86 void** iter, | 86 PickleIterator* iter, |
87 std::string* str) { | 87 std::string* str) { |
88 // Read the size of the original data. | 88 // Read the size of the original data. |
89 int original_size = 0; | 89 int original_size = 0; |
90 if (!pickle.ReadLength(iter, &original_size)) | 90 if (!pickle.ReadLength(iter, &original_size)) |
91 return false; | 91 return false; |
92 | 92 |
93 if (original_size == 0) { | 93 if (original_size == 0) { |
94 // No data to decompress. | 94 // No data to decompress. |
95 return true; | 95 return true; |
96 } | 96 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 result = BZ2_bzDecompressEnd(&stream); | 132 result = BZ2_bzDecompressEnd(&stream); |
133 if (result == BZ_OK) { | 133 if (result == BZ_OK) { |
134 str->assign(original_data.get(), original_size); | 134 str->assign(original_data.get(), original_size); |
135 } | 135 } |
136 } else { | 136 } else { |
137 BZ2_bzDecompressEnd(&stream); | 137 BZ2_bzDecompressEnd(&stream); |
138 } | 138 } |
139 } | 139 } |
140 return !str->empty(); | 140 return !str->empty(); |
141 } | 141 } |
OLD | NEW |