Move gpu-crashed event to app
authorCheng Zhao <zcbenz@gmail.com>
Thu, 25 Jun 2015 12:28:07 +0000 (20:28 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 26 Jun 2015 02:33:52 +0000 (10:33 +0800)
atom/browser/api/atom_api_app.cc
atom/browser/api/atom_api_app.h
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h

index 036c61b..018ca1f 100644 (file)
@@ -24,6 +24,7 @@
 #include "base/path_service.h"
 #include "brightray/browser/brightray_paths.h"
 #include "content/public/browser/client_certificate_delegate.h"
+#include "content/public/browser/gpu_data_manager.h"
 #include "native_mate/callback.h"
 #include "native_mate/dictionary.h"
 #include "native_mate/object_template_builder.h"
@@ -135,10 +136,12 @@ void OnClientCertificateSelected(
 
 App::App() {
   Browser::Get()->AddObserver(this);
+  content::GpuDataManager::GetInstance()->AddObserver(this);
 }
 
 App::~App() {
   Browser::Get()->RemoveObserver(this);
+  content::GpuDataManager::GetInstance()->RemoveObserver(this);
 }
 
 void App::OnBeforeQuit(bool* prevent_default) {
@@ -206,6 +209,10 @@ void App::OnSelectCertificate(
         cert_request_info->client_certs[0].get());
 }
 
+void App::OnGpuProcessCrashed(base::TerminationStatus exit_code) {
+  Emit("gpu-crashed");
+}
+
 base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
   bool succeed = false;
   base::FilePath path;
index 9748991..040f7e3 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "atom/browser/api/event_emitter.h"
 #include "atom/browser/browser_observer.h"
+#include "content/public/browser/gpu_data_manager_observer.h"
 #include "native_mate/handle.h"
 
 namespace base {
@@ -24,7 +25,8 @@ namespace atom {
 namespace api {
 
 class App : public mate::EventEmitter,
-            public BrowserObserver {
+            public BrowserObserver,
+            public content::GpuDataManagerObserver {
  public:
   static mate::Handle<App> Create(v8::Isolate* isolate);
 
@@ -47,6 +49,9 @@ class App : public mate::EventEmitter,
       net::SSLCertRequestInfo* cert_request_info,
       scoped_ptr<content::ClientCertificateDelegate> delegate) override;
 
+  // content::GpuDataManagerObserver:
+  void OnGpuProcessCrashed(base::TerminationStatus exit_code) override;
+
   // mate::Wrappable:
   mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
       v8::Isolate* isolate) override;
index 849b60e..d07b037 100644 (file)
@@ -328,11 +328,6 @@ void WebContents::PluginCrashed(const base::FilePath& plugin_path,
   Emit("plugin-crashed", info.name, info.version);
 }
 
-void WebContents::OnGpuProcessCrashed(base::TerminationStatus exit_code) {
-  if (exit_code == base::TERMINATION_STATUS_PROCESS_CRASHED)
-    Emit("gpu-crashed");
-}
-
 void WebContents::DocumentLoadedInFrame(
     content::RenderFrameHost* render_frame_host) {
   if (!render_frame_host->GetParent())
index 9ef88e5..e6056d0 100644 (file)
@@ -12,7 +12,6 @@
 #include "atom/browser/common_web_contents_delegate.h"
 #include "content/public/common/favicon_url.h"
 #include "content/public/browser/web_contents_observer.h"
-#include "content/public/browser/gpu_data_manager_observer.h"
 #include "native_mate/handle.h"
 #include "ui/gfx/image/image.h"
 
@@ -34,8 +33,7 @@ namespace api {
 
 class WebContents : public mate::TrackableObject<WebContents>,
                     public CommonWebContentsDelegate,
-                    public content::WebContentsObserver,
-                    public content::GpuDataManagerObserver {
+                    public content::WebContentsObserver {
  public:
   // For node.js callback function type: function(error, buffer)
   typedef base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>
@@ -185,9 +183,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
   void PluginCrashed(const base::FilePath& plugin_path,
                      base::ProcessId plugin_pid) override;
 
-  // content::GpuDataManagerObserver:
-  void OnGpuProcessCrashed(base::TerminationStatus exit_code) override;
-
  private:
   enum Type {
     BROWSER_WINDOW,  // Used by BrowserWindow.