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

Side by Side Diff: webrtc/base/win32filesystem.cc

Issue 1920043002: Replace scoped_ptr with unique_ptr in webrtc/base/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 7 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
« no previous file with comments | « webrtc/base/virtualsocketserver.cc ('k') | webrtc/base/win32regkey.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/win32filesystem.h" 11 #include "webrtc/base/win32filesystem.h"
12 12
13 #include "webrtc/base/win32.h" 13 #include "webrtc/base/win32.h"
14 #include <shellapi.h> 14 #include <shellapi.h>
15 #include <shlobj.h> 15 #include <shlobj.h>
16 #include <tchar.h> 16 #include <tchar.h>
17 17
18 #include <memory>
19
18 #include "webrtc/base/arraysize.h" 20 #include "webrtc/base/arraysize.h"
19 #include "webrtc/base/fileutils.h" 21 #include "webrtc/base/fileutils.h"
20 #include "webrtc/base/pathutils.h" 22 #include "webrtc/base/pathutils.h"
21 #include "webrtc/base/scoped_ptr.h"
22 #include "webrtc/base/stream.h" 23 #include "webrtc/base/stream.h"
23 #include "webrtc/base/stringutils.h" 24 #include "webrtc/base/stringutils.h"
24 25
25 // In several places in this file, we test the integrity level of the process 26 // In several places in this file, we test the integrity level of the process
26 // before calling GetLongPathName. We do this because calling GetLongPathName 27 // before calling GetLongPathName. We do this because calling GetLongPathName
27 // when running under protected mode IE (a low integrity process) can result in 28 // when running under protected mode IE (a low integrity process) can result in
28 // a virtualized path being returned, which is wrong if you only plan to read. 29 // a virtualized path being returned, which is wrong if you only plan to read.
29 // TODO: Waiting to hear back from IE team on whether this is the 30 // TODO: Waiting to hear back from IE team on whether this is the
30 // best approach; IEIsProtectedModeProcess is another possible solution. 31 // best approach; IEIsProtectedModeProcess is another possible solution.
31 32
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Get the size of its TOKEN_USER structure. Return value is not checked 89 // Get the size of its TOKEN_USER structure. Return value is not checked
89 // because we expect it to fail. 90 // because we expect it to fail.
90 DWORD token_user_size = 0; 91 DWORD token_user_size = 0;
91 (void)::GetTokenInformation(process_token, 92 (void)::GetTokenInformation(process_token,
92 TokenUser, 93 TokenUser,
93 NULL, 94 NULL,
94 0, 95 0,
95 &token_user_size); 96 &token_user_size);
96 97
97 // Get the TOKEN_USER structure. 98 // Get the TOKEN_USER structure.
98 scoped_ptr<char[]> token_user_bytes(new char[token_user_size]); 99 std::unique_ptr<char[]> token_user_bytes(new char[token_user_size]);
99 PTOKEN_USER token_user = reinterpret_cast<PTOKEN_USER>( 100 PTOKEN_USER token_user = reinterpret_cast<PTOKEN_USER>(
100 token_user_bytes.get()); 101 token_user_bytes.get());
101 memset(token_user, 0, token_user_size); 102 memset(token_user, 0, token_user_size);
102 BOOL success = ::GetTokenInformation(process_token, 103 BOOL success = ::GetTokenInformation(process_token,
103 TokenUser, 104 TokenUser,
104 token_user, 105 token_user,
105 token_user_size, 106 token_user_size,
106 &token_user_size); 107 &token_user_size);
107 // We're now done with this. 108 // We're now done with this.
108 ::CloseHandle(process_token); 109 ::CloseHandle(process_token);
109 if (!success) { 110 if (!success) {
110 LOG_ERR(LS_ERROR) << "GetTokenInformation() failed"; 111 LOG_ERR(LS_ERROR) << "GetTokenInformation() failed";
111 return false; 112 return false;
112 } 113 }
113 114
114 if (!IsValidSid(token_user->User.Sid)) { 115 if (!IsValidSid(token_user->User.Sid)) {
115 LOG_ERR(LS_ERROR) << "Current process has invalid user SID"; 116 LOG_ERR(LS_ERROR) << "Current process has invalid user SID";
116 return false; 117 return false;
117 } 118 }
118 119
119 // Compute size needed for an ACL that allows access to just this user. 120 // Compute size needed for an ACL that allows access to just this user.
120 int acl_size = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + 121 int acl_size = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) +
121 GetLengthSid(token_user->User.Sid); 122 GetLengthSid(token_user->User.Sid);
122 123
123 // Allocate it. 124 // Allocate it.
124 scoped_ptr<char[]> acl_bytes(new char[acl_size]); 125 std::unique_ptr<char[]> acl_bytes(new char[acl_size]);
125 PACL acl = reinterpret_cast<PACL>(acl_bytes.get()); 126 PACL acl = reinterpret_cast<PACL>(acl_bytes.get());
126 memset(acl, 0, acl_size); 127 memset(acl, 0, acl_size);
127 if (!::InitializeAcl(acl, acl_size, ACL_REVISION)) { 128 if (!::InitializeAcl(acl, acl_size, ACL_REVISION)) {
128 LOG_ERR(LS_ERROR) << "InitializeAcl() failed"; 129 LOG_ERR(LS_ERROR) << "InitializeAcl() failed";
129 return false; 130 return false;
130 } 131 }
131 132
132 // Allow access to only the current user. 133 // Allow access to only the current user.
133 if (!::AddAccessAllowedAce(acl, 134 if (!::AddAccessAllowedAce(acl,
134 ACL_REVISION, 135 ACL_REVISION,
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 return true; 419 return true;
419 } else { 420 } else {
420 LOG(LS_VERBOSE) << "GetDiskFreeSpaceEx returns error."; 421 LOG(LS_VERBOSE) << "GetDiskFreeSpaceEx returns error.";
421 return false; 422 return false;
422 } 423 }
423 } 424 }
424 425
425 Pathname Win32Filesystem::GetCurrentDirectory() { 426 Pathname Win32Filesystem::GetCurrentDirectory() {
426 Pathname cwd; 427 Pathname cwd;
427 int path_len = 0; 428 int path_len = 0;
428 scoped_ptr<wchar_t[]> path; 429 std::unique_ptr<wchar_t[]> path;
429 do { 430 do {
430 int needed = ::GetCurrentDirectory(path_len, path.get()); 431 int needed = ::GetCurrentDirectory(path_len, path.get());
431 if (needed == 0) { 432 if (needed == 0) {
432 // Error. 433 // Error.
433 LOG_GLE(LS_ERROR) << "::GetCurrentDirectory() failed"; 434 LOG_GLE(LS_ERROR) << "::GetCurrentDirectory() failed";
434 return cwd; // returns empty pathname 435 return cwd; // returns empty pathname
435 } 436 }
436 if (needed <= path_len) { 437 if (needed <= path_len) {
437 // It wrote successfully. 438 // It wrote successfully.
438 break; 439 break;
(...skipping 14 matching lines...) Expand all
453 temp_path16.append(1, '\0'); 454 temp_path16.append(1, '\0');
454 455
455 SHFILEOPSTRUCT file_op = { 0 }; 456 SHFILEOPSTRUCT file_op = { 0 };
456 file_op.wFunc = FO_DELETE; 457 file_op.wFunc = FO_DELETE;
457 file_op.pFrom = temp_path16.c_str(); 458 file_op.pFrom = temp_path16.c_str();
458 file_op.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT; 459 file_op.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
459 return (0 == SHFileOperation(&file_op)); 460 return (0 == SHFileOperation(&file_op));
460 */ 461 */
461 462
462 } // namespace rtc 463 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/virtualsocketserver.cc ('k') | webrtc/base/win32regkey.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698