summaryrefslogtreecommitdiffstats
path: root/chrome/browser/service/service_process_control_manager.cc
blob: ef1f007b8ad17ea24c072d9d0068bfc09f55ec1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/service/service_process_control_manager.h"

#include "base/singleton.h"
#include "base/stl_util-inl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/service/service_process_control.h"
#include "content/browser/browser_thread.h"

ServiceProcessControlManager::ServiceProcessControlManager() {
}

ServiceProcessControlManager::~ServiceProcessControlManager() {
  DCHECK(process_control_list_.empty());
}

ServiceProcessControl* ServiceProcessControlManager::GetProcessControl(
    Profile* profile) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

  // TODO(hclam): We will have different service process for different types of
  // service, but now we only create a new process for a different profile.
  for (ServiceProcessControlList::iterator i = process_control_list_.begin();
       i != process_control_list_.end(); ++i) {
    if ((*i)->profile() == profile)
      return *i;
  }

  // Couldn't find a ServiceProcess so construct a new one.
  ServiceProcessControl* process  = new ServiceProcessControl(profile);
  process_control_list_.push_back(process);
  return process;
}

void ServiceProcessControlManager::Shutdown() {
  // When we shutdown the manager we just clear the list and don't actually
  // shutdown the service process.
  STLDeleteElements(&process_control_list_);
}

// static
ServiceProcessControlManager* ServiceProcessControlManager::GetInstance() {
  return Singleton<ServiceProcessControlManager>::get();
}