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 "content/browser/gpu/gpu_internals_ui.h" | 5 #include "content/browser/gpu/gpu_internals_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 public GpuDataManagerObserver { | 472 public GpuDataManagerObserver { |
473 public: | 473 public: |
474 GpuMessageHandler(); | 474 GpuMessageHandler(); |
475 virtual ~GpuMessageHandler(); | 475 virtual ~GpuMessageHandler(); |
476 | 476 |
477 // WebUIMessageHandler implementation. | 477 // WebUIMessageHandler implementation. |
478 virtual void RegisterMessages() OVERRIDE; | 478 virtual void RegisterMessages() OVERRIDE; |
479 | 479 |
480 // GpuDataManagerObserver implementation. | 480 // GpuDataManagerObserver implementation. |
481 virtual void OnGpuInfoUpdate() OVERRIDE; | 481 virtual void OnGpuInfoUpdate() OVERRIDE; |
482 | 482 virtual void OnGpuSwitching() OVERRIDE; |
483 // Gpu switch handler. | |
484 void OnGpuSwitch(); | |
485 | 483 |
486 // Messages | 484 // Messages |
487 void OnBrowserBridgeInitialized(const base::ListValue* list); | 485 void OnBrowserBridgeInitialized(const base::ListValue* list); |
488 void OnCallAsync(const base::ListValue* list); | 486 void OnCallAsync(const base::ListValue* list); |
489 | 487 |
490 // Submessages dispatched from OnCallAsync | 488 // Submessages dispatched from OnCallAsync |
491 base::Value* OnRequestClientInfo(const base::ListValue* list); | 489 base::Value* OnRequestClientInfo(const base::ListValue* list); |
492 base::Value* OnRequestLogMessages(const base::ListValue* list); | 490 base::Value* OnRequestLogMessages(const base::ListValue* list); |
493 | 491 |
494 private: | 492 private: |
495 // True if observing the GpuDataManager (re-attaching as observer would | 493 // True if observing the GpuDataManager (re-attaching as observer would |
496 // DCHECK). | 494 // DCHECK). |
497 bool observing_; | 495 bool observing_; |
498 | 496 |
499 GpuDataManagerImpl::GpuSwitchCallback gpu_switch_callback_; | |
500 | |
501 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); | 497 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); |
502 }; | 498 }; |
503 | 499 |
504 //////////////////////////////////////////////////////////////////////////////// | 500 //////////////////////////////////////////////////////////////////////////////// |
505 // | 501 // |
506 // GpuMessageHandler | 502 // GpuMessageHandler |
507 // | 503 // |
508 //////////////////////////////////////////////////////////////////////////////// | 504 //////////////////////////////////////////////////////////////////////////////// |
509 | 505 |
510 GpuMessageHandler::GpuMessageHandler() | 506 GpuMessageHandler::GpuMessageHandler() |
511 : observing_(false), | 507 : observing_(false) { |
512 gpu_switch_callback_(base::Bind(&GpuMessageHandler::OnGpuSwitch, | |
513 base::Unretained(this))) { | |
514 } | 508 } |
515 | 509 |
516 GpuMessageHandler::~GpuMessageHandler() { | 510 GpuMessageHandler::~GpuMessageHandler() { |
517 GpuDataManagerImpl::GetInstance()->RemoveObserver(this); | 511 GpuDataManagerImpl::GetInstance()->RemoveObserver(this); |
518 GpuDataManagerImpl::GetInstance()->RemoveGpuSwitchCallback( | |
519 gpu_switch_callback_); | |
520 } | 512 } |
521 | 513 |
522 /* BrowserBridge.callAsync prepends a requestID to these messages. */ | 514 /* BrowserBridge.callAsync prepends a requestID to these messages. */ |
523 void GpuMessageHandler::RegisterMessages() { | 515 void GpuMessageHandler::RegisterMessages() { |
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
525 | 517 |
526 web_ui()->RegisterMessageCallback("browserBridgeInitialized", | 518 web_ui()->RegisterMessageCallback("browserBridgeInitialized", |
527 base::Bind(&GpuMessageHandler::OnBrowserBridgeInitialized, | 519 base::Bind(&GpuMessageHandler::OnBrowserBridgeInitialized, |
528 base::Unretained(this))); | 520 base::Unretained(this))); |
529 web_ui()->RegisterMessageCallback("callAsync", | 521 web_ui()->RegisterMessageCallback("callAsync", |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply", | 568 web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply", |
577 *requestId); | 569 *requestId); |
578 } | 570 } |
579 } | 571 } |
580 | 572 |
581 void GpuMessageHandler::OnBrowserBridgeInitialized( | 573 void GpuMessageHandler::OnBrowserBridgeInitialized( |
582 const base::ListValue* args) { | 574 const base::ListValue* args) { |
583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
584 | 576 |
585 // Watch for changes in GPUInfo | 577 // Watch for changes in GPUInfo |
586 if (!observing_) { | 578 if (!observing_) |
587 GpuDataManagerImpl::GetInstance()->AddObserver(this); | 579 GpuDataManagerImpl::GetInstance()->AddObserver(this); |
588 GpuDataManagerImpl::GetInstance()->AddGpuSwitchCallback( | |
589 gpu_switch_callback_); | |
590 } | |
591 observing_ = true; | 580 observing_ = true; |
592 | 581 |
593 // Tell GpuDataManager it should have full GpuInfo. If the | 582 // Tell GpuDataManager it should have full GpuInfo. If the |
594 // Gpu process has not run yet, this will trigger its launch. | 583 // Gpu process has not run yet, this will trigger its launch. |
595 GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded(); | 584 GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded(); |
596 | 585 |
597 // Run callback immediately in case the info is ready and no update in the | 586 // Run callback immediately in case the info is ready and no update in the |
598 // future. | 587 // future. |
599 OnGpuInfoUpdate(); | 588 OnGpuInfoUpdate(); |
600 } | 589 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 // Add in blacklisting features | 621 // Add in blacklisting features |
633 base::Value* feature_status = GetFeatureStatus(); | 622 base::Value* feature_status = GetFeatureStatus(); |
634 if (feature_status) | 623 if (feature_status) |
635 gpu_info_val->Set("featureStatus", feature_status); | 624 gpu_info_val->Set("featureStatus", feature_status); |
636 | 625 |
637 // Send GPU Info to javascript. | 626 // Send GPU Info to javascript. |
638 web_ui()->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", | 627 web_ui()->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", |
639 *(gpu_info_val.get())); | 628 *(gpu_info_val.get())); |
640 } | 629 } |
641 | 630 |
642 void GpuMessageHandler::OnGpuSwitch() { | 631 void GpuMessageHandler::OnGpuSwitching() { |
643 GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded(); | 632 GpuDataManagerImpl::GetInstance()->RequestCompleteGpuInfoIfNeeded(); |
644 } | 633 } |
645 | 634 |
646 } // namespace | 635 } // namespace |
647 | 636 |
648 | 637 |
649 //////////////////////////////////////////////////////////////////////////////// | 638 //////////////////////////////////////////////////////////////////////////////// |
650 // | 639 // |
651 // GpuInternalsUI | 640 // GpuInternalsUI |
652 // | 641 // |
653 //////////////////////////////////////////////////////////////////////////////// | 642 //////////////////////////////////////////////////////////////////////////////// |
654 | 643 |
655 GpuInternalsUI::GpuInternalsUI(WebUI* web_ui) | 644 GpuInternalsUI::GpuInternalsUI(WebUI* web_ui) |
656 : WebUIController(web_ui) { | 645 : WebUIController(web_ui) { |
657 web_ui->AddMessageHandler(new GpuMessageHandler()); | 646 web_ui->AddMessageHandler(new GpuMessageHandler()); |
658 | 647 |
659 // Set up the chrome://gpu/ source. | 648 // Set up the chrome://gpu/ source. |
660 BrowserContext* browser_context = | 649 BrowserContext* browser_context = |
661 web_ui->GetWebContents()->GetBrowserContext(); | 650 web_ui->GetWebContents()->GetBrowserContext(); |
662 WebUIDataSource::Add(browser_context, CreateGpuHTMLSource()); | 651 WebUIDataSource::Add(browser_context, CreateGpuHTMLSource()); |
663 } | 652 } |
664 | 653 |
665 } // namespace content | 654 } // namespace content |
OLD | NEW |