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

Side by Side Diff: win8/viewer/metro_viewer_process_host.cc

Issue 584213002: Only do aggressive metro viewer termination in tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 6 years, 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "win8/viewer/metro_viewer_process_host.h" 5 #include "win8/viewer/metro_viewer_process_host.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
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"
(...skipping 29 matching lines...) Expand all
40 MetroViewerProcessHost* owner) 40 MetroViewerProcessHost* owner)
41 : owner_(owner) { 41 : owner_(owner) {
42 } 42 }
43 43
44 void MetroViewerProcessHost::InternalMessageFilter::OnChannelConnected( 44 void MetroViewerProcessHost::InternalMessageFilter::OnChannelConnected(
45 int32 peer_pid) { 45 int32 peer_pid) {
46 owner_->NotifyChannelConnected(); 46 owner_->NotifyChannelConnected();
47 } 47 }
48 48
49 MetroViewerProcessHost::MetroViewerProcessHost( 49 MetroViewerProcessHost::MetroViewerProcessHost(
50 base::SingleThreadTaskRunner* ipc_task_runner) { 50 base::SingleThreadTaskRunner* ipc_task_runner)
51 : launched_for_test_(false) {
51 DCHECK(!instance_); 52 DCHECK(!instance_);
52 instance_ = this; 53 instance_ = this;
53 54
54 channel_ = IPC::ChannelProxy::Create(kMetroViewerIPCChannelName, 55 channel_ = IPC::ChannelProxy::Create(kMetroViewerIPCChannelName,
55 IPC::Channel::MODE_NAMED_SERVER, 56 IPC::Channel::MODE_NAMED_SERVER,
56 this, 57 this,
57 ipc_task_runner); 58 ipc_task_runner);
58 } 59 }
59 60
60 MetroViewerProcessHost::~MetroViewerProcessHost() { 61 MetroViewerProcessHost::~MetroViewerProcessHost() {
61 if (!channel_) { 62 if (!channel_) {
62 instance_ = NULL; 63 instance_ = NULL;
63 return; 64 return;
64 } 65 }
65 66
66 base::ProcessId viewer_process_id = GetViewerProcessId(); 67 base::ProcessId viewer_process_id = GetViewerProcessId();
67 channel_->Close(); 68 channel_->Close();
68 if (message_filter_) { 69 if (message_filter_) {
69 // Wait for the viewer process to go away. 70 // Wait for the viewer process to go away.
70 if (viewer_process_id != base::kNullProcessId) { 71 if (viewer_process_id != base::kNullProcessId) {
71 base::ProcessHandle viewer_process = NULL; 72 base::ProcessHandle viewer_process = NULL;
72 base::OpenProcessHandleWithAccess( 73 base::OpenProcessHandleWithAccess(
73 viewer_process_id, 74 viewer_process_id,
74 PROCESS_QUERY_INFORMATION | SYNCHRONIZE, 75 PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
75 &viewer_process); 76 &viewer_process);
76 if (viewer_process) { 77 if (viewer_process) {
77 ::WaitForSingleObject(viewer_process, INFINITE); 78 if (launched_for_test_) {
79 // In tests, we don't want to wait around for the viewer to
80 // terminate, so kill it after a short delay. See
81 // http://crbug.com/411147 for more details.
82 ::WaitForSingleObject(viewer_process, 100);
ananta 2014/09/19 19:36:57 Just TerminateProcess here?. The viewer has no sta
scottmg 2014/09/19 19:41:19 Sure, Done.
83 ::TerminateProcess(viewer_process, 0);
84 } else {
85 ::WaitForSingleObject(viewer_process, INFINITE);
86 }
78 ::CloseHandle(viewer_process); 87 ::CloseHandle(viewer_process);
79 } 88 }
80 } 89 }
81 channel_->RemoveFilter(message_filter_); 90 channel_->RemoveFilter(message_filter_);
82 } 91 }
83 instance_ = NULL; 92 instance_ = NULL;
84 } 93 }
85 94
86 base::ProcessId MetroViewerProcessHost::GetViewerProcessId() { 95 base::ProcessId MetroViewerProcessHost::GetViewerProcessId() {
87 if (channel_) 96 if (channel_)
88 return channel_->GetPeerPID(); 97 return channel_->GetPeerPID();
89 return base::kNullProcessId; 98 return base::kNullProcessId;
90 } 99 }
91 100
101 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnectionForTests(
102 const base::string16& app_user_model_id) {
103 launched_for_test_ = true;
104 return LaunchViewerAndWaitForConnection(app_user_model_id);
105 }
106
92 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection( 107 bool MetroViewerProcessHost::LaunchViewerAndWaitForConnection(
93 const base::string16& app_user_model_id) { 108 const base::string16& app_user_model_id) {
94 DCHECK_EQ(base::kNullProcessId, channel_->GetPeerPID()); 109 DCHECK_EQ(base::kNullProcessId, channel_->GetPeerPID());
95 110
96 channel_connected_event_.reset(new base::WaitableEvent(false, false)); 111 channel_connected_event_.reset(new base::WaitableEvent(false, false));
97 112
98 message_filter_ = new InternalMessageFilter(this); 113 message_filter_ = new InternalMessageFilter(this);
99 channel_->AddFilter(message_filter_); 114 channel_->AddFilter(message_filter_);
100 115
101 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 116 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 const base::FilePath& folder) { 350 const base::FilePath& folder) {
336 if (success) 351 if (success)
337 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL); 352 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL);
338 else 353 else
339 failure_callback_.Run(NULL); 354 failure_callback_.Run(NULL);
340 select_folder_completion_callback_.Reset(); 355 select_folder_completion_callback_.Reset();
341 failure_callback_.Reset(); 356 failure_callback_.Reset();
342 } 357 }
343 358
344 } // namespace win8 359 } // namespace win8
OLDNEW
« ash/test/ash_test_base.cc ('K') | « win8/viewer/metro_viewer_process_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698