Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1655)

Side by Side Diff: chrome/browser/service_process/service_process_control.cc

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Add DISALLOW_COPY_AND_ASSIGN Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/metrics/histogram_base.h" 15 #include "base/metrics/histogram_base.h"
16 #include "base/metrics/histogram_delta_serialization.h" 16 #include "base/metrics/histogram_delta_serialization.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/process/kill.h" 18 #include "base/process/kill.h"
19 #include "base/process/launch.h" 19 #include "base/process/launch.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/stl_util.h" 21 #include "base/stl_util.h"
22 #include "base/task_scheduler/post_task.h" 22 #include "base/task_scheduler/post_task.h"
23 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
24 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
25 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "chrome/browser/browser_process.h" 27 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/upgrade_detector.h" 28 #include "chrome/browser/upgrade_detector.h"
30 #include "chrome/common/service_messages.h" 29 #include "chrome/common/service_messages.h"
31 #include "chrome/common/service_process_util.h" 30 #include "chrome/common/service_process_util.h"
32 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/notification_service.h"
34 #include "ipc/ipc_channel_mojo.h" 32 #include "ipc/ipc_channel_mojo.h"
35 #include "mojo/edk/embedder/embedder.h" 33 #include "mojo/edk/embedder/embedder.h"
36 #include "mojo/edk/embedder/named_platform_handle.h" 34 #include "mojo/edk/embedder/named_platform_handle.h"
37 #include "mojo/edk/embedder/named_platform_handle_utils.h" 35 #include "mojo/edk/embedder/named_platform_handle_utils.h"
38 #include "mojo/edk/embedder/peer_connection.h" 36 #include "mojo/edk/embedder/peer_connection.h"
39 37
40 using content::BrowserThread; 38 using content::BrowserThread;
41 39
42 namespace { 40 namespace {
43 41
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 std::move(handle)); 78 std::move(handle));
81 response_task_runner->PostTask(FROM_HERE, 79 response_task_runner->PostTask(FROM_HERE,
82 base::BindOnce(std::move(response_callback), 80 base::BindOnce(std::move(response_callback),
83 std::move(peer_connection))); 81 std::move(peer_connection)));
84 } 82 }
85 } 83 }
86 84
87 } // namespace 85 } // namespace
88 86
89 // ServiceProcessControl implementation. 87 // ServiceProcessControl implementation.
90 ServiceProcessControl::ServiceProcessControl() : weak_factory_(this) {} 88 ServiceProcessControl::ServiceProcessControl()
89 : apply_changes_from_upgrade_observer_(false), weak_factory_(this) {
90 UpgradeDetector::GetInstance()->AddObserver(this);
91 }
91 92
92 ServiceProcessControl::~ServiceProcessControl() { 93 ServiceProcessControl::~ServiceProcessControl() {
94 UpgradeDetector::GetInstance()->RemoveObserver(this);
93 } 95 }
94 96
95 void ServiceProcessControl::ConnectInternal() { 97 void ServiceProcessControl::ConnectInternal() {
96 // If the channel has already been established then we run the task 98 // If the channel has already been established then we run the task
97 // and return. 99 // and return.
98 if (channel_.get()) { 100 if (channel_.get()) {
99 RunConnectDoneTasks(); 101 RunConnectDoneTasks();
100 return; 102 return;
101 } 103 }
102 104
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 237 }
236 238
237 void ServiceProcessControl::OnChannelConnected(int32_t peer_pid) { 239 void ServiceProcessControl::OnChannelConnected(int32_t peer_pid) {
238 DCHECK_CURRENTLY_ON(BrowserThread::UI); 240 DCHECK_CURRENTLY_ON(BrowserThread::UI);
239 241
240 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", 242 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
241 SERVICE_EVENT_CHANNEL_CONNECTED, SERVICE_EVENT_MAX); 243 SERVICE_EVENT_CHANNEL_CONNECTED, SERVICE_EVENT_MAX);
242 244
243 // We just established a channel with the service process. Notify it if an 245 // We just established a channel with the service process. Notify it if an
244 // upgrade is available. 246 // upgrade is available.
245 if (UpgradeDetector::GetInstance()->notify_upgrade()) { 247 if (UpgradeDetector::GetInstance()->notify_upgrade())
246 Send(new ServiceMsg_UpdateAvailable); 248 Send(new ServiceMsg_UpdateAvailable);
247 } else { 249 else
248 if (registrar_.IsEmpty()) 250 apply_changes_from_upgrade_observer_ = true;
249 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 251
250 content::NotificationService::AllSources());
251 }
252 RunConnectDoneTasks(); 252 RunConnectDoneTasks();
253 } 253 }
254 254
255 void ServiceProcessControl::OnChannelError() { 255 void ServiceProcessControl::OnChannelError() {
256 DCHECK_CURRENTLY_ON(BrowserThread::UI); 256 DCHECK_CURRENTLY_ON(BrowserThread::UI);
257 257
258 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", 258 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
259 SERVICE_EVENT_CHANNEL_ERROR, SERVICE_EVENT_MAX); 259 SERVICE_EVENT_CHANNEL_ERROR, SERVICE_EVENT_MAX);
260 260
261 channel_.reset(); 261 channel_.reset();
262 peer_connection_.reset(); 262 peer_connection_.reset();
263 RunConnectDoneTasks(); 263 RunConnectDoneTasks();
264 } 264 }
265 265
266 bool ServiceProcessControl::Send(IPC::Message* message) { 266 bool ServiceProcessControl::Send(IPC::Message* message) {
267 DCHECK_CURRENTLY_ON(BrowserThread::UI); 267 DCHECK_CURRENTLY_ON(BrowserThread::UI);
268 if (!channel_.get()) 268 if (!channel_.get())
269 return false; 269 return false;
270 return channel_->Send(message); 270 return channel_->Send(message);
271 } 271 }
272 272
273 // content::NotificationObserver implementation. 273 void ServiceProcessControl::OnUpgradeRecommended() {
274 void ServiceProcessControl::Observe( 274 if (apply_changes_from_upgrade_observer_)
275 int type, 275 Send(new ServiceMsg_UpdateAvailable);
276 const content::NotificationSource& source,
277 const content::NotificationDetails& details) {
278 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type);
279 Send(new ServiceMsg_UpdateAvailable);
280 } 276 }
281 277
282 void ServiceProcessControl::OnCloudPrintProxyInfo( 278 void ServiceProcessControl::OnCloudPrintProxyInfo(
283 const cloud_print::CloudPrintProxyInfo& proxy_info) { 279 const cloud_print::CloudPrintProxyInfo& proxy_info) {
284 DCHECK_CURRENTLY_ON(BrowserThread::UI); 280 DCHECK_CURRENTLY_ON(BrowserThread::UI);
285 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", 281 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
286 SERVICE_EVENT_INFO_REPLY, SERVICE_EVENT_MAX); 282 SERVICE_EVENT_INFO_REPLY, SERVICE_EVENT_MAX);
287 if (!cloud_print_info_callback_.is_null()) { 283 if (!cloud_print_info_callback_.is_null()) {
288 cloud_print_info_callback_.Run(proxy_info); 284 cloud_print_info_callback_.Run(proxy_info);
289 cloud_print_info_callback_.Reset(); 285 cloud_print_info_callback_.Reset();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (process_.IsValid()) { 451 if (process_.IsValid()) {
456 BrowserThread::PostTask( 452 BrowserThread::PostTask(
457 BrowserThread::IO, FROM_HERE, 453 BrowserThread::IO, FROM_HERE,
458 base::Bind(&Launcher::DoDetectLaunched, this)); 454 base::Bind(&Launcher::DoDetectLaunched, this));
459 } else { 455 } else {
460 BrowserThread::PostTask( 456 BrowserThread::PostTask(
461 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); 457 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this));
462 } 458 }
463 } 459 }
464 #endif // !OS_MACOSX 460 #endif // !OS_MACOSX
OLDNEW
« no previous file with comments | « chrome/browser/service_process/service_process_control.h ('k') | chrome/browser/ui/ash/system_tray_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698