Home | History | Annotate | Download | only in automation
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/automation/automation_extension_tracker.h"
      6 #include "chrome/browser/extensions/extension_service.h"
      7 #include "chrome/browser/profiles/profile.h"
      8 #include "chrome/common/extensions/extension.h"
      9 #include "content/common/notification_service.h"
     10 
     11 AutomationExtensionTracker::AutomationExtensionTracker(
     12     IPC::Message::Sender* automation)
     13     : AutomationResourceTracker<const Extension*>(automation) {
     14   registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
     15                  NotificationService::AllSources());
     16 }
     17 
     18 AutomationExtensionTracker::~AutomationExtensionTracker() {
     19 }
     20 
     21 void AutomationExtensionTracker::AddObserver(const Extension* resource) {}
     22 
     23 void AutomationExtensionTracker::RemoveObserver(const Extension* resource) {}
     24 
     25 void AutomationExtensionTracker::Observe(NotificationType type,
     26                                          const NotificationSource& source,
     27                                          const NotificationDetails& details) {
     28   if (type != NotificationType::EXTENSION_UNLOADED) {
     29     NOTREACHED();
     30     return;
     31   }
     32   UnloadedExtensionInfo* info = Details<UnloadedExtensionInfo>(details).ptr();
     33   const Extension* extension = info->extension;
     34   Profile* profile = Source<Profile>(source).ptr();
     35   if (profile) {
     36     ExtensionService* service = profile->GetExtensionService();
     37     if (service && info->reason == UnloadedExtensionInfo::UNINSTALL) {
     38       // Remove this extension only if it is uninstalled, not just disabled.
     39       CloseResource(extension);
     40     }
     41   }
     42 }
     43