Chromecast Android shell improvements:
* Handling RenderProcessGone in CastWindowAndroid
* Using CastBrowserProcess instead of passing the browser context
* A few style nits

R=byungchul@chromium.org,lcwu@chromium.org
BUG=None

Review URL: https://codereview.chromium.org/566963003

Cr-Commit-Position: refs/heads/master@{#295210}
diff --git a/chromecast/android/cast_jni_registrar.cc b/chromecast/android/cast_jni_registrar.cc
index db79061..e8bae63 100644
--- a/chromecast/android/cast_jni_registrar.cc
+++ b/chromecast/android/cast_jni_registrar.cc
@@ -6,7 +6,6 @@
 
 #include "base/android/jni_android.h"
 #include "base/android/jni_registrar.h"
-#include "chromecast/android/chromecast_config_android.h"
 #include "chromecast/shell/browser/android/cast_window_android.h"
 #include "chromecast/shell/browser/android/cast_window_manager.h"
 
diff --git a/chromecast/service/cast_service_android.cc b/chromecast/service/cast_service_android.cc
index afaab64..07fdb5a 100644
--- a/chromecast/service/cast_service_android.cc
+++ b/chromecast/service/cast_service_android.cc
@@ -6,7 +6,6 @@
 
 #include "base/callback.h"
 #include "chromecast/android/chromecast_config_android.h"
-#include "chromecast/shell/browser/android/cast_window_manager.h"
 
 namespace chromecast {
 
@@ -17,7 +16,6 @@
 
 CastServiceAndroid::CastServiceAndroid(content::BrowserContext* browser_context)
     : CastService(browser_context) {
-  shell::SetBrowserContextAndroid(browser_context);
 }
 
 CastServiceAndroid::~CastServiceAndroid() {
diff --git a/chromecast/shell/app/cast_main_delegate.cc b/chromecast/shell/app/cast_main_delegate.cc
index f713f5b..719cc2b 100644
--- a/chromecast/shell/app/cast_main_delegate.cc
+++ b/chromecast/shell/app/cast_main_delegate.cc
@@ -93,7 +93,7 @@
         base::File(pak_fd), ui::SCALE_FACTOR_100P);
     return;
   }
-#endif
+#endif  // defined(OS_ANDROID)
 
   resource_delegate_.reset(new CastResourceDelegate());
   // TODO(gunsch): Use LOAD_COMMON_RESOURCES once ResourceBundle no longer
diff --git a/chromecast/shell/browser/android/cast_window_android.cc b/chromecast/shell/browser/android/cast_window_android.cc
index 65380b147..4bf98c2 100644
--- a/chromecast/shell/browser/android/cast_window_android.cc
+++ b/chromecast/shell/browser/android/cast_window_android.cc
@@ -126,5 +126,10 @@
   contents->GetRenderViewHost()->Blur();
 }
 
+void CastWindowAndroid::RenderProcessGone(base::TerminationStatus status) {
+  LOG(ERROR) << "Render process gone: status=" << status;
+  Close();
+}
+
 }  // namespace shell
 }  // namespace chromecast
diff --git a/chromecast/shell/browser/android/cast_window_android.h b/chromecast/shell/browser/android/cast_window_android.h
index 979aea9..512e5e8 100644
--- a/chromecast/shell/browser/android/cast_window_android.h
+++ b/chromecast/shell/browser/android/cast_window_android.h
@@ -50,7 +50,7 @@
   // Registers the JNI methods for CastWindowAndroid.
   static bool RegisterJni(JNIEnv* env);
 
-  // WebContentsDelegate implementation.
+  // content::WebContentsDelegate implementation:
   virtual void AddNewContents(content::WebContents* source,
                               content::WebContents* new_contents,
                               WindowOpenDisposition disposition,
@@ -67,6 +67,9 @@
   virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
   virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
 
+  // content::WebContentsObserver implementation:
+  virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
+
  private:
   explicit CastWindowAndroid(content::WebContents* web_contents);
 
diff --git a/chromecast/shell/browser/android/cast_window_manager.cc b/chromecast/shell/browser/android/cast_window_manager.cc
index daa18af..8f485d54 100644
--- a/chromecast/shell/browser/android/cast_window_manager.cc
+++ b/chromecast/shell/browser/android/cast_window_manager.cc
@@ -16,6 +16,7 @@
 #include "chromecast/shell/browser/android/cast_window_android.h"
 #include "chromecast/shell/browser/cast_browser_context.h"
 #include "chromecast/shell/browser/cast_browser_main_parts.h"
+#include "chromecast/shell/browser/cast_browser_process.h"
 #include "chromecast/shell/browser/cast_content_browser_client.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/web_contents.h"
@@ -25,20 +26,14 @@
 
 namespace {
 
-base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject>>
+base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >
     g_window_manager = LAZY_INSTANCE_INITIALIZER;
 
-content::BrowserContext* g_browser_context = NULL;
-
 }  // namespace
 
 namespace chromecast {
 namespace shell {
 
-void SetBrowserContextAndroid(content::BrowserContext* browser_context) {
-  g_browser_context = browser_context;
-}
-
 base::android::ScopedJavaLocalRef<jobject>
 CreateCastWindowView(CastWindowAndroid* shell) {
   JNIEnv* env = base::android::AttachCurrentThread();
@@ -63,10 +58,11 @@
 }
 
 jlong LaunchCastWindow(JNIEnv* env, jclass clazz, jstring jurl) {
-  DCHECK(g_browser_context);
   GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
   return reinterpret_cast<jlong>(
-      CastWindowAndroid::CreateNewWindow(g_browser_context, url));
+      CastWindowAndroid::CreateNewWindow(
+          CastBrowserProcess::GetInstance()->browser_context(),
+          url));
 }
 
 void StopCastWindow(JNIEnv* env, jclass clazz, jlong nativeCastWindow) {
diff --git a/chromecast/shell/browser/android/cast_window_manager.h b/chromecast/shell/browser/android/cast_window_manager.h
index 9a811a91..a7c2e0a 100644
--- a/chromecast/shell/browser/android/cast_window_manager.h
+++ b/chromecast/shell/browser/android/cast_window_manager.h
@@ -19,10 +19,6 @@
 namespace chromecast {
 namespace shell {
 
-// Sets the browser context to use for creating windows. Must be invoked before
-// a LaunchCastWindow call.
-void SetBrowserContextAndroid(content::BrowserContext* browser_context);
-
 // Given a CastWindowAndroid instance, creates and returns a Java wrapper.
 base::android::ScopedJavaLocalRef<jobject>
 CreateCastWindowView(CastWindowAndroid* shell);