| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 class IOThreadImpl; | 146 class IOThreadImpl; |
| 147 | 147 |
| 148 // This is the "real" message handler, which lives on the IO thread. | 148 // This is the "real" message handler, which lives on the IO thread. |
| 149 scoped_refptr<IOThreadImpl> proxy_; | 149 scoped_refptr<IOThreadImpl> proxy_; |
| 150 | 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler); | 151 DISALLOW_COPY_AND_ASSIGN(NetInternalsMessageHandler); |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 // This class is the "real" message handler. With the exception of being | 154 // This class is the "real" message handler. It is allocated and destroyed on |
| 155 // allocated and destroyed on the UI thread, its methods are expected to be | 155 // the UI thread. With the exception of OnAddEntry, OnDOMUIDeleted, and |
| 156 // called from the IO thread. | 156 // CallJavascriptFunction, its methods are all expected to be called from the IO |
| 157 // thread. OnAddEntry and CallJavascriptFunction can be called from any thread, |
| 158 // and OnDOMUIDeleted can only be called from the UI thread. |
| 157 class NetInternalsMessageHandler::IOThreadImpl | 159 class NetInternalsMessageHandler::IOThreadImpl |
| 158 : public base::RefCountedThreadSafe< | 160 : public base::RefCountedThreadSafe< |
| 159 NetInternalsMessageHandler::IOThreadImpl, | 161 NetInternalsMessageHandler::IOThreadImpl, |
| 160 BrowserThread::DeleteOnUIThread>, | 162 BrowserThread::DeleteOnUIThread>, |
| 161 public ChromeNetLog::Observer, | 163 public ChromeNetLog::ThreadSafeObserver, |
| 162 public ConnectionTester::Delegate { | 164 public ConnectionTester::Delegate { |
| 163 public: | 165 public: |
| 164 // Type for methods that can be used as MessageHandler callbacks. | 166 // Type for methods that can be used as MessageHandler callbacks. |
| 165 typedef void (IOThreadImpl::*MessageHandler)(const ListValue*); | 167 typedef void (IOThreadImpl::*MessageHandler)(const ListValue*); |
| 166 | 168 |
| 167 // Creates a proxy for |handler| that will live on the IO thread. | 169 // Creates a proxy for |handler| that will live on the IO thread. |
| 168 // |handler| is a weak pointer, since it is possible for the DOMMessageHandler | 170 // |handler| is a weak pointer, since it is possible for the DOMMessageHandler |
| 169 // to be deleted on the UI thread while we were executing on the IO thread. | 171 // to be deleted on the UI thread while we were executing on the IO thread. |
| 170 // |io_thread| is the global IOThread (it is passed in as an argument since | 172 // |io_thread| is the global IOThread (it is passed in as an argument since |
| 171 // we need to grab it from the UI thread). | 173 // we need to grab it from the UI thread). |
| 172 IOThreadImpl( | 174 IOThreadImpl( |
| 173 const base::WeakPtr<NetInternalsMessageHandler>& handler, | 175 const base::WeakPtr<NetInternalsMessageHandler>& handler, |
| 174 IOThread* io_thread, | 176 IOThread* io_thread, |
| 175 URLRequestContextGetter* context_getter); | 177 URLRequestContextGetter* context_getter); |
| 176 | 178 |
| 177 ~IOThreadImpl(); | 179 ~IOThreadImpl(); |
| 178 | 180 |
| 179 // Creates a callback that will run |method| on the IO thread. | 181 // Creates a callback that will run |method| on the IO thread. |
| 180 // | 182 // |
| 181 // This can be used with DOMUI::RegisterMessageCallback() to bind to a method | 183 // This can be used with DOMUI::RegisterMessageCallback() to bind to a method |
| 182 // on the IO thread. | 184 // on the IO thread. |
| 183 DOMUI::MessageCallback* CreateCallback(MessageHandler method); | 185 DOMUI::MessageCallback* CreateCallback(MessageHandler method); |
| 184 | 186 |
| 185 // Called once the DOMUI has been deleted (i.e. renderer went away), on the | 187 // Called once the DOMUI has been deleted (i.e. renderer went away), on the |
| 186 // IO thread. | 188 // IO thread. |
| 187 void Detach(); | 189 void Detach(); |
| 188 | 190 |
| 191 // Sends all passive log entries in |passive_entries| to the Javascript |
| 192 // handler, called on the IO thread. |
| 193 void SendPassiveLogEntries(const ChromeNetLog::EntryList& passive_entries); |
| 194 |
| 195 // Called when the DOMUI is deleted. Prevents calling Javascript functions |
| 196 // afterwards. Called on UI thread. |
| 197 void OnDOMUIDeleted(); |
| 198 |
| 189 //-------------------------------- | 199 //-------------------------------- |
| 190 // Javascript message handlers: | 200 // Javascript message handlers: |
| 191 //-------------------------------- | 201 //-------------------------------- |
| 192 | 202 |
| 193 // This message is called after the webpage's onloaded handler has fired. | |
| 194 // it indicates that the renderer is ready to start receiving captured data. | |
| 195 void OnRendererReady(const ListValue* list); | 203 void OnRendererReady(const ListValue* list); |
| 196 | 204 |
| 197 void OnGetProxySettings(const ListValue* list); | 205 void OnGetProxySettings(const ListValue* list); |
| 198 void OnReloadProxySettings(const ListValue* list); | 206 void OnReloadProxySettings(const ListValue* list); |
| 199 void OnGetBadProxies(const ListValue* list); | 207 void OnGetBadProxies(const ListValue* list); |
| 200 void OnClearBadProxies(const ListValue* list); | 208 void OnClearBadProxies(const ListValue* list); |
| 201 void OnGetHostResolverInfo(const ListValue* list); | 209 void OnGetHostResolverInfo(const ListValue* list); |
| 202 void OnClearHostResolverCache(const ListValue* list); | 210 void OnClearHostResolverCache(const ListValue* list); |
| 203 void OnEnableIPv6(const ListValue* list); | 211 void OnEnableIPv6(const ListValue* list); |
| 204 void OnGetPassiveLogEntries(const ListValue* list); | |
| 205 void OnStartConnectionTests(const ListValue* list); | 212 void OnStartConnectionTests(const ListValue* list); |
| 206 void OnGetHttpCacheInfo(const ListValue* list); | 213 void OnGetHttpCacheInfo(const ListValue* list); |
| 207 void OnGetSocketPoolInfo(const ListValue* list); | 214 void OnGetSocketPoolInfo(const ListValue* list); |
| 208 void OnGetSpdySessionInfo(const ListValue* list); | 215 void OnGetSpdySessionInfo(const ListValue* list); |
| 209 #ifdef OS_WIN | 216 #ifdef OS_WIN |
| 210 void OnGetServiceProviders(const ListValue* list); | 217 void OnGetServiceProviders(const ListValue* list); |
| 211 #endif | 218 #endif |
| 212 | 219 |
| 213 void OnSetLogLevel(const ListValue* list); | 220 void OnSetLogLevel(const ListValue* list); |
| 214 | 221 |
| 215 // ChromeNetLog::Observer implementation: | 222 // ChromeNetLog::ThreadSafeObserver implementation: |
| 216 virtual void OnAddEntry(net::NetLog::EventType type, | 223 virtual void OnAddEntry(net::NetLog::EventType type, |
| 217 const base::TimeTicks& time, | 224 const base::TimeTicks& time, |
| 218 const net::NetLog::Source& source, | 225 const net::NetLog::Source& source, |
| 219 net::NetLog::EventPhase phase, | 226 net::NetLog::EventPhase phase, |
| 220 net::NetLog::EventParameters* params); | 227 net::NetLog::EventParameters* params); |
| 221 | 228 |
| 222 // ConnectionTester::Delegate implementation: | 229 // ConnectionTester::Delegate implementation: |
| 223 virtual void OnStartConnectionTestSuite(); | 230 virtual void OnStartConnectionTestSuite(); |
| 224 virtual void OnStartConnectionTestExperiment( | 231 virtual void OnStartConnectionTestExperiment( |
| 225 const ConnectionTester::Experiment& experiment); | 232 const ConnectionTester::Experiment& experiment); |
| 226 virtual void OnCompletedConnectionTestExperiment( | 233 virtual void OnCompletedConnectionTestExperiment( |
| 227 const ConnectionTester::Experiment& experiment, | 234 const ConnectionTester::Experiment& experiment, |
| 228 int result); | 235 int result); |
| 229 virtual void OnCompletedConnectionTestSuite(); | 236 virtual void OnCompletedConnectionTestSuite(); |
| 230 | 237 |
| 231 private: | 238 private: |
| 232 class CallbackHelper; | 239 class CallbackHelper; |
| 233 | 240 |
| 234 // Helper that runs |method| with |arg|, and deletes |arg| on completion. | 241 // Helper that runs |method| with |arg|, and deletes |arg| on completion. |
| 235 void DispatchToMessageHandler(ListValue* arg, MessageHandler method); | 242 void DispatchToMessageHandler(ListValue* arg, MessageHandler method); |
| 236 | 243 |
| 237 // Helper that executes |function_name| in the attached renderer. | 244 // Helper that executes |function_name| in the attached renderer. |
| 238 // The function takes ownership of |arg|. | 245 // The function takes ownership of |arg|. Note that this can be called from |
| 246 // any thread. |
| 239 void CallJavascriptFunction(const std::wstring& function_name, | 247 void CallJavascriptFunction(const std::wstring& function_name, |
| 240 Value* arg); | 248 Value* arg); |
| 241 | 249 |
| 242 // Pointer to the UI-thread message handler. Only access this from | 250 // Pointer to the UI-thread message handler. Only access this from |
| 243 // the UI thread. | 251 // the UI thread. |
| 244 base::WeakPtr<NetInternalsMessageHandler> handler_; | 252 base::WeakPtr<NetInternalsMessageHandler> handler_; |
| 245 | 253 |
| 246 // The global IOThread, which contains the global NetLog to observer. | 254 // The global IOThread, which contains the global NetLog to observer. |
| 247 IOThread* io_thread_; | 255 IOThread* io_thread_; |
| 248 | 256 |
| 249 scoped_refptr<URLRequestContextGetter> context_getter_; | 257 scoped_refptr<URLRequestContextGetter> context_getter_; |
| 250 | 258 |
| 251 // Helper that runs the suite of connection tests. | 259 // Helper that runs the suite of connection tests. |
| 252 scoped_ptr<ConnectionTester> connection_tester_; | 260 scoped_ptr<ConnectionTester> connection_tester_; |
| 253 | 261 |
| 262 // True if the DOM UI has been deleted. This is used to prevent calling |
| 263 // Javascript functions after the DOM UI is destroyed. On refresh, the |
| 264 // messages can end up being sent to the refreshed page, causing duplicate |
| 265 // or partial entries. |
| 266 // |
| 267 // This is only read and written to on the UI thread. |
| 268 bool was_domui_deleted_; |
| 269 |
| 254 // True if we have attached an observer to the NetLog already. | 270 // True if we have attached an observer to the NetLog already. |
| 255 bool is_observing_log_; | 271 bool is_observing_log_; |
| 256 friend class base::RefCountedThreadSafe<IOThreadImpl>; | 272 friend class base::RefCountedThreadSafe<IOThreadImpl>; |
| 257 }; | 273 }; |
| 258 | 274 |
| 259 // Helper class for a DOMUI::MessageCallback which when excuted calls | 275 // Helper class for a DOMUI::MessageCallback which when excuted calls |
| 260 // instance->*method(value) on the IO thread. | 276 // instance->*method(value) on the IO thread. |
| 261 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper | 277 class NetInternalsMessageHandler::IOThreadImpl::CallbackHelper |
| 262 : public DOMUI::MessageCallback { | 278 : public DOMUI::MessageCallback { |
| 263 public: | 279 public: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 //////////////////////////////////////////////////////////////////////////////// | 353 //////////////////////////////////////////////////////////////////////////////// |
| 338 // | 354 // |
| 339 // NetInternalsMessageHandler | 355 // NetInternalsMessageHandler |
| 340 // | 356 // |
| 341 //////////////////////////////////////////////////////////////////////////////// | 357 //////////////////////////////////////////////////////////////////////////////// |
| 342 | 358 |
| 343 NetInternalsMessageHandler::NetInternalsMessageHandler() {} | 359 NetInternalsMessageHandler::NetInternalsMessageHandler() {} |
| 344 | 360 |
| 345 NetInternalsMessageHandler::~NetInternalsMessageHandler() { | 361 NetInternalsMessageHandler::~NetInternalsMessageHandler() { |
| 346 if (proxy_) { | 362 if (proxy_) { |
| 363 proxy_.get()->OnDOMUIDeleted(); |
| 347 // Notify the handler on the IO thread that the renderer is gone. | 364 // Notify the handler on the IO thread that the renderer is gone. |
| 348 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 365 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 349 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); | 366 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); |
| 350 } | 367 } |
| 351 } | 368 } |
| 352 | 369 |
| 353 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { | 370 DOMMessageHandler* NetInternalsMessageHandler::Attach(DOMUI* dom_ui) { |
| 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 355 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), | 372 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), |
| 356 dom_ui->GetProfile()->GetRequestContext()); | 373 dom_ui->GetProfile()->GetRequestContext()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 379 dom_ui_->RegisterMessageCallback( | 396 dom_ui_->RegisterMessageCallback( |
| 380 "getHostResolverInfo", | 397 "getHostResolverInfo", |
| 381 proxy_->CreateCallback(&IOThreadImpl::OnGetHostResolverInfo)); | 398 proxy_->CreateCallback(&IOThreadImpl::OnGetHostResolverInfo)); |
| 382 dom_ui_->RegisterMessageCallback( | 399 dom_ui_->RegisterMessageCallback( |
| 383 "clearHostResolverCache", | 400 "clearHostResolverCache", |
| 384 proxy_->CreateCallback(&IOThreadImpl::OnClearHostResolverCache)); | 401 proxy_->CreateCallback(&IOThreadImpl::OnClearHostResolverCache)); |
| 385 dom_ui_->RegisterMessageCallback( | 402 dom_ui_->RegisterMessageCallback( |
| 386 "enableIPv6", | 403 "enableIPv6", |
| 387 proxy_->CreateCallback(&IOThreadImpl::OnEnableIPv6)); | 404 proxy_->CreateCallback(&IOThreadImpl::OnEnableIPv6)); |
| 388 dom_ui_->RegisterMessageCallback( | 405 dom_ui_->RegisterMessageCallback( |
| 389 "getPassiveLogEntries", | |
| 390 proxy_->CreateCallback(&IOThreadImpl::OnGetPassiveLogEntries)); | |
| 391 dom_ui_->RegisterMessageCallback( | |
| 392 "startConnectionTests", | 406 "startConnectionTests", |
| 393 proxy_->CreateCallback(&IOThreadImpl::OnStartConnectionTests)); | 407 proxy_->CreateCallback(&IOThreadImpl::OnStartConnectionTests)); |
| 394 dom_ui_->RegisterMessageCallback( | 408 dom_ui_->RegisterMessageCallback( |
| 395 "getHttpCacheInfo", | 409 "getHttpCacheInfo", |
| 396 proxy_->CreateCallback(&IOThreadImpl::OnGetHttpCacheInfo)); | 410 proxy_->CreateCallback(&IOThreadImpl::OnGetHttpCacheInfo)); |
| 397 dom_ui_->RegisterMessageCallback( | 411 dom_ui_->RegisterMessageCallback( |
| 398 "getSocketPoolInfo", | 412 "getSocketPoolInfo", |
| 399 proxy_->CreateCallback(&IOThreadImpl::OnGetSocketPoolInfo)); | 413 proxy_->CreateCallback(&IOThreadImpl::OnGetSocketPoolInfo)); |
| 400 dom_ui_->RegisterMessageCallback( | 414 dom_ui_->RegisterMessageCallback( |
| 401 "getSpdySessionInfo", | 415 "getSpdySessionInfo", |
| (...skipping 23 matching lines...) Expand all Loading... |
| 425 //////////////////////////////////////////////////////////////////////////////// | 439 //////////////////////////////////////////////////////////////////////////////// |
| 426 // | 440 // |
| 427 // NetInternalsMessageHandler::IOThreadImpl | 441 // NetInternalsMessageHandler::IOThreadImpl |
| 428 // | 442 // |
| 429 //////////////////////////////////////////////////////////////////////////////// | 443 //////////////////////////////////////////////////////////////////////////////// |
| 430 | 444 |
| 431 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( | 445 NetInternalsMessageHandler::IOThreadImpl::IOThreadImpl( |
| 432 const base::WeakPtr<NetInternalsMessageHandler>& handler, | 446 const base::WeakPtr<NetInternalsMessageHandler>& handler, |
| 433 IOThread* io_thread, | 447 IOThread* io_thread, |
| 434 URLRequestContextGetter* context_getter) | 448 URLRequestContextGetter* context_getter) |
| 435 : Observer(net::NetLog::LOG_ALL_BUT_BYTES), | 449 : ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES), |
| 436 handler_(handler), | 450 handler_(handler), |
| 437 io_thread_(io_thread), | 451 io_thread_(io_thread), |
| 438 context_getter_(context_getter), | 452 context_getter_(context_getter), |
| 453 was_domui_deleted_(false), |
| 439 is_observing_log_(false) { | 454 is_observing_log_(false) { |
| 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 441 } | 456 } |
| 442 | 457 |
| 443 NetInternalsMessageHandler::IOThreadImpl::~IOThreadImpl() { | 458 NetInternalsMessageHandler::IOThreadImpl::~IOThreadImpl() { |
| 444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 445 } | 460 } |
| 446 | 461 |
| 447 DOMUI::MessageCallback* | 462 DOMUI::MessageCallback* |
| 448 NetInternalsMessageHandler::IOThreadImpl::CreateCallback( | 463 NetInternalsMessageHandler::IOThreadImpl::CreateCallback( |
| 449 MessageHandler method) { | 464 MessageHandler method) { |
| 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 451 return new CallbackHelper(this, method); | 466 return new CallbackHelper(this, method); |
| 452 } | 467 } |
| 453 | 468 |
| 454 void NetInternalsMessageHandler::IOThreadImpl::Detach() { | 469 void NetInternalsMessageHandler::IOThreadImpl::Detach() { |
| 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 456 // Unregister with network stack to observe events. | 471 // Unregister with network stack to observe events. |
| 457 if (is_observing_log_) | 472 if (is_observing_log_) |
| 458 io_thread_->globals()->net_log->RemoveObserver(this); | 473 io_thread_->net_log()->RemoveObserver(this); |
| 459 | 474 |
| 460 // Cancel any in-progress connection tests. | 475 // Cancel any in-progress connection tests. |
| 461 connection_tester_.reset(); | 476 connection_tester_.reset(); |
| 462 } | 477 } |
| 463 | 478 |
| 479 void NetInternalsMessageHandler::IOThreadImpl::SendPassiveLogEntries( |
| 480 const ChromeNetLog::EntryList& passive_entries) { |
| 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 482 ListValue* dict_list = new ListValue(); |
| 483 for (size_t i = 0; i < passive_entries.size(); ++i) { |
| 484 const ChromeNetLog::Entry& e = passive_entries[i]; |
| 485 dict_list->Append(net::NetLog::EntryToDictionaryValue(e.type, |
| 486 e.time, |
| 487 e.source, |
| 488 e.phase, |
| 489 e.params, |
| 490 false)); |
| 491 } |
| 492 |
| 493 CallJavascriptFunction(L"g_browser.receivedPassiveLogEntries", dict_list); |
| 494 } |
| 495 |
| 496 void NetInternalsMessageHandler::IOThreadImpl::OnDOMUIDeleted() { |
| 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 498 was_domui_deleted_ = true; |
| 499 } |
| 500 |
| 464 void NetInternalsMessageHandler::IOThreadImpl::OnRendererReady( | 501 void NetInternalsMessageHandler::IOThreadImpl::OnRendererReady( |
| 465 const ListValue* list) { | 502 const ListValue* list) { |
| 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 467 DCHECK(!is_observing_log_) << "notifyReady called twice"; | 504 DCHECK(!is_observing_log_) << "notifyReady called twice"; |
| 468 | 505 |
| 469 // Register with network stack to observe events. | |
| 470 is_observing_log_ = true; | |
| 471 io_thread_->globals()->net_log->AddObserver(this); | |
| 472 | |
| 473 // Tell the javascript about the relationship between event type enums and | 506 // Tell the javascript about the relationship between event type enums and |
| 474 // their symbolic name. | 507 // their symbolic name. |
| 475 { | 508 { |
| 476 std::vector<net::NetLog::EventType> event_types = | 509 std::vector<net::NetLog::EventType> event_types = |
| 477 net::NetLog::GetAllEventTypes(); | 510 net::NetLog::GetAllEventTypes(); |
| 478 | 511 |
| 479 DictionaryValue* dict = new DictionaryValue(); | 512 DictionaryValue* dict = new DictionaryValue(); |
| 480 | 513 |
| 481 for (size_t i = 0; i < event_types.size(); ++i) { | 514 for (size_t i = 0; i < event_types.size(); ++i) { |
| 482 const char* name = net::NetLog::EventTypeToString(event_types[i]); | 515 const char* name = net::NetLog::EventTypeToString(event_types[i]); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 // be part of the time library. | 643 // be part of the time library. |
| 611 const int64 kUnixEpochMs = 11644473600000LL; | 644 const int64 kUnixEpochMs = 11644473600000LL; |
| 612 int64 tick_to_unix_time_ms = tick_to_time_ms - kUnixEpochMs; | 645 int64 tick_to_unix_time_ms = tick_to_time_ms - kUnixEpochMs; |
| 613 | 646 |
| 614 // Pass it as a string, since it may be too large to fit in an integer. | 647 // Pass it as a string, since it may be too large to fit in an integer. |
| 615 CallJavascriptFunction(L"g_browser.receivedTimeTickOffset", | 648 CallJavascriptFunction(L"g_browser.receivedTimeTickOffset", |
| 616 Value::CreateStringValue( | 649 Value::CreateStringValue( |
| 617 base::Int64ToString(tick_to_unix_time_ms))); | 650 base::Int64ToString(tick_to_unix_time_ms))); |
| 618 } | 651 } |
| 619 | 652 |
| 620 OnGetPassiveLogEntries(NULL); | 653 // Register with network stack to observe events. |
| 654 is_observing_log_ = true; |
| 655 ChromeNetLog::EntryList entries; |
| 656 io_thread_->net_log()->AddObserverAndGetAllPassivelyCapturedEvents(this, |
| 657 &entries); |
| 658 SendPassiveLogEntries(entries); |
| 621 } | 659 } |
| 622 | 660 |
| 623 void NetInternalsMessageHandler::IOThreadImpl::OnGetProxySettings( | 661 void NetInternalsMessageHandler::IOThreadImpl::OnGetProxySettings( |
| 624 const ListValue* list) { | 662 const ListValue* list) { |
| 625 URLRequestContext* context = context_getter_->GetURLRequestContext(); | 663 URLRequestContext* context = context_getter_->GetURLRequestContext(); |
| 626 net::ProxyService* proxy_service = context->proxy_service(); | 664 net::ProxyService* proxy_service = context->proxy_service(); |
| 627 | 665 |
| 628 DictionaryValue* dict = new DictionaryValue(); | 666 DictionaryValue* dict = new DictionaryValue(); |
| 629 if (proxy_service->fetched_config().is_valid()) | 667 if (proxy_service->fetched_config().is_valid()) |
| 630 dict->Set("original", proxy_service->fetched_config().ToValue()); | 668 dict->Set("original", proxy_service->fetched_config().ToValue()); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 | 805 |
| 768 if (host_resolver_impl) { | 806 if (host_resolver_impl) { |
| 769 host_resolver_impl->SetDefaultAddressFamily( | 807 host_resolver_impl->SetDefaultAddressFamily( |
| 770 net::ADDRESS_FAMILY_UNSPECIFIED); | 808 net::ADDRESS_FAMILY_UNSPECIFIED); |
| 771 } | 809 } |
| 772 | 810 |
| 773 // Cause the renderer to be notified of the new value. | 811 // Cause the renderer to be notified of the new value. |
| 774 OnGetHostResolverInfo(NULL); | 812 OnGetHostResolverInfo(NULL); |
| 775 } | 813 } |
| 776 | 814 |
| 777 void NetInternalsMessageHandler::IOThreadImpl::OnGetPassiveLogEntries( | |
| 778 const ListValue* list) { | |
| 779 ChromeNetLog* net_log = io_thread_->globals()->net_log.get(); | |
| 780 | |
| 781 PassiveLogCollector::EntryList passive_entries; | |
| 782 net_log->passive_collector()->GetAllCapturedEvents(&passive_entries); | |
| 783 | |
| 784 ListValue* dict_list = new ListValue(); | |
| 785 for (size_t i = 0; i < passive_entries.size(); ++i) { | |
| 786 const PassiveLogCollector::Entry& e = passive_entries[i]; | |
| 787 dict_list->Append(net::NetLog::EntryToDictionaryValue(e.type, | |
| 788 e.time, | |
| 789 e.source, | |
| 790 e.phase, | |
| 791 e.params, | |
| 792 false)); | |
| 793 } | |
| 794 | |
| 795 CallJavascriptFunction(L"g_browser.receivedPassiveLogEntries", dict_list); | |
| 796 } | |
| 797 | |
| 798 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests( | 815 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests( |
| 799 const ListValue* list) { | 816 const ListValue* list) { |
| 800 // |value| should be: [<URL to test>]. | 817 // |value| should be: [<URL to test>]. |
| 801 string16 url_str; | 818 string16 url_str; |
| 802 CHECK(list->GetString(0, &url_str)); | 819 CHECK(list->GetString(0, &url_str)); |
| 803 | 820 |
| 804 // Try to fix-up the user provided URL into something valid. | 821 // Try to fix-up the user provided URL into something valid. |
| 805 // For example, turn "www.google.com" into "http://www.google.com". | 822 // For example, turn "www.google.com" into "http://www.google.com". |
| 806 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); | 823 GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); |
| 807 | 824 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 int log_level; | 921 int log_level; |
| 905 std::string log_level_string; | 922 std::string log_level_string; |
| 906 if (!list->GetString(0, &log_level_string) || | 923 if (!list->GetString(0, &log_level_string) || |
| 907 !base::StringToInt(log_level_string, &log_level)) { | 924 !base::StringToInt(log_level_string, &log_level)) { |
| 908 NOTREACHED(); | 925 NOTREACHED(); |
| 909 return; | 926 return; |
| 910 } | 927 } |
| 911 | 928 |
| 912 DCHECK_GE(log_level, net::NetLog::LOG_ALL); | 929 DCHECK_GE(log_level, net::NetLog::LOG_ALL); |
| 913 DCHECK_LE(log_level, net::NetLog::LOG_BASIC); | 930 DCHECK_LE(log_level, net::NetLog::LOG_BASIC); |
| 914 set_log_level(static_cast<net::NetLog::LogLevel>(log_level)); | 931 SetLogLevel(static_cast<net::NetLog::LogLevel>(log_level)); |
| 915 } | 932 } |
| 916 | 933 |
| 934 // Note that unlike other methods of IOThreadImpl, this function |
| 935 // can be called from ANY THREAD. |
| 917 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 936 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
| 918 net::NetLog::EventType type, | 937 net::NetLog::EventType type, |
| 919 const base::TimeTicks& time, | 938 const base::TimeTicks& time, |
| 920 const net::NetLog::Source& source, | 939 const net::NetLog::Source& source, |
| 921 net::NetLog::EventPhase phase, | 940 net::NetLog::EventPhase phase, |
| 922 net::NetLog::EventParameters* params) { | 941 net::NetLog::EventParameters* params) { |
| 923 DCHECK(is_observing_log_); | |
| 924 | |
| 925 CallJavascriptFunction( | 942 CallJavascriptFunction( |
| 926 L"g_browser.receivedLogEntry", | 943 L"g_browser.receivedLogEntry", |
| 927 net::NetLog::EntryToDictionaryValue(type, time, source, phase, params, | 944 net::NetLog::EntryToDictionaryValue(type, time, source, phase, params, |
| 928 false)); | 945 false)); |
| 929 } | 946 } |
| 930 | 947 |
| 931 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestSuite() { | 948 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTestSuite() { |
| 932 CallJavascriptFunction(L"g_browser.receivedStartConnectionTestSuite", NULL); | 949 CallJavascriptFunction(L"g_browser.receivedStartConnectionTestSuite", NULL); |
| 933 } | 950 } |
| 934 | 951 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 960 NULL); | 977 NULL); |
| 961 } | 978 } |
| 962 | 979 |
| 963 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( | 980 void NetInternalsMessageHandler::IOThreadImpl::DispatchToMessageHandler( |
| 964 ListValue* arg, MessageHandler method) { | 981 ListValue* arg, MessageHandler method) { |
| 965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 966 (this->*method)(arg); | 983 (this->*method)(arg); |
| 967 delete arg; | 984 delete arg; |
| 968 } | 985 } |
| 969 | 986 |
| 987 // Note that this can be called from ANY THREAD. |
| 970 void NetInternalsMessageHandler::IOThreadImpl::CallJavascriptFunction( | 988 void NetInternalsMessageHandler::IOThreadImpl::CallJavascriptFunction( |
| 971 const std::wstring& function_name, | 989 const std::wstring& function_name, |
| 972 Value* arg) { | 990 Value* arg) { |
| 973 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 991 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 974 if (handler_) { | 992 if (handler_ && !was_domui_deleted_) { |
| 975 // We check |handler_| in case it was deleted on the UI thread earlier | 993 // We check |handler_| in case it was deleted on the UI thread earlier |
| 976 // while we were running on the IO thread. | 994 // while we were running on the IO thread. |
| 977 handler_->CallJavascriptFunction(function_name, arg); | 995 handler_->CallJavascriptFunction(function_name, arg); |
| 978 } | 996 } |
| 979 delete arg; | 997 delete arg; |
| 980 return; | 998 return; |
| 981 } | 999 } |
| 982 | 1000 |
| 983 // Otherwise if we were called from the IO thread, bridge the request over to | |
| 984 // the UI thread. | |
| 985 | |
| 986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 987 if (!BrowserThread::PostTask( | 1001 if (!BrowserThread::PostTask( |
| 988 BrowserThread::UI, FROM_HERE, | 1002 BrowserThread::UI, FROM_HERE, |
| 989 NewRunnableMethod( | 1003 NewRunnableMethod( |
| 990 this, | 1004 this, |
| 991 &IOThreadImpl::CallJavascriptFunction, | 1005 &IOThreadImpl::CallJavascriptFunction, |
| 992 function_name, arg))) { | 1006 function_name, arg))) { |
| 993 // Failed posting the task, avoid leaking. | 1007 // Failed posting the task, avoid leaking. |
| 994 delete arg; | 1008 delete arg; |
| 995 } | 1009 } |
| 996 } | 1010 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1010 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 1024 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
| 1011 | 1025 |
| 1012 // Set up the chrome://net-internals/ source. | 1026 // Set up the chrome://net-internals/ source. |
| 1013 BrowserThread::PostTask( | 1027 BrowserThread::PostTask( |
| 1014 BrowserThread::IO, FROM_HERE, | 1028 BrowserThread::IO, FROM_HERE, |
| 1015 NewRunnableMethod( | 1029 NewRunnableMethod( |
| 1016 Singleton<ChromeURLDataManager>::get(), | 1030 Singleton<ChromeURLDataManager>::get(), |
| 1017 &ChromeURLDataManager::AddDataSource, | 1031 &ChromeURLDataManager::AddDataSource, |
| 1018 make_scoped_refptr(html_source))); | 1032 make_scoped_refptr(html_source))); |
| 1019 } | 1033 } |
| OLD | NEW |