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

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

Issue 2925973002: Migrate upgrade notifications to observer (Closed)
Patch Set: Fix test failure 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() : weak_factory_(this) {
89 UpgradeDetector::GetInstance()->AddObserver(this);
90 }
91 91
92 ServiceProcessControl::~ServiceProcessControl() { 92 ServiceProcessControl::~ServiceProcessControl() {
93 UpgradeDetector::GetInstance()->RemoveObserver(this);
93 } 94 }
94 95
95 void ServiceProcessControl::ConnectInternal() { 96 void ServiceProcessControl::ConnectInternal() {
96 // If the channel has already been established then we run the task 97 // If the channel has already been established then we run the task
97 // and return. 98 // and return.
98 if (channel_.get()) { 99 if (channel_.get()) {
99 RunConnectDoneTasks(); 100 RunConnectDoneTasks();
100 return; 101 return;
101 } 102 }
102 103
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void ServiceProcessControl::OnChannelConnected(int32_t peer_pid) { 238 void ServiceProcessControl::OnChannelConnected(int32_t peer_pid) {
238 DCHECK_CURRENTLY_ON(BrowserThread::UI); 239 DCHECK_CURRENTLY_ON(BrowserThread::UI);
239 240
240 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", 241 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
241 SERVICE_EVENT_CHANNEL_CONNECTED, SERVICE_EVENT_MAX); 242 SERVICE_EVENT_CHANNEL_CONNECTED, SERVICE_EVENT_MAX);
242 243
243 // We just established a channel with the service process. Notify it if an 244 // We just established a channel with the service process. Notify it if an
244 // upgrade is available. 245 // upgrade is available.
245 if (UpgradeDetector::GetInstance()->notify_upgrade()) { 246 if (UpgradeDetector::GetInstance()->notify_upgrade()) {
246 Send(new ServiceMsg_UpdateAvailable); 247 Send(new ServiceMsg_UpdateAvailable);
247 } else {
248 if (registrar_.IsEmpty())
249 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
250 content::NotificationService::AllSources());
251 } 248 }
252 RunConnectDoneTasks(); 249 RunConnectDoneTasks();
253 } 250 }
254 251
255 void ServiceProcessControl::OnChannelError() { 252 void ServiceProcessControl::OnChannelError() {
256 DCHECK_CURRENTLY_ON(BrowserThread::UI); 253 DCHECK_CURRENTLY_ON(BrowserThread::UI);
257 254
258 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", 255 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
259 SERVICE_EVENT_CHANNEL_ERROR, SERVICE_EVENT_MAX); 256 SERVICE_EVENT_CHANNEL_ERROR, SERVICE_EVENT_MAX);
260 257
261 channel_.reset(); 258 channel_.reset();
262 peer_connection_.reset(); 259 peer_connection_.reset();
263 RunConnectDoneTasks(); 260 RunConnectDoneTasks();
264 } 261 }
265 262
266 bool ServiceProcessControl::Send(IPC::Message* message) { 263 bool ServiceProcessControl::Send(IPC::Message* message) {
267 DCHECK_CURRENTLY_ON(BrowserThread::UI); 264 DCHECK_CURRENTLY_ON(BrowserThread::UI);
268 if (!channel_.get()) 265 if (!channel_.get())
269 return false; 266 return false;
270 return channel_->Send(message); 267 return channel_->Send(message);
271 } 268 }
272 269
273 // content::NotificationObserver implementation. 270 void ServiceProcessControl::OnUpgradeRecommended() {
274 void ServiceProcessControl::Observe(
275 int type,
276 const content::NotificationSource& source,
277 const content::NotificationDetails& details) {
278 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type);
sky 2017/06/07 23:01:41 Previously the observer was only added in a certai
weidongg 2017/06/08 02:28:42 This function will be called multiple times. So I
279 Send(new ServiceMsg_UpdateAvailable); 271 Send(new ServiceMsg_UpdateAvailable);
280 } 272 }
281 273
282 void ServiceProcessControl::OnCloudPrintProxyInfo( 274 void ServiceProcessControl::OnCloudPrintProxyInfo(
283 const cloud_print::CloudPrintProxyInfo& proxy_info) { 275 const cloud_print::CloudPrintProxyInfo& proxy_info) {
284 DCHECK_CURRENTLY_ON(BrowserThread::UI); 276 DCHECK_CURRENTLY_ON(BrowserThread::UI);
285 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", 277 UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents",
286 SERVICE_EVENT_INFO_REPLY, SERVICE_EVENT_MAX); 278 SERVICE_EVENT_INFO_REPLY, SERVICE_EVENT_MAX);
287 if (!cloud_print_info_callback_.is_null()) { 279 if (!cloud_print_info_callback_.is_null()) {
288 cloud_print_info_callback_.Run(proxy_info); 280 cloud_print_info_callback_.Run(proxy_info);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 if (process_.IsValid()) { 447 if (process_.IsValid()) {
456 BrowserThread::PostTask( 448 BrowserThread::PostTask(
457 BrowserThread::IO, FROM_HERE, 449 BrowserThread::IO, FROM_HERE,
458 base::Bind(&Launcher::DoDetectLaunched, this)); 450 base::Bind(&Launcher::DoDetectLaunched, this));
459 } else { 451 } else {
460 BrowserThread::PostTask( 452 BrowserThread::PostTask(
461 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this)); 453 BrowserThread::UI, FROM_HERE, base::Bind(&Launcher::Notify, this));
462 } 454 }
463 } 455 }
464 #endif // !OS_MACOSX 456 #endif // !OS_MACOSX
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698