| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 5 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 6 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 7 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/test/mock_entropy_provider.h" | 11 #include "base/test/mock_entropy_provider.h" |
| 9 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "build/build_config.h" |
| 10 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 11 #include "net/test/embedded_test_server/embedded_test_server.h" | 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 12 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 13 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
| 14 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 15 #include "sync/internal_api/public/base/cancelation_signal.h" | 19 #include "sync/internal_api/public/base/cancelation_signal.h" |
| 16 #include "sync/internal_api/public/http_bridge.h" | 20 #include "sync/internal_api/public/http_bridge.h" |
| 17 #include "sync/internal_api/public/http_post_provider_factory.h" | 21 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/zlib/zlib.h" | 23 #include "third_party/zlib/zlib.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return Z_DATA_ERROR; | 76 return Z_DATA_ERROR; |
| 73 return err; | 77 return err; |
| 74 } | 78 } |
| 75 *dest_length = stream.total_out; | 79 *dest_length = stream.total_out; |
| 76 | 80 |
| 77 err = inflateEnd(&stream); | 81 err = inflateEnd(&stream); |
| 78 return err; | 82 return err; |
| 79 } | 83 } |
| 80 | 84 |
| 81 // Returns the uncompressed size from GZIP-compressed |compressed_data|. | 85 // Returns the uncompressed size from GZIP-compressed |compressed_data|. |
| 82 uint32 GetUncompressedSize(const std::string& compressed_data) { | 86 uint32_t GetUncompressedSize(const std::string& compressed_data) { |
| 83 // The uncompressed size is stored in the last 4 bytes of |input| in LE. | 87 // The uncompressed size is stored in the last 4 bytes of |input| in LE. |
| 84 uint32 size; | 88 uint32_t size; |
| 85 if (compressed_data.length() < sizeof(size)) | 89 if (compressed_data.length() < sizeof(size)) |
| 86 return 0; | 90 return 0; |
| 87 memcpy(&size, &compressed_data[compressed_data.length() - sizeof(size)], | 91 memcpy(&size, &compressed_data[compressed_data.length() - sizeof(size)], |
| 88 sizeof(size)); | 92 sizeof(size)); |
| 89 return base::ByteSwapToLE32(size); | 93 return base::ByteSwapToLE32(size); |
| 90 } | 94 } |
| 91 | 95 |
| 92 bool GzipUncompress(const std::string& input, std::string* output) { | 96 bool GzipUncompress(const std::string& input, std::string* output) { |
| 93 std::string uncompressed_output; | 97 std::string uncompressed_output; |
| 94 uLongf uncompressed_size = static_cast<uLongf>(GetUncompressedSize(input)); | 98 uLongf uncompressed_size = static_cast<uLongf>(GetUncompressedSize(input)); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 | 681 |
| 678 // Sync thread: Finally run the posted task, only to find that our | 682 // Sync thread: Finally run the posted task, only to find that our |
| 679 // HttpBridgeFactory has been neutered. Should not crash. | 683 // HttpBridgeFactory has been neutered. Should not crash. |
| 680 factory->Init("TestUserAgent", BindToTrackerCallback()); | 684 factory->Init("TestUserAgent", BindToTrackerCallback()); |
| 681 | 685 |
| 682 // At this point, attempting to use the factory would trigger a crash. Both | 686 // At this point, attempting to use the factory would trigger a crash. Both |
| 683 // this test and the real world code should make sure this never happens. | 687 // this test and the real world code should make sure this never happens. |
| 684 } | 688 } |
| 685 | 689 |
| 686 } // namespace syncer | 690 } // namespace syncer |
| OLD | NEW |