| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" |
| 9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 10 #include "base/metrics/stats_counters.h" | 11 #include "base/metrics/stats_counters.h" |
| 11 #include "base/singleton.h" | |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/host_resolver.h" | 15 #include "net/base/host_resolver.h" |
| 16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/ssl_config_service.h" | 18 #include "net/base/ssl_config_service.h" |
| 19 #include "net/http/http_auth_handler_factory.h" | 19 #include "net/http/http_auth_handler_factory.h" |
| 20 #include "net/http/http_cache.h" | 20 #include "net/http/http_cache.h" |
| 21 #include "net/http/http_network_layer.h" | 21 #include "net/http/http_network_layer.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 void ClientStopped() { | 40 void ClientStopped() { |
| 41 if (!--clients_) { | 41 if (!--clients_) { |
| 42 MessageLoop::current()->Quit(); | 42 MessageLoop::current()->Quit(); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 int clients_; | 47 int clients_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 static base::LazyInstance<Driver> g_driver(base::LINKER_INITIALIZED); |
| 51 |
| 50 // A network client | 52 // A network client |
| 51 class Client { | 53 class Client { |
| 52 public: | 54 public: |
| 53 Client(net::HttpTransactionFactory* factory, const std::string& url) : | 55 Client(net::HttpTransactionFactory* factory, const std::string& url) : |
| 54 url_(url), | 56 url_(url), |
| 55 buffer_(new net::IOBuffer(kBufferSize)), | 57 buffer_(new net::IOBuffer(kBufferSize)), |
| 56 ALLOW_THIS_IN_INITIALIZER_LIST( | 58 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 57 connect_callback_(this, &Client::OnConnectComplete)), | 59 connect_callback_(this, &Client::OnConnectComplete)), |
| 58 ALLOW_THIS_IN_INITIALIZER_LIST( | 60 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 59 read_callback_(this, &Client::OnReadComplete)) { | 61 read_callback_(this, &Client::OnReadComplete)) { |
| 60 int rv = factory->CreateTransaction(&transaction_); | 62 int rv = factory->CreateTransaction(&transaction_); |
| 61 DCHECK_EQ(net::OK, rv); | 63 DCHECK_EQ(net::OK, rv); |
| 62 buffer_->AddRef(); | 64 buffer_->AddRef(); |
| 63 driver_->ClientStarted(); | 65 g_driver.Get().ClientStarted(); |
| 64 request_info_.url = url_; | 66 request_info_.url = url_; |
| 65 request_info_.method = "GET"; | 67 request_info_.method = "GET"; |
| 66 int state = transaction_->Start( | 68 int state = transaction_->Start( |
| 67 &request_info_, &connect_callback_, net::BoundNetLog()); | 69 &request_info_, &connect_callback_, net::BoundNetLog()); |
| 68 DCHECK(state == net::ERR_IO_PENDING); | 70 DCHECK(state == net::ERR_IO_PENDING); |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 private: | 73 private: |
| 72 void OnConnectComplete(int result) { | 74 void OnConnectComplete(int result) { |
| 73 // Do work here. | 75 // Do work here. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 94 if (state == net::ERR_IO_PENDING) | 96 if (state == net::ERR_IO_PENDING) |
| 95 return; // IO has started. | 97 return; // IO has started. |
| 96 if (state < 0) | 98 if (state < 0) |
| 97 return; // ERROR! | 99 return; // ERROR! |
| 98 OnReadComplete(state); | 100 OnReadComplete(state); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void OnRequestComplete(int result) { | 103 void OnRequestComplete(int result) { |
| 102 static base::StatsCounter requests("FetchClient.requests"); | 104 static base::StatsCounter requests("FetchClient.requests"); |
| 103 requests.Increment(); | 105 requests.Increment(); |
| 104 driver_->ClientStopped(); | 106 g_driver.Get().ClientStopped(); |
| 105 printf("."); | 107 printf("."); |
| 106 } | 108 } |
| 107 | 109 |
| 108 static const int kBufferSize = (16 * 1024); | 110 static const int kBufferSize = (16 * 1024); |
| 109 GURL url_; | 111 GURL url_; |
| 110 net::HttpRequestInfo request_info_; | 112 net::HttpRequestInfo request_info_; |
| 111 scoped_ptr<net::HttpTransaction> transaction_; | 113 scoped_ptr<net::HttpTransaction> transaction_; |
| 112 scoped_refptr<net::IOBuffer> buffer_; | 114 scoped_refptr<net::IOBuffer> buffer_; |
| 113 net::CompletionCallbackImpl<Client> connect_callback_; | 115 net::CompletionCallbackImpl<Client> connect_callback_; |
| 114 net::CompletionCallbackImpl<Client> read_callback_; | 116 net::CompletionCallbackImpl<Client> read_callback_; |
| 115 Singleton<Driver> driver_; | |
| 116 }; | 117 }; |
| 117 | 118 |
| 118 int main(int argc, char**argv) { | 119 int main(int argc, char**argv) { |
| 119 base::AtExitManager exit; | 120 base::AtExitManager exit; |
| 120 base::StatsTable table("fetchclient", 50, 1000); | 121 base::StatsTable table("fetchclient", 50, 1000); |
| 121 table.set_current(&table); | 122 table.set_current(&table); |
| 122 | 123 |
| 123 CommandLine::Init(argc, argv); | 124 CommandLine::Init(argc, argv); |
| 124 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 125 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 125 std::string url = parsed_command_line.GetSwitchValueASCII("url"); | 126 std::string url = parsed_command_line.GetSwitchValueASCII("url"); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 std::string name(table.GetRowName(index)); | 208 std::string name(table.GetRowName(index)); |
| 208 if (name.length() > 0) { | 209 if (name.length() > 0) { |
| 209 int value = table.GetRowValue(index); | 210 int value = table.GetRowValue(index); |
| 210 printf("%s:\t%d\n", name.c_str(), value); | 211 printf("%s:\t%d\n", name.c_str(), value); |
| 211 } | 212 } |
| 212 } | 213 } |
| 213 printf("</stats>\n"); | 214 printf("</stats>\n"); |
| 214 } | 215 } |
| 215 return 0; | 216 return 0; |
| 216 } | 217 } |
| OLD | NEW |