summaryrefslogtreecommitdiffstats
path: root/chrome/service/service_process.cc
blob: 6e9baf25698e1e46dbd9b56add55e12880f8fccc (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
48
49
50
51
52
53
54
55
56
// 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/service/service_process.h"

#include "base/stl_util-inl.h"
#include "chrome/service/cloud_print/cloud_print_proxy.h"
#include "chrome/service/net/service_network_change_notifier_thread.h"

ServiceProcess* g_service_process = NULL;

ServiceProcess::ServiceProcess() {
  DCHECK(!g_service_process);
  g_service_process = this;
}

bool ServiceProcess::Initialize() {
  base::Thread::Options options;
  options.message_loop_type = MessageLoop::TYPE_IO;
  io_thread_.reset(new base::Thread("ServiceProcess_IO"));
  file_thread_.reset(new base::Thread("ServiceProcess_File"));
  if (!io_thread_->StartWithOptions(options) ||
      !file_thread_->StartWithOptions(options)) {
    NOTREACHED();
    Teardown();
    return false;
  }
  network_change_notifier_thread_ =
      new ServiceNetworkChangeNotifierThread(io_thread_->message_loop());
  network_change_notifier_thread_->Initialize();
  return true;
}

bool ServiceProcess::Teardown() {
  network_change_notifier_thread_ = NULL;
  io_thread_.reset();
  file_thread_.reset();
  STLDeleteElements(&cloud_print_proxy_list_);
  return true;
}

CloudPrintProxy* ServiceProcess::CreateCloudPrintProxy(
    JsonPrefStore* service_prefs) {
  CloudPrintProxy* cloud_print_proxy = new CloudPrintProxy();
  cloud_print_proxy->Initialize(service_prefs);
  cloud_print_proxy_list_.push_back(cloud_print_proxy);
  return cloud_print_proxy;
}

ServiceProcess::~ServiceProcess() {
  Teardown();
  DCHECK(cloud_print_proxy_list_.size() == 0);
  g_service_process = NULL;
}