1 // Copyright 2019 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/extensions/scoped_active_install.h" 6 7 #include "chrome/browser/extensions/active_install_data.h" 8 9 namespace extensions { 10 ScopedActiveInstall(InstallTracker * tracker,const ActiveInstallData & install_data)11ScopedActiveInstall::ScopedActiveInstall(InstallTracker* tracker, 12 const ActiveInstallData& install_data) 13 : tracker_(tracker), extension_id_(install_data.extension_id) { 14 Init(); 15 tracker_->AddActiveInstall(install_data); 16 } 17 ScopedActiveInstall(InstallTracker * tracker,const std::string & extension_id)18ScopedActiveInstall::ScopedActiveInstall(InstallTracker* tracker, 19 const std::string& extension_id) 20 : tracker_(tracker), extension_id_(extension_id) { 21 Init(); 22 } 23 ~ScopedActiveInstall()24ScopedActiveInstall::~ScopedActiveInstall() { 25 if (tracker_) 26 tracker_->RemoveActiveInstall(extension_id_); 27 } 28 CancelDeregister()29void ScopedActiveInstall::CancelDeregister() { 30 tracker_observer_.RemoveAll(); 31 tracker_ = nullptr; 32 } 33 Init()34void ScopedActiveInstall::Init() { 35 DCHECK(!extension_id_.empty()); 36 DCHECK(tracker_); 37 tracker_observer_.Add(tracker_); 38 } 39 OnShutdown()40void ScopedActiveInstall::OnShutdown() { 41 CancelDeregister(); 42 } 43 44 } // namespace extensions 45