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

Side by Side Diff: chrome/browser/importer/firefox_importer_utils_win.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
« no previous file with comments | « chrome/browser/history/history_publisher_win.cc ('k') | chrome/browser/importer/ie_importer.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 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/importer/firefox_importer_utils.h" 5 #include "chrome/browser/importer/firefox_importer_utils.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/registry.h" 10 #include "base/win/registry.h"
11 11
12 // NOTE: Keep these in order since we need test all those paths according 12 // NOTE: Keep these in order since we need test all those paths according
13 // to priority. For example. One machine has multiple users. One non-admin 13 // to priority. For example. One machine has multiple users. One non-admin
14 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU. 14 // user installs Firefox 2, which causes there is a Firefox2 entry under HKCU.
15 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry 15 // One admin user installs Firefox 3, which causes there is a Firefox 3 entry
16 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2 16 // under HKLM. So when the non-admin user log in, we should deal with Firefox 2
17 // related data instead of Firefox 3. 17 // related data instead of Firefox 3.
18 static const HKEY kFireFoxRegistryPaths[] = { 18 static const HKEY kFireFoxRegistryPaths[] = {
19 HKEY_CURRENT_USER, 19 HKEY_CURRENT_USER,
20 HKEY_LOCAL_MACHINE 20 HKEY_LOCAL_MACHINE
21 }; 21 };
22 22
23 int GetCurrentFirefoxMajorVersionFromRegistry() { 23 int GetCurrentFirefoxMajorVersionFromRegistry() {
24 TCHAR ver_buffer[128]; 24 TCHAR ver_buffer[128];
25 DWORD ver_buffer_length = sizeof(ver_buffer); 25 DWORD ver_buffer_length = sizeof(ver_buffer);
26 int highest_version = 0; 26 int highest_version = 0;
27 // When installing Firefox with admin account, the product keys will be 27 // When installing Firefox with admin account, the product keys will be
28 // written under HKLM\Mozilla. Otherwise it the keys will be written under 28 // written under HKLM\Mozilla. Otherwise it the keys will be written under
29 // HKCU\Mozilla. 29 // HKCU\Mozilla.
30 for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { 30 for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) {
31 RegKey reg_key(kFireFoxRegistryPaths[i], 31 base::win::RegKey reg_key(kFireFoxRegistryPaths[i],
32 L"Software\\Mozilla\\Mozilla Firefox", KEY_READ); 32 L"Software\\Mozilla\\Mozilla Firefox", KEY_READ);
33 33
34 bool result = reg_key.ReadValue(L"CurrentVersion", ver_buffer, 34 bool result = reg_key.ReadValue(L"CurrentVersion", ver_buffer,
35 &ver_buffer_length, NULL); 35 &ver_buffer_length, NULL);
36 if (!result) 36 if (!result)
37 continue; 37 continue;
38 highest_version = std::max(highest_version, _wtoi(ver_buffer)); 38 highest_version = std::max(highest_version, _wtoi(ver_buffer));
39 } 39 }
40 return highest_version; 40 return highest_version;
41 } 41 }
42 42
43 std::wstring GetFirefoxInstallPathFromRegistry() { 43 std::wstring GetFirefoxInstallPathFromRegistry() {
44 // Detects the path that Firefox is installed in. 44 // Detects the path that Firefox is installed in.
45 std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; 45 std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox";
46 wchar_t buffer[MAX_PATH]; 46 wchar_t buffer[MAX_PATH];
47 DWORD buffer_length = sizeof(buffer); 47 DWORD buffer_length = sizeof(buffer);
48 RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(), KEY_READ); 48 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(),
49 KEY_READ);
49 bool result = reg_key.ReadValue(L"CurrentVersion", buffer, 50 bool result = reg_key.ReadValue(L"CurrentVersion", buffer,
50 &buffer_length, NULL); 51 &buffer_length, NULL);
51 if (!result) 52 if (!result)
52 return std::wstring(); 53 return std::wstring();
53 registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; 54 registry_path += L"\\" + std::wstring(buffer) + L"\\Main";
54 buffer_length = sizeof(buffer); 55 buffer_length = sizeof(buffer);
55 RegKey reg_key_directory(HKEY_LOCAL_MACHINE, registry_path.c_str(), KEY_READ); 56 base::win::RegKey reg_key_directory(HKEY_LOCAL_MACHINE,
57 registry_path.c_str(), KEY_READ);
56 result = reg_key_directory.ReadValue(L"Install Directory", buffer, 58 result = reg_key_directory.ReadValue(L"Install Directory", buffer,
57 &buffer_length, NULL); 59 &buffer_length, NULL);
58 if (!result) 60 if (!result)
59 return std::wstring(); 61 return std::wstring();
60 return buffer; 62 return buffer;
61 } 63 }
62 64
63 FilePath GetProfilesINI() { 65 FilePath GetProfilesINI() {
64 FilePath ini_file; 66 FilePath ini_file;
65 // The default location of the profile folder containing user data is 67 // The default location of the profile folder containing user data is
66 // under the "Application Data" folder in Windows XP. 68 // under the "Application Data" folder in Windows XP.
67 wchar_t buffer[MAX_PATH] = {0}; 69 wchar_t buffer[MAX_PATH] = {0};
68 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 70 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL,
69 SHGFP_TYPE_CURRENT, buffer))) { 71 SHGFP_TYPE_CURRENT, buffer))) {
70 ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini"); 72 ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini");
71 } 73 }
72 if (file_util::PathExists(ini_file)) 74 if (file_util::PathExists(ini_file))
73 return ini_file; 75 return ini_file;
74 76
75 return FilePath(); 77 return FilePath();
76 } 78 }
OLDNEW
« no previous file with comments | « chrome/browser/history/history_publisher_win.cc ('k') | chrome/browser/importer/ie_importer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698