• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2006-2008 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_provider_list.h"
6 
7 #include <algorithm>
8 
9 #include "base/logging.h"
10 #include "chrome/browser/automation/automation_provider.h"
11 
12 AutomationProviderList* AutomationProviderList::instance_ = NULL;
13 
AutomationProviderList()14 AutomationProviderList::AutomationProviderList() {
15 }
16 
~AutomationProviderList()17 AutomationProviderList::~AutomationProviderList() {
18   iterator iter = automation_providers_.begin();
19   while (iter != automation_providers_.end()) {
20     (*iter)->Release();
21     iter = automation_providers_.erase(iter);
22   }
23   instance_ = NULL;
24 }
25 
AddProvider(AutomationProvider * provider)26 bool AutomationProviderList::AddProvider(AutomationProvider* provider) {
27   provider->AddRef();
28   automation_providers_.push_back(provider);
29   return true;
30 }
31 
RemoveProvider(AutomationProvider * provider)32 bool AutomationProviderList::RemoveProvider(AutomationProvider* provider) {
33   const iterator remove_provider =
34     find(automation_providers_.begin(), automation_providers_.end(), provider);
35   if (remove_provider != automation_providers_.end()) {
36     (*remove_provider)->Release();
37     automation_providers_.erase(remove_provider);
38     if (automation_providers_.empty())
39       OnLastProviderRemoved();
40     return true;
41   }
42   return false;
43 }
44 
GetInstance()45 AutomationProviderList* AutomationProviderList::GetInstance() {
46   if (!instance_) {
47     instance_ = new AutomationProviderList;
48   }
49   DCHECK(NULL != instance_);
50   return instance_;
51 }
52