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

Side by Side Diff: chrome/installer/util/delete_after_reboot_helper.cc

Issue 3836005: Move pe_image and registry from base to base/win and use the namespace. It re... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // This file defines helper methods used to schedule files for deletion 5 // This file defines helper methods used to schedule files for deletion
6 // on next reboot. The code here is heavily borrowed and simplified from 6 // on next reboot. The code here is heavily borrowed and simplified from
7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and 7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and
8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc 8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc
9 // 9 //
10 // This implementation really is not fast, so do not use it where that will 10 // This implementation really is not fast, so do not use it where that will
11 // matter. 11 // matter.
12 12
13 #include "chrome/installer/util/delete_after_reboot_helper.h" 13 #include "chrome/installer/util/delete_after_reboot_helper.h"
14 14
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/file_util.h" 18 #include "base/file_util.h"
19 #include "base/registry.h" 19 #include "base/win/registry.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 21
22 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the 22 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the
23 // registry. 23 // registry.
24 const wchar_t kSessionManagerKey[] = 24 const wchar_t kSessionManagerKey[] =
25 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; 25 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager";
26 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations"; 26 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations";
27 27
28 namespace { 28 namespace {
29 29
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return short_path; 238 return short_path;
239 } 239 }
240 240
241 HRESULT GetPendingMovesValue( 241 HRESULT GetPendingMovesValue(
242 std::vector<PendingMove>* pending_moves) { 242 std::vector<PendingMove>* pending_moves) {
243 DCHECK(pending_moves); 243 DCHECK(pending_moves);
244 pending_moves->clear(); 244 pending_moves->clear();
245 245
246 // Get the current value of the key 246 // Get the current value of the key
247 // If the Key is missing, that's totally acceptable. 247 // If the Key is missing, that's totally acceptable.
248 RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey, 248 base::win::RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey,
249 KEY_QUERY_VALUE); 249 KEY_QUERY_VALUE);
250 HKEY session_manager_handle = session_manager_key.Handle(); 250 HKEY session_manager_handle = session_manager_key.Handle();
251 if (!session_manager_handle) { 251 if (!session_manager_handle) {
252 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); 252 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
253 } 253 }
254 254
255 // The base::RegKey Read code squashes the return code from 255 // The base::RegKey Read code squashes the return code from
256 // ReqQueryValueEx, we have to do things ourselves: 256 // ReqQueryValueEx, we have to do things ourselves:
257 DWORD buffer_size = 0; 257 DWORD buffer_size = 0;
258 std::vector<char> buffer; 258 std::vector<char> buffer;
259 buffer.resize(1); 259 buffer.resize(1);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 strings_to_keep.push_back(*iter); 344 strings_to_keep.push_back(*iter);
345 } 345 }
346 } 346 }
347 347
348 if (strings_to_keep.size() == pending_moves.size()) { 348 if (strings_to_keep.size() == pending_moves.size()) {
349 // Nothing to remove, return true. 349 // Nothing to remove, return true.
350 return true; 350 return true;
351 } 351 }
352 352
353 // Write the key back into a buffer. 353 // Write the key back into a buffer.
354 RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey, 354 base::win::RegKey session_manager_key(HKEY_LOCAL_MACHINE, kSessionManagerKey,
355 KEY_CREATE_SUB_KEY | KEY_SET_VALUE); 355 KEY_CREATE_SUB_KEY | KEY_SET_VALUE);
356 if (!session_manager_key.Handle()) { 356 if (!session_manager_key.Handle()) {
357 // Couldn't open / create the key. 357 // Couldn't open / create the key.
358 LOG(ERROR) << "Failed to open session manager key for writing."; 358 LOG(ERROR) << "Failed to open session manager key for writing.";
359 return false; 359 return false;
360 } 360 }
361 361
362 if (strings_to_keep.size() > 1) { 362 if (strings_to_keep.size() > 1) {
363 std::vector<char> buffer; 363 std::vector<char> buffer;
364 StringArrayToMultiSZBytes(strings_to_keep, &buffer); 364 StringArrayToMultiSZBytes(strings_to_keep, &buffer);
365 DCHECK(buffer.size() > 0); 365 DCHECK(buffer.size() > 0);
366 if (buffer.size() > 0) { 366 if (buffer.size() > 0) {
367 return session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], 367 return session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0],
368 buffer.size(), REG_MULTI_SZ); 368 buffer.size(), REG_MULTI_SZ);
369 } else { 369 } else {
370 return false; 370 return false;
371 } 371 }
372 } else { 372 } else {
373 // We have only the trailing NULL string. Don't bother writing that. 373 // We have only the trailing NULL string. Don't bother writing that.
374 return session_manager_key.DeleteValue(kPendingFileRenameOps); 374 return session_manager_key.DeleteValue(kPendingFileRenameOps);
375 } 375 }
376 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698