Chromium Code Reviews| 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 "chrome/browser/dom_ui/net_internals_ui.h" | 5 #include "chrome/browser/dom_ui/net_internals_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/browser_thread.h" | 24 #include "chrome/browser/browser_thread.h" |
| 25 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 25 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 26 #include "chrome/browser/io_thread.h" | 26 #include "chrome/browser/io_thread.h" |
| 27 #include "chrome/browser/net/chrome_net_log.h" | 27 #include "chrome/browser/net/chrome_net_log.h" |
| 28 #include "chrome/browser/net/connection_tester.h" | 28 #include "chrome/browser/net/connection_tester.h" |
| 29 #include "chrome/browser/net/passive_log_collector.h" | 29 #include "chrome/browser/net/passive_log_collector.h" |
| 30 #include "chrome/browser/net/url_fixer_upper.h" | 30 #include "chrome/browser/net/url_fixer_upper.h" |
| 31 #include "chrome/browser/platform_util.h" | 31 #include "chrome/browser/platform_util.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/shell_dialogs.h" | |
| 34 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 35 #include "chrome/browser/tab_contents/tab_contents_view.h" | |
| 33 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
| 34 #include "chrome/common/chrome_version_info.h" | 37 #include "chrome/common/chrome_version_info.h" |
| 35 #include "chrome/common/jstemplate_builder.h" | 38 #include "chrome/common/jstemplate_builder.h" |
| 36 #include "chrome/common/net/url_request_context_getter.h" | 39 #include "chrome/common/net/url_request_context_getter.h" |
| 37 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 38 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| 39 #include "grit/net_internals_resources.h" | 42 #include "grit/net_internals_resources.h" |
| 40 #include "net/base/escape.h" | 43 #include "net/base/escape.h" |
| 41 #include "net/base/host_resolver_impl.h" | 44 #include "net/base/host_resolver_impl.h" |
| 42 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 43 #include "net/base/net_util.h" | 46 #include "net/base/net_util.h" |
| 44 #include "net/base/sys_addrinfo.h" | 47 #include "net/base/sys_addrinfo.h" |
| 45 #include "net/disk_cache/disk_cache.h" | 48 #include "net/disk_cache/disk_cache.h" |
| 46 #include "net/http/http_cache.h" | 49 #include "net/http/http_cache.h" |
| 47 #include "net/http/http_network_layer.h" | 50 #include "net/http/http_network_layer.h" |
| 48 #include "net/http/http_network_session.h" | 51 #include "net/http/http_network_session.h" |
| 49 #include "net/proxy/proxy_service.h" | 52 #include "net/proxy/proxy_service.h" |
| 50 #include "net/url_request/url_request_context.h" | 53 #include "net/url_request/url_request_context.h" |
| 51 #ifdef OS_WIN | 54 #ifdef OS_WIN |
| 52 #include "chrome/browser/net/service_providers_win.h" | 55 #include "chrome/browser/net/service_providers_win.h" |
| 53 #endif | 56 #endif |
| 54 | 57 |
| 55 namespace { | 58 namespace { |
| 56 | 59 |
| 60 // Delay between when an event occurs and when it is passed to the Javascript | |
| 61 // page. All events that occur during this period are grouped together and | |
| 62 // sent to the page at once, which reduces context switching and CPU usage. | |
| 63 const int kNetLogEventDelayMilliseconds = 100; | |
| 64 | |
| 57 // Returns the HostCache for |context|'s primary HostResolver, or NULL if | 65 // Returns the HostCache for |context|'s primary HostResolver, or NULL if |
| 58 // there is none. | 66 // there is none. |
| 59 net::HostCache* GetHostResolverCache(URLRequestContext* context) { | 67 net::HostCache* GetHostResolverCache(URLRequestContext* context) { |
| 60 net::HostResolverImpl* host_resolver_impl = | 68 net::HostResolverImpl* host_resolver_impl = |
| 61 context->host_resolver()->GetAsHostResolverImpl(); | 69 context->host_resolver()->GetAsHostResolverImpl(); |
| 62 | 70 |
| 63 if (!host_resolver_impl) | 71 if (!host_resolver_impl) |
| 64 return NULL; | 72 return NULL; |
| 65 | 73 |
| 66 return host_resolver_impl->cache(); | 74 return host_resolver_impl->cache(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 // Note that the DOMUI infrastructure runs on the UI thread, therefore all of | 130 // Note that the DOMUI infrastructure runs on the UI thread, therefore all of |
| 123 // this class's methods are expected to run on the UI thread. | 131 // this class's methods are expected to run on the UI thread. |
| 124 // | 132 // |
| 125 // Since the network code we want to run lives on the IO thread, we proxy | 133 // Since the network code we want to run lives on the IO thread, we proxy |
| 126 // everything over to NetInternalsMessageHandler::IOThreadImpl, which runs | 134 // everything over to NetInternalsMessageHandler::IOThreadImpl, which runs |
| 127 // on the IO thread. | 135 // on the IO thread. |
| 128 // | 136 // |
| 129 // TODO(eroman): Can we start on the IO thread to begin with? | 137 // TODO(eroman): Can we start on the IO thread to begin with? |
| 130 class NetInternalsMessageHandler | 138 class NetInternalsMessageHandler |
| 131 : public DOMMessageHandler, | 139 : public DOMMessageHandler, |
| 140 public SelectFileDialog::Listener, | |
| 132 public base::SupportsWeakPtr<NetInternalsMessageHandler> { | 141 public base::SupportsWeakPtr<NetInternalsMessageHandler> { |
| 133 public: | 142 public: |
| 134 NetInternalsMessageHandler(); | 143 NetInternalsMessageHandler(); |
| 135 virtual ~NetInternalsMessageHandler(); | 144 virtual ~NetInternalsMessageHandler(); |
| 136 | 145 |
| 137 // DOMMessageHandler implementation. | 146 // DOMMessageHandler implementation. |
| 138 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 147 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 139 virtual void RegisterMessages(); | 148 virtual void RegisterMessages(); |
| 140 | 149 |
| 141 // Executes the javascript function |function_name| in the renderer, passing | 150 // Executes the javascript function |function_name| in the renderer, passing |
| 142 // it the argument |value|. | 151 // it the argument |value|. |
| 143 void CallJavascriptFunction(const std::wstring& function_name, | 152 void CallJavascriptFunction(const std::wstring& function_name, |
| 144 const Value* value); | 153 const Value* value); |
| 145 | 154 |
| 155 // SelectFileDialog::Listener implementation | |
| 156 virtual void FileSelected(const FilePath& path, int index, void* params); | |
| 157 virtual void FileSelectionCanceled(void* params); | |
| 158 | |
| 159 // The only callback handled on the UI thread. As it needs to access fields | |
| 160 // from |dom_ui_|, it can't be called on the IO thread. | |
| 161 void OnLoadLogFile(const ListValue* list); | |
| 162 | |
| 146 private: | 163 private: |
| 147 class IOThreadImpl; | 164 class IOThreadImpl; |
| 148 | 165 |
| 166 // Task run on the FILE thread to read the contents of a log file. The result | |
| 167 // is then passed to IOThreadImpl's CallJavascriptFunction, which sends it | |
| 168 // back to the web page. IOThreadImpl is used instead of the | |
| 169 // NetInternalsMessageHandler directly because it checks if the message | |
| 170 // handler has been destroyed in the meantime. | |
| 171 class ReadLogFileTask : public Task { | |
| 172 public: | |
| 173 ReadLogFileTask(IOThreadImpl* proxy, const FilePath& path); | |
| 174 | |
| 175 virtual void Run(); | |
| 176 | |
| 177 private: | |
| 178 // IOThreadImpl implements existence checks already. Simpler to reused them | |
| 179 // then to reimplement them. | |
| 180 scoped_refptr<IOThreadImpl> proxy_; | |
| 181 | |
| 182 // Path of the file to open. | |
| 183 const FilePath path_; | |
| 184 }; | |
| 185 | |
| 149 // This is the "real" message handler, which lives on the IO thread. | 186 // This is the "real" message handler, which lives on the IO thread. |
| 150 scoped_refptr<IOThreadImpl> proxy_; | 187 scoped_refptr<IOThreadImpl> proxy_; |
| 151 | 188 |
| 189 // Used for loading log files. | |
| 190 scoped_refptr<SelectFileDialog> select_log_file_dialog_; | |
| 191 | |
| 152 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler); | 192 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler); |
| 153 }; | 193 }; |
| 154 | 194 |
| 155 // This class is the "real" message handler. It is allocated and destroyed on | 195 // This class is the "real" message handler. It is allocated and destroyed on |
| 156 // the UI thread. With the exception of OnAddEntry, OnDOMUIDeleted, and | 196 // the UI thread. With the exception of OnAddEntry, OnDOMUIDeleted, and |
| 157 // CallJavascriptFunction, its methods are all expected to be called from the IO | 197 // CallJavascriptFunction, its methods are all expected to be called from the IO |
| 158 // thread. OnAddEntry and CallJavascriptFunction can be called from any thread, | 198 // thread. OnAddEntry and CallJavascriptFunction can be called from any thread, |
| 159 // and OnDOMUIDeleted can only be called from the UI thread. | 199 // and OnDOMUIDeleted can only be called from the UI thread. |
| 160 class NetInternalsMessageHandler::IOThreadImpl | 200 class NetInternalsMessageHandler::IOThreadImpl |
| 161 : public base::RefCountedThreadSafe< | 201 : public base::RefCountedThreadSafe< |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 | 269 |
| 230 // ConnectionTester::Delegate implementation: | 270 // ConnectionTester::Delegate implementation: |
| 231 virtual void OnStartConnectionTestSuite(); | 271 virtual void OnStartConnectionTestSuite(); |
| 232 virtual void OnStartConnectionTestExperiment( | 272 virtual void OnStartConnectionTestExperiment( |
| 233 const ConnectionTester::Experiment& experiment); | 273 const ConnectionTester::Experiment& experiment); |
| 234 virtual void OnCompletedConnectionTestExperiment( | 274 virtual void OnCompletedConnectionTestExperiment( |
| 235 const ConnectionTester::Experiment& experiment, | 275 const ConnectionTester::Experiment& experiment, |
| 236 int result); | 276 int result); |
| 237 virtual void OnCompletedConnectionTestSuite(); | 277 virtual void OnCompletedConnectionTestSuite(); |
| 238 | 278 |
| 279 // Helper that executes |function_name| in the attached renderer. | |
| 280 // The function takes ownership of |arg|. Note that this can be called from | |
| 281 // any thread. | |
| 282 void CallJavascriptFunction(const std::wstring& function_name, Value* arg); | |
| 283 | |
| 239 private: | 284 private: |
| 240 class CallbackHelper; | 285 class CallbackHelper; |
| 241 | 286 |
| 242 // Helper that runs |method| with |arg|, and deletes |arg| on completion. | 287 // Helper that runs |method| with |arg|, and deletes |arg| on completion. |
| 243 void DispatchToMessageHandler(ListValue* arg, MessageHandler method); | 288 void DispatchToMessageHandler(ListValue* arg, MessageHandler method); |
| 244 | 289 |
| 245 // Helper that executes |function_name| in the attached renderer. | 290 // Adds |entry| to the queue of pending log entries to be sent to the page via |
| 246 // The function takes ownership of |arg|. Note that this can be called from | 291 // Javascript. Must be called on the IO Thread. Also creates a delayed task |
| 247 // any thread. | 292 // that will call PostPendingEntries, if there isn't one already. |
| 248 void CallJavascriptFunction(const std::wstring& function_name, | 293 void AddEntryToQueue(Value* entry); |
| 249 Value* arg); | 294 |
| 295 // Sends all pending entries to the page via Javascript, and clears the list | |
| 296 // of pending entries. Sending multiple entries at once results in a | |
| 297 // significant reduction of CPU usage when a lot of events are happening. | |
| 298 // Must be called on the IO Thread. | |
| 299 void PostPendingEntries(); | |
| 250 | 300 |
| 251 // Pointer to the UI-thread message handler. Only access this from | 301 // Pointer to the UI-thread message handler. Only access this from |
| 252 // the UI thread. | 302 // the UI thread. |
| 253 base::WeakPtr<NetInternalsMessageHandler> handler_; | 303 base::WeakPtr<NetInternalsMessageHandler> handler_; |
| 254 | 304 |
| 255 // The global IOThread, which contains the global NetLog to observer. | 305 // The global IOThread, which contains the global NetLog to observer. |
| 256 IOThread* io_thread_; | 306 IOThread* io_thread_; |
| 257 | 307 |
| 258 scoped_refptr<URLRequestContextGetter> context_getter_; | 308 scoped_refptr<URLRequestContextGetter> context_getter_; |
| 259 | 309 |
| 260 // Helper that runs the suite of connection tests. | 310 // Helper that runs the suite of connection tests. |
| 261 scoped_ptr<ConnectionTester> connection_tester_; | 311 scoped_ptr<ConnectionTester> connection_tester_; |
| 262 | 312 |
| 263 // True if the DOM UI has been deleted. This is used to prevent calling | 313 // True if the DOM UI has been deleted. This is used to prevent calling |
| 264 // Javascript functions after the DOM UI is destroyed. On refresh, the | 314 // Javascript functions after the DOM UI is destroyed. On refresh, the |
| 265 // messages can end up being sent to the refreshed page, causing duplicate | 315 // messages can end up being sent to the refreshed page, causing duplicate |
| 266 // or partial entries. | 316 // or partial entries. |
| 267 // | 317 // |
| 268 // This is only read and written to on the UI thread. | 318 // This is only read and written to on the UI thread. |
| 269 bool was_domui_deleted_; | 319 bool was_domui_deleted_; |
| 270 | 320 |
| 271 // True if we have attached an observer to the NetLog already. | 321 // True if we have attached an observer to the NetLog already. |
| 272 bool is_observing_log_; | 322 bool is_observing_log_; |
| 273 friend class base::RefCountedThreadSafe<IOThreadImpl>; | 323 friend class base::RefCountedThreadSafe<IOThreadImpl>; |
| 324 | |
| 325 // Log entries that have yet to be passed along to Javascript page. Non-NULL | |
| 326 // when and only when there is a pending delayed task to call | |
| 327 // PostPendingEntries. Read and written to exclusively on the IO Thread. | |
| 328 scoped_ptr<ListValue> pending_entries_; | |
| 274 }; | 329 }; |
| 275 | 330 |
| 276 // Helper class for a DOMUI::MessageCallback which when excuted calls | 331 // Helper class for a DOMUI::MessageCallback which when excuted calls |
| 277 // instance->*method(value) on the IO thread. | 332 // instance->*method(value) on the IO thread. |
| 278 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper | 333 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper |
| 279 : public DOMUI::MessageCallback { | 334 : public DOMUI::MessageCallback { |
| 280 public: | 335 public: |
| 281 CallbackHelper(IOThreadImpl* instance, IOThreadImpl::MessageHandler method) | 336 CallbackHelper(IOThreadImpl* instance, IOThreadImpl::MessageHandler method) |
| 282 : instance_(instance), | 337 : instance_(instance), |
| 283 method_(method) { | 338 method_(method) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 | 424 |
| 370 NetInternalsMessageHandler::NetInternalsMessageHandler() {} | 425 NetInternalsMessageHandler::NetInternalsMessageHandler() {} |
| 371 | 426 |
| 372 NetInternalsMessageHandler::~NetInternalsMessageHandler() { | 427 NetInternalsMessageHandler::~NetInternalsMessageHandler() { |
| 373 if (proxy_) { | 428 if (proxy_) { |
| 374 proxy_.get()->OnDOMUIDeleted(); | 429 proxy_.get()->OnDOMUIDeleted(); |
| 375 // Notify the handler on the IO thread that the renderer is gone. | 430 // Notify the handler on the IO thread that the renderer is gone. |
| 376 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 431 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 377 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); | 432 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); |
| 378 } | 433 } |
| 434 if (select_log_file_dialog_) | |
| 435 select_log_file_dialog_->ListenerDestroyed(); | |
| 379 } | 436 } |
| 380 | 437 |
| 381 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { | 438 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { |
| 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 383 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), | 440 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), |
| 384 dom_ui->GetProfile()->GetRequestContext()); | 441 dom_ui->GetProfile()->GetRequestContext()); |
| 385 DOMMessageHandler* result = DOMMessageHandler::Attach(dom_ui); | 442 DOMMessageHandler* result = DOMMessageHandler::Attach(dom_ui); |
| 386 return result; | 443 return result; |
| 387 } | 444 } |
| 388 | 445 |
| 446 void NetInternalsMessageHandler::FileSelected( | |
| 447 const FilePath& path, int index, void* params) { | |
| 448 select_log_file_dialog_.release(); | |
| 449 BrowserThread::PostTask( | |
| 450 BrowserThread::FILE, FROM_HERE, | |
| 451 new ReadLogFileTask(proxy_.get(), path)); | |
| 452 } | |
| 453 | |
| 454 void NetInternalsMessageHandler::FileSelectionCanceled(void* params) { | |
| 455 select_log_file_dialog_.release(); | |
| 456 } | |
| 457 | |
| 458 void NetInternalsMessageHandler::OnLoadLogFile(const ListValue* list) { | |
| 459 // Only allow a single dialog at a time. | |
| 460 if (select_log_file_dialog_.get()) | |
| 461 return; | |
| 462 select_log_file_dialog_ = SelectFileDialog::Create(this); | |
| 463 select_log_file_dialog_->SelectFile( | |
| 464 SelectFileDialog::SELECT_OPEN_FILE, string16(), FilePath(), NULL, 0, | |
| 465 FILE_PATH_LITERAL(""), | |
| 466 dom_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); | |
| 467 } | |
| 468 | |
| 389 void NetInternalsMessageHandler::RegisterMessages() { | 469 void NetInternalsMessageHandler::RegisterMessages() { |
| 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 471 // Only callback handled on UI thread. | |
| 472 dom_ui_->RegisterMessageCallback("loadLogFile", | |
|
eroman
2011/01/24 20:45:56
nit: can you break the line here, for consistency
mmenke
2011/01/25 20:08:13
Done. It also violated Google style guidelines.
| |
| 473 NewCallback(this, &NetInternalsMessageHandler::OnLoadLogFile)); | |
| 391 | 474 |
| 392 dom_ui_->RegisterMessageCallback( | 475 dom_ui_->RegisterMessageCallback( |
| 393 "notifyReady", | 476 "notifyReady", |
| 394 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); | 477 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); |
| 395 dom_ui_->RegisterMessageCallback( | 478 dom_ui_->RegisterMessageCallback( |
| 396 "getProxySettings", | 479 "getProxySettings", |
| 397 proxy_->CreateCallback(&IOThreadImpl::OnGetProxySettings)); | 480 proxy_->CreateCallback(&IOThreadImpl::OnGetProxySettings)); |
| 398 dom_ui_->RegisterMessageCallback( | 481 dom_ui_->RegisterMessageCallback( |
| 399 "reloadProxySettings", | 482 "reloadProxySettings", |
| 400 proxy_->CreateCallback(&IOThreadImpl::OnReloadProxySettings)); | 483 proxy_->CreateCallback(&IOThreadImpl::OnReloadProxySettings)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 443 if (value) { | 526 if (value) { |
| 444 dom_ui_->CallJavascriptFunction(function_name, *value); | 527 dom_ui_->CallJavascriptFunction(function_name, *value); |
| 445 } else { | 528 } else { |
| 446 dom_ui_->CallJavascriptFunction(function_name); | 529 dom_ui_->CallJavascriptFunction(function_name); |
| 447 } | 530 } |
| 448 } | 531 } |
| 449 | 532 |
| 450 //////////////////////////////////////////////////////////////////////////////// | 533 //////////////////////////////////////////////////////////////////////////////// |
| 451 // | 534 // |
| 535 // NetInternalsMessageHandler::ReadLogFileTask | |
| 536 // | |
| 537 //////////////////////////////////////////////////////////////////////////////// | |
| 538 | |
| 539 NetInternalsMessageHandler::ReadLogFileTask::ReadLogFileTask( | |
| 540 IOThreadImpl* proxy, const FilePath& path) | |
| 541 : proxy_(proxy), path_(path) { | |
| 542 } | |
| 543 | |
| 544 void NetInternalsMessageHandler::ReadLogFileTask::Run() { | |
| 545 std::string file_contents; | |
| 546 if (!file_util::ReadFileToString(path_, &file_contents)) | |
| 547 return; | |
| 548 proxy_->CallJavascriptFunction(L"g_browser.loadedLogFile", | |
| 549 new StringValue(file_contents)); | |
| 550 } | |
| 551 | |
| 552 //////////////////////////////////////////////////////////////////////////////// | |
| 553 // | |
| 452 // NetInternalsMessageHandler::IOThreadImpl | 554 // NetInternalsMessageHandler::IOThreadImpl |
| 453 // | 555 // |
| 454 //////////////////////////////////////////////////////////////////////////////// | 556 //////////////////////////////////////////////////////////////////////////////// |
| 455 | 557 |
| 456 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( | 558 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( |
| 457 const base::WeakPtr<NetInternalsMessageHandler>& handler, | 559 const base::WeakPtr<NetInternalsMessageHandler>& handler, |
| 458 IOThread* io_thread, | 560 IOThread* io_thread, |
| 459 URLRequestContextGetter* context_getter) | 561 URLRequestContextGetter* context_getter) |
| 460 : ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES), | 562 : ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES), |
| 461 handler_(handler), | 563 handler_(handler), |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 } | 1046 } |
| 945 | 1047 |
| 946 // Note that unlike other methods of IOThreadImpl, this function | 1048 // Note that unlike other methods of IOThreadImpl, this function |
| 947 // can be called from ANY THREAD. | 1049 // can be called from ANY THREAD. |
| 948 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 1050 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
| 949 net::NetLog::EventType type, | 1051 net::NetLog::EventType type, |
| 950 const base::TimeTicks& time, | 1052 const base::TimeTicks& time, |
| 951 const net::NetLog::Source& source, | 1053 const net::NetLog::Source& source, |
| 952 net::NetLog::EventPhase phase, | 1054 net::NetLog::EventPhase phase, |
| 953 net::NetLog::EventParameters* params) { | 1055 net::NetLog::EventParameters* params) { |
| 1056 BrowserThread::PostTask( | |
| 1057 BrowserThread::IO, FROM_HERE, | |
| 1058 NewRunnableMethod( | |
| 1059 this, &IOThreadImpl::AddEntryToQueue, | |
| 1060 net::NetLog::EntryToDictionaryValue(type, time, source, phase, | |
| 1061 params, false))); | |
| 1062 } | |
| 1063 | |
| 1064 void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue(Value* entry) { | |
| 1065 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 1066 if (!pending_entries_.get()) { | |
| 1067 pending_entries_.reset(new ListValue()); | |
| 1068 BrowserThread::PostDelayedTask( | |
| 1069 BrowserThread::IO, FROM_HERE, | |
| 1070 NewRunnableMethod(this, &IOThreadImpl::PostPendingEntries), | |
| 1071 kNetLogEventDelayMilliseconds); | |
| 1072 } | |
| 1073 pending_entries_->Append(entry); | |
| 1074 } | |
| 1075 | |
| 1076 void NetInternalsMessageHandler::IOThreadImpl::PostPendingEntries() { | |
| 1077 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 954 CallJavascriptFunction( | 1078 CallJavascriptFunction( |
| 955 L"g_browser.receivedLogEntry", | 1079 L"g_browser.receivedLogEntries", |
| 956 net::NetLog::EntryToDictionaryValue(type, time, source, phase, params, | 1080 pending_entries_.release()); |
| 957 false)); | |
| 958 } | 1081 } |
| 959 | 1082 |
| 960 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestSuite() { | 1083 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestSuite() { |
| 961 CallJavascriptFunction(L"g_browser.receivedStartConnectionTestSuite", NULL); | 1084 CallJavascriptFunction(L"g_browser.receivedStartConnectionTestSuite", NULL); |
| 962 } | 1085 } |
| 963 | 1086 |
| 964 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestExperiment( | 1087 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestExperiment( |
| 965 const ConnectionTester::Experiment& experiment) { | 1088 const ConnectionTester::Experiment& experiment) { |
| 966 CallJavascriptFunction( | 1089 CallJavascriptFunction( |
| 967 L"g_browser.receivedStartConnectionTestExperiment", | 1090 L"g_browser.receivedStartConnectionTestExperiment", |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 1159 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
| 1037 | 1160 |
| 1038 // Set up the chrome://net-internals/ source. | 1161 // Set up the chrome://net-internals/ source. |
| 1039 BrowserThread::PostTask( | 1162 BrowserThread::PostTask( |
| 1040 BrowserThread::IO, FROM_HERE, | 1163 BrowserThread::IO, FROM_HERE, |
| 1041 NewRunnableMethod( | 1164 NewRunnableMethod( |
| 1042 ChromeURLDataManager::GetInstance(), | 1165 ChromeURLDataManager::GetInstance(), |
| 1043 &ChromeURLDataManager::AddDataSource, | 1166 &ChromeURLDataManager::AddDataSource, |
| 1044 make_scoped_refptr(html_source))); | 1167 make_scoped_refptr(html_source))); |
| 1045 } | 1168 } |
| OLD | NEW |