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/service/service_process_control_manager.h"
6
7#include "base/memory/singleton.h"
8#include "base/stl_util-inl.h"
9#include "chrome/browser/profiles/profile.h"
10#include "chrome/browser/service/service_process_control.h"
11#include "content/browser/browser_thread.h"
12
13ServiceProcessControlManager::ServiceProcessControlManager() {
14}
15
16ServiceProcessControlManager::~ServiceProcessControlManager() {
17  DCHECK(process_control_list_.empty());
18}
19
20ServiceProcessControl* ServiceProcessControlManager::GetProcessControl(
21    Profile* profile) {
22  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
23
24  // TODO(hclam): We will have different service process for different types of
25  // service, but now we only create a new process for a different profile.
26  for (ServiceProcessControlList::iterator i = process_control_list_.begin();
27       i != process_control_list_.end(); ++i) {
28    if ((*i)->profile() == profile)
29      return *i;
30  }
31
32  // Couldn't find a ServiceProcess so construct a new one.
33  ServiceProcessControl* process  = new ServiceProcessControl(profile);
34  process_control_list_.push_back(process);
35  return process;
36}
37
38void ServiceProcessControlManager::Shutdown() {
39  // When we shutdown the manager we just clear the list and don't actually
40  // shutdown the service process.
41  STLDeleteElements(&process_control_list_);
42}
43
44// static
45ServiceProcessControlManager* ServiceProcessControlManager::GetInstance() {
46  return Singleton<ServiceProcessControlManager>::get();
47}
48