Exempt default apps from external-extension alerts.

BUG=106188
TEST=added


Review URL: http://codereview.chromium.org/8800016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113144 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/default_apps.cc b/chrome/browser/extensions/default_apps.cc
index fbd85fed..33ed772 100644
--- a/chrome/browser/extensions/default_apps.cc
+++ b/chrome/browser/extensions/default_apps.cc
@@ -114,6 +114,7 @@
                                     download_location, creation_flags),
       profile_(profile) {
   DCHECK(profile);
+  set_auto_acknowledge(true);
 }
 
 void Provider::VisitRegisteredExtension() {
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index 4f06365..8bf574a 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -1739,7 +1739,7 @@
       global_error.get_external_extension_ids();
   for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
        iter != extension_ids->end(); ++iter) {
-    extension_prefs_->AcknowledgeExternalExtension(*iter);
+    AcknowledgeExternalExtension(*iter);
   }
   extension_ids = global_error.get_blacklisted_extension_ids();
   for (ExtensionIdSet::const_iterator iter = extension_ids->begin();
@@ -1753,6 +1753,10 @@
   }
 }
 
+void ExtensionService::AcknowledgeExternalExtension(const std::string& id) {
+  extension_prefs_->AcknowledgeExternalExtension(id);
+}
+
 void ExtensionService::HandleExtensionAlertDetails(
     const ExtensionGlobalError& global_error, Browser* browser) {
   if (browser) {
@@ -2245,7 +2249,8 @@
          const Version* version,
          const FilePath& path,
          Extension::Location location,
-         int creation_flags) {
+         int creation_flags,
+         bool mark_acknowledged) {
   CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   CHECK(Extension::IdIsValid(id));
   if (extension_prefs_->IsExternalExtensionUninstalled(id))
@@ -2282,6 +2287,12 @@
   installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE);
   installer->set_creation_flags(creation_flags);
   installer->InstallCrx(path);
+
+  // Depending on the source, a new external extension might not need a user
+  // notification on installation. For such extensions, mark them acknowledged
+  // now to suppress the notification.
+  if (mark_acknowledged)
+    AcknowledgeExternalExtension(id);
 }
 
 void ExtensionService::ReportExtensionLoadError(
diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h
index 006d655..370ad22 100644
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -505,7 +505,8 @@
                                             const Version* version,
                                             const FilePath& path,
                                             Extension::Location location,
-                                            int creation_flags)
+                                            int creation_flags,
+                                            bool mark_acknowledged)
       OVERRIDE;
 
   virtual void OnExternalExtensionUpdateUrlFound(const std::string& id,
@@ -527,6 +528,10 @@
   void HandleExtensionAlertAccept(const ExtensionGlobalError& global_error,
                                   Browser* browser);
 
+  // Given a (presumably just-installed) extension id, mark that extension as
+  // acknowledged.
+  void AcknowledgeExternalExtension(const std::string& id);
+
   // Opens the Extensions page because the user wants to get more details
   // about the alerts.
   void HandleExtensionAlertDetails(const ExtensionGlobalError& global_error,
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 6f3fc61..78ef149 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -155,7 +155,7 @@
 
       visitor_->OnExternalExtensionFileFound(
           i->first, version.get(), i->second.second, location_,
-          Extension::NO_FLAGS);
+          Extension::NO_FLAGS, false);
     }
     visitor_->OnExternalProviderReady(this);
   }
@@ -254,7 +254,8 @@
                                             const Version* version,
                                             const FilePath& path,
                                             Extension::Location unused,
-                                            int creation_flags) {
+                                            int creation_flags,
+                                            bool mark_acknowledged) {
     EXPECT_EQ(Extension::NO_FLAGS, creation_flags);
 
     ++ids_found_;
@@ -1255,7 +1256,7 @@
   // Install an external extension.
   service_->OnExternalExtensionFileFound(good_crx, version.get(),
                                          path, Extension::EXTERNAL_PREF,
-                                         Extension::FROM_BOOKMARK);
+                                         Extension::FROM_BOOKMARK, false);
   loop_.RunAllPending();
 
   const Extension* extension = service_->GetExtensionById(good_crx, false);
@@ -1276,7 +1277,7 @@
   // Install an external extension.
   service_->OnExternalExtensionFileFound(good_crx, version.get(),
                                          path, Extension::EXTERNAL_PREF,
-                                         Extension::NO_FLAGS);
+                                         Extension::NO_FLAGS, false);
   loop_.RunAllPending();
   ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
 
@@ -1288,7 +1289,7 @@
   // Try to re-install it externally. This should fail because of the killbit.
   service_->OnExternalExtensionFileFound(good_crx, version.get(),
                                          path, Extension::EXTERNAL_PREF,
-                                         Extension::NO_FLAGS);
+                                         Extension::NO_FLAGS, false);
   loop_.RunAllPending();
   ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
   ValidateIntegerPref(good_crx, "location",
@@ -1299,7 +1300,7 @@
   path = data_dir_.AppendASCII("good2.crx");
   service_->OnExternalExtensionFileFound(good_crx, version.get(),
                                          path, Extension::EXTERNAL_PREF,
-                                         Extension::NO_FLAGS);
+                                         Extension::NO_FLAGS, false);
   loop_.RunAllPending();
   ASSERT_TRUE(NULL == service_->GetExtensionById(good_crx, false));
   ValidateIntegerPref(good_crx, "location",
@@ -1359,7 +1360,7 @@
   // source that is not equal to the ID in the extension manifest.
   service_->OnExternalExtensionFileFound(
       wrong_id, version.get(), path, Extension::EXTERNAL_PREF,
-      Extension::NO_FLAGS);
+      Extension::NO_FLAGS, false);
 
   loop_.RunAllPending();
   ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
@@ -1367,7 +1368,7 @@
   // Try again with the right ID. Expect success.
   service_->OnExternalExtensionFileFound(
       correct_id, version.get(), path, Extension::EXTERNAL_PREF,
-      Extension::NO_FLAGS);
+      Extension::NO_FLAGS, false);
   loop_.RunAllPending();
   ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
 }
@@ -1384,7 +1385,7 @@
   wrong_version.reset(Version::GetVersionFromString("1.2.3.4"));
   service_->OnExternalExtensionFileFound(
       good_crx, wrong_version.get(), path, Extension::EXTERNAL_PREF,
-      Extension::NO_FLAGS);
+      Extension::NO_FLAGS, false);
 
   loop_.RunAllPending();
   ASSERT_FALSE(service_->GetExtensionById(good_crx, false));
@@ -1394,7 +1395,7 @@
   correct_version.reset(Version::GetVersionFromString("1.0.0.0"));
   service_->OnExternalExtensionFileFound(
       good_crx, correct_version.get(), path, Extension::EXTERNAL_PREF,
-      Extension::NO_FLAGS);
+      Extension::NO_FLAGS, false);
   loop_.RunAllPending();
   ASSERT_TRUE(service_->GetExtensionById(good_crx, false));
 }
@@ -4172,7 +4173,7 @@
 
     service_->OnExternalExtensionFileFound(
         crx_id_, version.get(), crx_path_, Extension::EXTERNAL_PREF,
-        Extension::NO_FLAGS);
+        Extension::NO_FLAGS, false);
   }
 
   // Fake a request from sync to install an extension.
diff --git a/chrome/browser/extensions/external_extension_provider_impl.cc b/chrome/browser/extensions/external_extension_provider_impl.cc
index b8fbdb0..cc1dd9b 100644
--- a/chrome/browser/extensions/external_extension_provider_impl.cc
+++ b/chrome/browser/extensions/external_extension_provider_impl.cc
@@ -56,7 +56,8 @@
     prefs_(NULL),
     ready_(false),
     loader_(loader),
-    creation_flags_(creation_flags) {
+    creation_flags_(creation_flags),
+    auto_acknowledge_(false) {
   loader_->Init(this);
 }
 
@@ -73,7 +74,7 @@
 void ExternalExtensionProviderImpl::SetPrefs(DictionaryValue* prefs) {
   CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
 
-  // Check if the service is still alive. It is possible that it had went
+  // Check if the service is still alive. It is possible that it went
   // away while |loader_| was working on the FILE thread.
   if (!service_) return;
 
@@ -196,7 +197,8 @@
         continue;
       }
       service_->OnExternalExtensionFileFound(extension_id, version.get(), path,
-                                             crx_location_, creation_flags_);
+                                             crx_location_, creation_flags_,
+                                             auto_acknowledge_);
     } else { // if (has_external_update_url)
       CHECK(has_external_update_url);  // Checking of keys above ensures this.
       if (download_location_ == Extension::INVALID) {
diff --git a/chrome/browser/extensions/external_extension_provider_impl.h b/chrome/browser/extensions/external_extension_provider_impl.h
index 80044c9..242c6183 100644
--- a/chrome/browser/extensions/external_extension_provider_impl.h
+++ b/chrome/browser/extensions/external_extension_provider_impl.h
@@ -71,6 +71,10 @@
   static const char kExternalUpdateUrl[];
   static const char kSupportedLocales[];
 
+  void set_auto_acknowledge(bool auto_acknowledge) {
+    auto_acknowledge_ = auto_acknowledge;
+  }
+
  private:
   // Location for external extensions that are provided by this provider from
   // local crx files.
@@ -99,6 +103,10 @@
   // when calling Extenion::Create() by the crx installer.
   int creation_flags_;
 
+  // Whether loaded extensions should be automatically acknowledged, so that
+  // the user doesn't see an alert about them.
+  bool auto_acknowledge_;
+
   DISALLOW_COPY_AND_ASSIGN(ExternalExtensionProviderImpl);
 };
 
diff --git a/chrome/browser/extensions/external_extension_provider_interface.h b/chrome/browser/extensions/external_extension_provider_interface.h
index 313e2c7..088b179 100644
--- a/chrome/browser/extensions/external_extension_provider_interface.h
+++ b/chrome/browser/extensions/external_extension_provider_interface.h
@@ -30,7 +30,8 @@
         const Version* version,
         const FilePath& path,
         Extension::Location location,
-        int creation_flags) = 0;
+        int creation_flags,
+        bool mark_acknowledged) = 0;
 
     virtual void OnExternalExtensionUpdateUrlFound(
         const std::string& id,
diff --git a/chrome/browser/extensions/external_policy_extension_loader_unittest.cc b/chrome/browser/extensions/external_policy_extension_loader_unittest.cc
index c5fa9f5..4d0d085 100644
--- a/chrome/browser/extensions/external_policy_extension_loader_unittest.cc
+++ b/chrome/browser/extensions/external_policy_extension_loader_unittest.cc
@@ -69,7 +69,8 @@
                                             const Version* version,
                                             const FilePath& path,
                                             Extension::Location unused,
-                                            int unused2) {
+                                            int unused2,
+                                            bool unused3) {
     ADD_FAILURE() << "There should be no external extensions from files.";
   }