| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/service_process/service_process_control.h" | 5 #include "chrome/browser/service_process/service_process_control.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/metrics/histogram_base.h" | 11 #include "base/metrics/histogram_base.h" |
| 12 #include "base/metrics/histogram_delta_serialization.h" | 12 #include "base/metrics/histogram_delta_serialization.h" |
| 13 #include "base/process/kill.h" | 13 #include "base/process/kill.h" |
| 14 #include "base/process/launch.h" | 14 #include "base/process/launch.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/upgrade_detector.h" | 20 #include "chrome/browser/upgrade_detector.h" |
| 21 #include "chrome/common/service_messages.h" | 21 #include "chrome/common/service_messages.h" |
| 22 #include "chrome/common/service_process_util.h" | 22 #include "chrome/common/service_process_util.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 | 25 |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 | 27 |
| 28 namespace { |
| 29 |
| 30 // Test: On Mac, launchd_msg_send tries to allocate a 10MB buffer, but doesn't |
| 31 // handle errors and makes ugly crash dumps when close to OOM. |
| 32 // TODO(vitalybuka): Remove after few Canary builds. |
| 33 // See http://crbug.com/406227 |
| 34 void AllocDebugTest() { |
| 35 #if defined(OS_MACOSX) |
| 36 void* buffer = malloc(20 * 1024 * 1024); |
| 37 CHECK(buffer); |
| 38 free(buffer); |
| 39 #endif // OS_MACOSX |
| 40 } |
| 41 |
| 42 } // namespace |
| 43 |
| 28 // ServiceProcessControl implementation. | 44 // ServiceProcessControl implementation. |
| 29 ServiceProcessControl::ServiceProcessControl() { | 45 ServiceProcessControl::ServiceProcessControl() { |
| 30 } | 46 } |
| 31 | 47 |
| 32 ServiceProcessControl::~ServiceProcessControl() { | 48 ServiceProcessControl::~ServiceProcessControl() { |
| 33 } | 49 } |
| 34 | 50 |
| 35 void ServiceProcessControl::ConnectInternal() { | 51 void ServiceProcessControl::ConnectInternal() { |
| 36 // If the channel has already been established then we run the task | 52 // If the channel has already been established then we run the task |
| 37 // and return. | 53 // and return. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 const std::vector<std::string>& pickled_histograms) { | 232 const std::vector<std::string>& pickled_histograms) { |
| 217 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", | 233 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", |
| 218 SERVICE_EVENT_HISTOGRAMS_REPLY, SERVICE_EVENT_MAX); | 234 SERVICE_EVENT_HISTOGRAMS_REPLY, SERVICE_EVENT_MAX); |
| 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 220 base::HistogramDeltaSerialization::DeserializeAndAddSamples( | 236 base::HistogramDeltaSerialization::DeserializeAndAddSamples( |
| 221 pickled_histograms); | 237 pickled_histograms); |
| 222 RunHistogramsCallback(); | 238 RunHistogramsCallback(); |
| 223 } | 239 } |
| 224 | 240 |
| 225 void ServiceProcessControl::RunHistogramsCallback() { | 241 void ServiceProcessControl::RunHistogramsCallback() { |
| 242 AllocDebugTest(); |
| 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 227 if (!histograms_callback_.is_null()) { | 244 if (!histograms_callback_.is_null()) { |
| 228 histograms_callback_.Run(); | 245 histograms_callback_.Run(); |
| 229 histograms_callback_.Reset(); | 246 histograms_callback_.Reset(); |
| 230 } | 247 } |
| 231 histograms_timeout_callback_.Cancel(); | 248 histograms_timeout_callback_.Cancel(); |
| 232 } | 249 } |
| 233 | 250 |
| 234 void ServiceProcessControl::OnPrinters( | 251 void ServiceProcessControl::OnPrinters( |
| 235 const std::vector<std::string>& printers) { | 252 const std::vector<std::string>& printers) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 252 SERVICE_EVENT_INFO_REQUEST, SERVICE_EVENT_MAX); | 269 SERVICE_EVENT_INFO_REQUEST, SERVICE_EVENT_MAX); |
| 253 if (!Send(new ServiceMsg_GetCloudPrintProxyInfo())) | 270 if (!Send(new ServiceMsg_GetCloudPrintProxyInfo())) |
| 254 return false; | 271 return false; |
| 255 cloud_print_info_callback_ = cloud_print_info_callback; | 272 cloud_print_info_callback_ = cloud_print_info_callback; |
| 256 return true; | 273 return true; |
| 257 } | 274 } |
| 258 | 275 |
| 259 bool ServiceProcessControl::GetHistograms( | 276 bool ServiceProcessControl::GetHistograms( |
| 260 const base::Closure& histograms_callback, | 277 const base::Closure& histograms_callback, |
| 261 const base::TimeDelta& timeout) { | 278 const base::TimeDelta& timeout) { |
| 279 AllocDebugTest(); |
| 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 263 DCHECK(!histograms_callback.is_null()); | 281 DCHECK(!histograms_callback.is_null()); |
| 264 histograms_callback_.Reset(); | 282 histograms_callback_.Reset(); |
| 265 | 283 |
| 266 // If the service process is already running then connect to it. | 284 // If the service process is already running then connect to it. |
| 267 if (!CheckServiceProcessReady()) | 285 if (!CheckServiceProcessReady()) |
| 268 return false; | 286 return false; |
| 269 ConnectInternal(); | 287 ConnectInternal(); |
| 270 | 288 |
| 271 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", | 289 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 if (base::LaunchProcess(*cmd_line_, options, &process_handle_)) { | 403 if (base::LaunchProcess(*cmd_line_, options, &process_handle_)) { |
| 386 BrowserThread::PostTask( | 404 BrowserThread::PostTask( |
| 387 BrowserThread::IO, FROM_HERE, | 405 BrowserThread::IO, FROM_HERE, |
| 388 base::Bind(&Launcher::DoDetectLaunched, this)); | 406 base::Bind(&Launcher::DoDetectLaunched, this)); |
| 389 } else { | 407 } else { |
| 390 BrowserThread::PostTask( | 408 BrowserThread::PostTask( |
| 391 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); | 409 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); |
| 392 } | 410 } |
| 393 } | 411 } |
| 394 #endif // !OS_MACOSX | 412 #endif // !OS_MACOSX |
| OLD | NEW |