| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/service/service_process.h" | 5 #include "chrome/service/service_process.h" |
| 6 | 6 |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "chrome/service/cloud_print/cloud_print_proxy.h" | 8 #include "chrome/service/cloud_print/cloud_print_proxy.h" |
| 9 #include "chrome/service/net/service_network_change_notifier_thread.h" | 9 #include "net/base/network_change_notifier.h" |
| 10 | 10 |
| 11 ServiceProcess* g_service_process = NULL; | 11 ServiceProcess* g_service_process = NULL; |
| 12 | 12 |
| 13 ServiceProcess::ServiceProcess() { | 13 ServiceProcess::ServiceProcess() { |
| 14 DCHECK(!g_service_process); | 14 DCHECK(!g_service_process); |
| 15 g_service_process = this; | 15 g_service_process = this; |
| 16 } | 16 } |
| 17 | 17 |
| 18 bool ServiceProcess::Initialize() { | 18 bool ServiceProcess::Initialize() { |
| 19 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 19 base::Thread::Options options; | 20 base::Thread::Options options; |
| 20 options.message_loop_type = MessageLoop::TYPE_IO; | 21 options.message_loop_type = MessageLoop::TYPE_IO; |
| 21 io_thread_.reset(new base::Thread("ServiceProcess_IO")); | 22 io_thread_.reset(new base::Thread("ServiceProcess_IO")); |
| 22 file_thread_.reset(new base::Thread("ServiceProcess_File")); | 23 file_thread_.reset(new base::Thread("ServiceProcess_File")); |
| 23 if (!io_thread_->StartWithOptions(options) || | 24 if (!io_thread_->StartWithOptions(options) || |
| 24 !file_thread_->StartWithOptions(options)) { | 25 !file_thread_->StartWithOptions(options)) { |
| 25 NOTREACHED(); | 26 NOTREACHED(); |
| 26 Teardown(); | 27 Teardown(); |
| 27 return false; | 28 return false; |
| 28 } | 29 } |
| 29 network_change_notifier_thread_ = | |
| 30 new ServiceNetworkChangeNotifierThread(io_thread_->message_loop()); | |
| 31 network_change_notifier_thread_->Initialize(); | |
| 32 return true; | 30 return true; |
| 33 } | 31 } |
| 34 | 32 |
| 35 bool ServiceProcess::Teardown() { | 33 bool ServiceProcess::Teardown() { |
| 36 network_change_notifier_thread_ = NULL; | |
| 37 io_thread_.reset(); | 34 io_thread_.reset(); |
| 38 file_thread_.reset(); | 35 file_thread_.reset(); |
| 39 STLDeleteElements(&cloud_print_proxy_list_); | 36 STLDeleteElements(&cloud_print_proxy_list_); |
| 37 // The NetworkChangeNotifier must be destroyed after all other threads that |
| 38 // might use it have been shut down. |
| 39 network_change_notifier_.reset(); |
| 40 return true; | 40 return true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 CloudPrintProxy* ServiceProcess::CreateCloudPrintProxy( | 43 CloudPrintProxy* ServiceProcess::CreateCloudPrintProxy( |
| 44 JsonPrefStore* service_prefs) { | 44 JsonPrefStore* service_prefs) { |
| 45 CloudPrintProxy* cloud_print_proxy = new CloudPrintProxy(); | 45 CloudPrintProxy* cloud_print_proxy = new CloudPrintProxy(); |
| 46 cloud_print_proxy->Initialize(service_prefs); | 46 cloud_print_proxy->Initialize(service_prefs); |
| 47 cloud_print_proxy_list_.push_back(cloud_print_proxy); | 47 cloud_print_proxy_list_.push_back(cloud_print_proxy); |
| 48 return cloud_print_proxy; | 48 return cloud_print_proxy; |
| 49 } | 49 } |
| 50 | 50 |
| 51 ServiceProcess::~ServiceProcess() { | 51 ServiceProcess::~ServiceProcess() { |
| 52 Teardown(); | 52 Teardown(); |
| 53 DCHECK(cloud_print_proxy_list_.size() == 0); | 53 DCHECK(cloud_print_proxy_list_.size() == 0); |
| 54 g_service_process = NULL; | 54 g_service_process = NULL; |
| 55 } | 55 } |
| 56 | 56 |
| OLD | NEW |