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

Side by Side Diff: cloud_print/virtual_driver/win/install/setup.cc

Issue 7532031: Changes to write various registry keys as required by Omaha for Windows Cloud Print Virtual Driver. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Changes as per code review. Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 <windows.h> 5 #include <windows.h>
6 #include <winspool.h> 6 #include <winspool.h>
7 7
8 #include "base/at_exit.h" 8 #include "base/at_exit.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/file_version_info_win.h" 11 #include "base/file_version_info_win.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/process_util.h" 14 #include "base/process_util.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/win/registry.h"
16 #include "base/win/scoped_handle.h" 17 #include "base/win/scoped_handle.h"
17 #include "cloud_print/virtual_driver/win/virtual_driver_consts.h" 18 #include "cloud_print/virtual_driver/win/virtual_driver_consts.h"
18 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" 19 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
19 #include "grit/virtual_driver_setup_resources.h" 20 #include "grit/virtual_driver_setup_resources.h"
20 21
21 namespace { 22 namespace {
23 const wchar_t* kVersionKey = L"pv";
sanjeevr 2011/08/03 11:19:29 It is the norm in Chrome to use const wchar_t[] in
abeera 2011/08/03 19:50:30 Done.
24 const wchar_t* kNameKey = L"name";
25 const wchar_t* kLangKey = L"lang";
26
27 void SetRegistryKeys() {
28 base::win::RegKey key;
29 if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation,
30 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
sanjeevr 2011/08/03 11:19:29 You don't need KEY_ALL_ACCESS here. You just need
abeera 2011/08/03 19:50:30 Done.
31 LOG(ERROR) << "Unable to open key";
32 }
33
34 // Get the version from the resource file.
35 std::wstring version_string;
36 scoped_ptr<FileVersionInfo> version_info(
37 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
38
39 if (version_info.get()) {
40 FileVersionInfoWin* version_info_win =
41 static_cast<FileVersionInfoWin*>(version_info.get());
42 version_string = version_info_win->product_version();
43 } else {
44 LOG(ERROR) << "Unable to get version string";
45 // Use a random version string so that Omaha has something to go by.
46 version_string = L"0.0.0.99";
47 }
48
49 if (key.WriteValue(kVersionKey, version_string.c_str()) != ERROR_SUCCESS ||
50 key.WriteValue(kNameKey, L"GCP Virtual Driver") != ERROR_SUCCESS ||
sanjeevr 2011/08/03 11:19:29 Why don't you create constant strings for these as
abeera 2011/08/03 19:50:30 Done.
51 key.WriteValue(kLangKey, L"en") != ERROR_SUCCESS) {
52 LOG(ERROR) << "Unable to set registry keys";
53 }
54 }
55
56 void DeleteRegistryKeys() {
57 base::win::RegKey key;
58 if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation,
59 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
sanjeevr 2011/08/03 11:19:29 Again you only need DELETE access. And you don't n
abeera 2011/08/03 19:50:30 Done.
60 LOG(ERROR) << "Unable to open key to delete";
61 }
62 if (key.DeleteKey(L"") != ERROR_SUCCESS) {
63 LOG(ERROR) << "Unable to delete key";
64 }
65 }
22 66
23 HRESULT GetGpdPath(FilePath* path) { 67 HRESULT GetGpdPath(FilePath* path) {
24 if (!PathService::Get(base::DIR_EXE, path)) { 68 if (!PathService::Get(base::DIR_EXE, path)) {
25 LOG(ERROR) << "Unable to get install path."; 69 LOG(ERROR) << "Unable to get install path.";
26 return ERROR_PATH_NOT_FOUND; 70 return ERROR_PATH_NOT_FOUND;
27 } 71 }
28 *path = path->Append(L"gcp.gpd"); 72 *path = path->Append(L"gcp.gpd");
29 return S_OK; 73 return S_OK;
30 } 74 }
31 75
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 result = InstallGpd(); 315 result = InstallGpd();
272 if (!SUCCEEDED(result)) { 316 if (!SUCCEEDED(result)) {
273 LOG(ERROR) << "Unable to install gpd."; 317 LOG(ERROR) << "Unable to install gpd.";
274 return result; 318 return result;
275 } 319 }
276 result = InstallPrinter(); 320 result = InstallPrinter();
277 if (!SUCCEEDED(result)) { 321 if (!SUCCEEDED(result)) {
278 LOG(ERROR) << "Unable to install printer."; 322 LOG(ERROR) << "Unable to install printer.";
279 return result; 323 return result;
280 } 324 }
325 SetRegistryKeys();
281 return S_OK; 326 return S_OK;
282 } 327 }
283 328
284 HRESULT UninstallVirtualDriver(void) { 329 HRESULT UninstallVirtualDriver(void) {
285 HRESULT result = S_OK; 330 HRESULT result = S_OK;
286 result = UninstallPrinter(); 331 result = UninstallPrinter();
287 if (!SUCCEEDED(result)) { 332 if (!SUCCEEDED(result)) {
288 LOG(ERROR) << "Unable to uninstall gpd."; 333 LOG(ERROR) << "Unable to uninstall gpd.";
289 return result; 334 return result;
290 } 335 }
291 result = UninstallGpd(); 336 result = UninstallGpd();
292 if (!SUCCEEDED(result)) { 337 if (!SUCCEEDED(result)) {
293 LOG(ERROR) << "Unable to remove gpd."; 338 LOG(ERROR) << "Unable to remove gpd.";
294 return result; 339 return result;
295 } 340 }
296 result = RegisterPortMonitor(false); 341 result = RegisterPortMonitor(false);
297 if (!SUCCEEDED(result)) { 342 if (!SUCCEEDED(result)) {
298 LOG(ERROR) << "Unable to remove port monitor."; 343 LOG(ERROR) << "Unable to remove port monitor.";
299 return result; 344 return result;
300 } 345 }
346 DeleteRegistryKeys();
301 return S_OK; 347 return S_OK;
302 } 348 }
303 349
304 } // namespace 350 } // namespace
305 351
306 int WINAPI WinMain(__in HINSTANCE hInstance, 352 int WINAPI WinMain(__in HINSTANCE hInstance,
307 __in HINSTANCE hPrevInstance, 353 __in HINSTANCE hPrevInstance,
308 __in LPSTR lpCmdLine, 354 __in LPSTR lpCmdLine,
309 __in int nCmdShow) { 355 __in int nCmdShow) {
310 base::AtExitManager at_exit_manager; 356 base::AtExitManager at_exit_manager;
311 CommandLine::Init(0, NULL); 357 CommandLine::Init(0, NULL);
312 HRESULT retval = S_OK; 358 HRESULT retval = S_OK;
313 if (CommandLine::ForCurrentProcess()->HasSwitch("uninstall")) { 359 if (CommandLine::ForCurrentProcess()->HasSwitch("uninstall")) {
314 retval = UninstallVirtualDriver(); 360 retval = UninstallVirtualDriver();
315 } else { 361 } else {
316 retval = InstallVirtualDriver(); 362 retval = InstallVirtualDriver();
317 } 363 }
318 if (!CommandLine::ForCurrentProcess()->HasSwitch("silent")) { 364 // Installer is silent by default as required by Omaha.
365 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) {
319 cloud_print::DisplayWindowsMessage(NULL, retval, 366 cloud_print::DisplayWindowsMessage(NULL, retval,
320 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); 367 cloud_print::LoadLocalString(IDS_DRIVER_NAME));
321 } 368 }
322 return retval; 369 return retval;
323 } 370 }
324 371
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698