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

Side by Side Diff: chrome/default_plugin/plugin_install_job_monitor.cc

Issue 8851007: WIP / Do not commit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/default_plugin/plugin_install_job_monitor.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "chrome/default_plugin/plugin_impl.h"
10
11 PluginInstallationJobMonitorThread::PluginInstallationJobMonitorThread()
12 : Thread("Chrome plugin install thread"),
13 install_job_completion_port_(NULL),
14 stop_job_monitoring_(false),
15 plugin_window_(NULL),
16 install_job_(NULL) {
17 }
18
19 PluginInstallationJobMonitorThread::~PluginInstallationJobMonitorThread() {
20 // The way this class is used, Thread::Stop() has always been called
21 // by the time we reach this point, so we do not need to call it
22 // again.
23 DCHECK(!Thread::IsRunning());
24 if (install_job_) {
25 ::CloseHandle(install_job_);
26 install_job_ = NULL;
27 }
28 }
29
30 bool PluginInstallationJobMonitorThread::Initialize() {
31 DCHECK(install_job_ == NULL);
32
33 install_job_ = ::CreateJobObject(NULL, NULL);
34 if (install_job_ == NULL) {
35 DLOG(ERROR) << "Failed to create plugin install job. Error = "
36 << ::GetLastError();
37 NOTREACHED();
38 return false;
39 }
40
41 return Start();
42 }
43
44 void PluginInstallationJobMonitorThread::Init() {
45 this->message_loop()->PostTask(
46 FROM_HERE,
47 base::Bind(&PluginInstallationJobMonitorThread::WaitForJobThread, this));
48 }
49
50 void PluginInstallationJobMonitorThread::WaitForJobThread() {
51 if (!install_job_) {
52 DLOG(WARNING) << "Invalid job information";
53 NOTREACHED();
54 return;
55 }
56
57 DCHECK(install_job_completion_port_ == NULL);
58
59 install_job_completion_port_ =
60 ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL,
61 reinterpret_cast<ULONG_PTR>(install_job_), 0);
62 DCHECK(install_job_completion_port_ != NULL);
63
64 JOBOBJECT_ASSOCIATE_COMPLETION_PORT job_completion_port = {0};
65 job_completion_port.CompletionKey = install_job_;
66 job_completion_port.CompletionPort = install_job_completion_port_;
67
68 if (!SetInformationJobObject(install_job_,
69 JobObjectAssociateCompletionPortInformation,
70 &job_completion_port,
71 sizeof(job_completion_port))) {
72 DLOG(WARNING) << "Failed to associate completion port with job object.Err "
73 << ::GetLastError();
74 NOTREACHED();
75 return;
76 }
77
78 while (!stop_job_monitoring_) {
79 unsigned long job_event = 0;
80 unsigned long completion_key = 0;
81 LPOVERLAPPED overlapped = NULL;
82
83 if (::GetQueuedCompletionStatus(
84 install_job_completion_port_, &job_event,
85 &completion_key, &overlapped, INFINITE)) {
86 if (job_event == JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO) {
87 DVLOG(1) << "All processes in the installer job have exited. "
88 "Initiating refresh on the plugins list";
89 DCHECK(::IsWindow(plugin_window_));
90 PostMessageW(plugin_window_,
91 PluginInstallerImpl::kRefreshPluginsMessage, 0, 0);
92 }
93 }
94 }
95 }
96
97 void PluginInstallationJobMonitorThread::Stop() {
98 stop_job_monitoring_ = true;
99 ::PostQueuedCompletionStatus(
100 install_job_completion_port_, JOB_OBJECT_MSG_END_OF_JOB_TIME,
101 reinterpret_cast<ULONG_PTR>(install_job_), NULL);
102 Thread::Stop();
103 ::CloseHandle(install_job_completion_port_);
104 install_job_completion_port_ = NULL;
105 }
106
107 bool PluginInstallationJobMonitorThread::AssignProcessToJob(
108 HANDLE process_handle) {
109 BOOL result = AssignProcessToJobObject(install_job_, process_handle);
110 return result ? true : false;
111 }
OLDNEW
« no previous file with comments | « chrome/default_plugin/plugin_install_job_monitor.h ('k') | chrome/renderer/custom_menu_commands.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698