Disable "Ok Google" hotwording in open source builds by default.

The compile-time flag "enable_hotwording" is now tied to
branding=Chrome (false by default unless making a Google Chrome build).

Note: Chromium will no longer download/install the Hotword Shared
Module, and will automatically remove the Hotword Shared Module on
startup if it was previously installed. To keep this functionality, add
"enable_hotwording=1" to GYP_DEFINES.

BUG=500922

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

Cr-Commit-Position: refs/heads/master@{#335874}
diff --git a/build/common.gypi b/build/common.gypi
index ef38f66..52a633f 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -416,8 +416,10 @@
       # Web speech is enabled by default. Set to 0 to disable.
       'enable_web_speech%': 1,
 
-      # 'Ok Google' hotwording is enabled by default. Set to 0 to disable.
-      'enable_hotwording%': 1,
+      # 'Ok Google' hotwording is disabled by default in open source builds. Set
+      # to 1 to enable. (This will download a closed-source NaCl module at
+      # startup.) Chrome-branded builds have this enabled by default.
+      'enable_hotwording%': 0,
 
       # Notifications are compiled in by default. Set to 0 to disable.
       'notifications%' : 1,
@@ -836,6 +838,10 @@
           'enable_prod_wallet_service%': 1,
         }],
 
+        ['branding=="Chrome"', {
+          'enable_hotwording%': 1,
+        }],
+
         ['OS=="android"', {
           'enable_webrtc%': 1,
         }],
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 0a57c7a..d8a6b77 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -20,8 +20,10 @@
 }
 
 declare_args() {
-  # 'Ok Google' hotwording is enabled.
-  enable_hotwording = true
+  # 'Ok Google' hotwording is disabled by default in open source builds. Set to
+  # true to enable. (This will download a closed-source NaCl module at startup.)
+  # Chrome-branded builds have this enabled by default.
+  enable_hotwording = is_chrome_branded
 }
 
 about_credits_file = "$target_gen_dir/about_credits.html"
diff --git a/chrome/browser/search/hotword_service_unittest.cc b/chrome/browser/search/hotword_service_unittest.cc
index 9d53410..dd27eeb 100644
--- a/chrome/browser/search/hotword_service_unittest.cc
+++ b/chrome/browser/search/hotword_service_unittest.cc
@@ -159,10 +159,15 @@
                             extension_misc::kHotwordSharedModuleId));
 
 TEST_P(HotwordServiceTest, IsHotwordAllowedLocale) {
-#if defined(ENABLE_HOTWORDING)
   TestingProfile::Builder profile_builder;
   scoped_ptr<TestingProfile> profile = profile_builder.Build();
 
+#if defined(ENABLE_HOTWORDING)
+  bool hotwording_enabled = true;
+#else
+  bool hotwording_enabled = false;
+#endif
+
   // Check that the service exists so that a NULL service be ruled out in
   // following tests.
   HotwordService* hotword_service =
@@ -175,22 +180,26 @@
 
   // Now with valid locales it should be fine.
   SetApplicationLocale(static_cast<Profile*>(profile.get()), "en");
-  EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
+  EXPECT_EQ(hotwording_enabled,
+            HotwordServiceFactory::IsHotwordAllowed(profile.get()));
   SetApplicationLocale(static_cast<Profile*>(profile.get()), "en-US");
-  EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
+  EXPECT_EQ(hotwording_enabled,
+            HotwordServiceFactory::IsHotwordAllowed(profile.get()));
   SetApplicationLocale(static_cast<Profile*>(profile.get()), "en_us");
-  EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
+  EXPECT_EQ(hotwording_enabled,
+            HotwordServiceFactory::IsHotwordAllowed(profile.get()));
   SetApplicationLocale(static_cast<Profile*>(profile.get()), "de_DE");
-  EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
+  EXPECT_EQ(hotwording_enabled,
+            HotwordServiceFactory::IsHotwordAllowed(profile.get()));
   SetApplicationLocale(static_cast<Profile*>(profile.get()), "fr_fr");
-  EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile.get()));
+  EXPECT_EQ(hotwording_enabled,
+            HotwordServiceFactory::IsHotwordAllowed(profile.get()));
 
   // Test that incognito even with a valid locale and valid field trial
   // still returns false.
   Profile* otr_profile = profile->GetOffTheRecordProfile();
   SetApplicationLocale(otr_profile, "en");
   EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(otr_profile));
-#endif  // defined(ENABLE_HOTWORDING)
 }
 
 TEST_P(HotwordServiceTest, ShouldReinstallExtension) {
@@ -247,7 +256,6 @@
 }
 
 TEST_P(HotwordServiceTest, UninstallReinstallTriggeredCorrectly) {
-#if defined(ENABLE_HOTWORDING)
   InitializeEmptyExtensionService();
   service_->Init();
 
@@ -289,7 +297,11 @@
 
   // Switch the locale to a valid but different one.
   SetApplicationLocale(profile(), "fr_fr");
+#if defined(ENABLE_HOTWORDING)
   EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile()));
+#else
+  EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile()));
+#endif
 
   // Different but valid locale so expect uninstall.
   EXPECT_TRUE(hotword_service->MaybeReinstallHotwordExtension());
@@ -315,10 +327,13 @@
   // If the locale is set back to the last valid one, then an uninstall-install
   // shouldn't be needed.
   SetApplicationLocale(profile(), "fr_fr");
+#if defined(ENABLE_HOTWORDING)
   EXPECT_TRUE(HotwordServiceFactory::IsHotwordAllowed(profile()));
+#else
+  EXPECT_FALSE(HotwordServiceFactory::IsHotwordAllowed(profile()));
+#endif
   EXPECT_FALSE(hotword_service->MaybeReinstallHotwordExtension());
   EXPECT_EQ(1, hotword_service->uninstall_count());  // no change
-#endif  // defined(ENABLE_HOTWORDING)
 }
 
 TEST_P(HotwordServiceTest, DisableAlwaysOnOnLanguageChange) {