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

Side by Side Diff: remoting/host/desktop_win.cc

Issue 10832068: Moving Windows-only files: remoting/host -> remoting/host/win. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/desktop_win.h ('k') | remoting/host/elevated_controller.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "remoting/host/desktop_win.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10
11 namespace remoting {
12
13 DesktopWin::DesktopWin(HDESK desktop, bool own) : desktop_(desktop), own_(own) {
14 }
15
16 DesktopWin::~DesktopWin() {
17 if (own_ && desktop_ != NULL) {
18 if (!::CloseDesktop(desktop_)) {
19 LOG_GETLASTERROR(ERROR)
20 << "Failed to close the owned desktop handle";
21 }
22 }
23 }
24
25 bool DesktopWin::GetName(string16* desktop_name_out) const {
26 if (desktop_ == NULL)
27 return false;
28
29 DWORD length;
30 CHECK(!GetUserObjectInformationW(desktop_, UOI_NAME, NULL, 0, &length));
31 CHECK(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
32
33 length /= sizeof(char16);
34 std::vector<char16> buffer(length);
35 if (!GetUserObjectInformationW(desktop_, UOI_NAME, &buffer[0],
36 length * sizeof(char16), &length)) {
37 LOG_GETLASTERROR(ERROR)
38 << "Failed to query the desktop name";
39 return false;
40 }
41
42 desktop_name_out->assign(&buffer[0], length / sizeof(char16));
43 return true;
44 }
45
46 bool DesktopWin::IsSame(const DesktopWin& other) const {
47 string16 name;
48 if (!GetName(&name))
49 return false;
50
51 string16 other_name;
52 if (!other.GetName(&other_name))
53 return false;
54
55 return name == other_name;
56 }
57
58 bool DesktopWin::SetThreadDesktop() const {
59 if (!::SetThreadDesktop(desktop_)) {
60 LOG_GETLASTERROR(ERROR)
61 << "Failed to assign the desktop to the current thread";
62 return false;
63 }
64
65 return true;
66 }
67
68 scoped_ptr<DesktopWin> DesktopWin::GetDesktop(const wchar_t* desktop_name) {
69 ACCESS_MASK desired_access =
70 DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE |
71 DESKTOP_HOOKCONTROL | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
72 DESKTOP_SWITCHDESKTOP | GENERIC_WRITE;
73 HDESK desktop = OpenDesktop(desktop_name, 0, FALSE, desired_access);
74 if (desktop == NULL) {
75 LOG_GETLASTERROR(ERROR)
76 << "Failed to open the desktop '" << desktop_name << "'";
77 return scoped_ptr<DesktopWin>();
78 }
79
80 return scoped_ptr<DesktopWin>(new DesktopWin(desktop, true));
81 }
82
83 scoped_ptr<DesktopWin> DesktopWin::GetInputDesktop() {
84 HDESK desktop = OpenInputDesktop(
85 0, FALSE, GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE);
86 if (desktop == NULL) {
87 LOG_GETLASTERROR(ERROR)
88 << "Failed to open the desktop receiving user input";
89 return scoped_ptr<DesktopWin>();
90 }
91
92 return scoped_ptr<DesktopWin>(new DesktopWin(desktop, true));
93 }
94
95 scoped_ptr<DesktopWin> DesktopWin::GetThreadDesktop() {
96 HDESK desktop = ::GetThreadDesktop(GetCurrentThreadId());
97 if (desktop == NULL) {
98 LOG_GETLASTERROR(ERROR)
99 << "Failed to retrieve the handle of the desktop assigned to "
100 "the current thread";
101 return scoped_ptr<DesktopWin>();
102 }
103
104 return scoped_ptr<DesktopWin>(new DesktopWin(desktop, false));
105 }
106
107 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/desktop_win.h ('k') | remoting/host/elevated_controller.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698