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

Side by Side Diff: chrome/browser/importer/firefox_importer_utils.cc

Issue 115133: Add import settings dialog on linux. (Closed)
Patch Set: fix mac build again Created 11 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <algorithm> 7 #include <algorithm>
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <shlobj.h> 10 #include <shlobj.h>
11 11
12 #include "app/win_util.h" 12 #include "app/win_util.h"
13 #include "base/registry.h" 13 #include "base/registry.h"
14 #endif 14 #endif
15 #include "base/file_util.h"
16 #include "base/logging.h" 15 #include "base/logging.h"
17 #include "base/string_util.h" 16 #include "base/string_util.h"
18 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
19 #include "chrome/browser/search_engines/template_url.h" 18 #include "chrome/browser/search_engines/template_url.h"
20 #include "chrome/browser/search_engines/template_url_model.h" 19 #include "chrome/browser/search_engines/template_url_model.h"
21 #include "chrome/browser/search_engines/template_url_parser.h" 20 #include "chrome/browser/search_engines/template_url_parser.h"
22 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
23 #include "net/base/base64.h" 22 #include "net/base/base64.h"
24 23
25 24
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 highest_version = std::max(highest_version, _wtoi(ver_buffer)); 100 highest_version = std::max(highest_version, _wtoi(ver_buffer));
102 } 101 }
103 return highest_version; 102 return highest_version;
104 #else 103 #else
105 // TODO(port): Read in firefox configuration. 104 // TODO(port): Read in firefox configuration.
106 NOTIMPLEMENTED(); 105 NOTIMPLEMENTED();
107 return 0; 106 return 0;
108 #endif 107 #endif
109 } 108 }
110 109
110 #if defined(OS_WIN) || defined(OS_LINUX)
111 bool GetFirefoxVersionAndPathFromProfile(const std::wstring& profile_path,
112 int* version,
113 std::wstring* app_path) {
114 bool ret = false;
115 std::wstring compatibility_file(profile_path);
116 file_util::AppendToPath(&compatibility_file, L"compatibility.ini");
117 std::string content;
118 file_util::ReadFileToString(compatibility_file, &content);
119 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
120 std::vector<std::string> lines;
121 SplitString(content, '\n', &lines);
122
123 for (size_t i = 0; i < lines.size(); ++i) {
124 const std::string& line = lines[i];
125 if (line.empty() || line[0] == '#' || line[0] == ';')
126 continue;
127 size_t equal = line.find('=');
128 if (equal != std::string::npos) {
129 std::string key = line.substr(0, equal);
130 if (key == "LastVersion") {
131 *version = line.substr(equal + 1)[0] - '0';
132 ret = true;
133 } else if (key == "LastAppDir") {
134 *app_path = UTF8ToWide(line.substr(equal + 1));
135 }
136 }
137 }
138 return ret;
139 }
140
141
142 FilePath GetProfilesINI() {
143 FilePath ini_file;
111 #if defined(OS_WIN) 144 #if defined(OS_WIN)
112 std::wstring GetProfilesINI() {
113 // The default location of the profile folder containing user data is 145 // The default location of the profile folder containing user data is
114 // under the "Application Data" folder in Windows XP. 146 // under the "Application Data" folder in Windows XP.
115 std::wstring ini_file;
116 wchar_t buffer[MAX_PATH] = {0}; 147 wchar_t buffer[MAX_PATH] = {0};
117 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 148 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL,
118 SHGFP_TYPE_CURRENT, buffer))) { 149 SHGFP_TYPE_CURRENT, buffer))) {
119 ini_file = buffer; 150 ini_file = FilePath(buffer).Append(L"Mozilla\\Firefox\\profiles.ini");
120 file_util::AppendToPath(&ini_file, L"Mozilla\\Firefox\\profiles.ini");
121 } 151 }
122 if (!file_util::PathExists(ini_file))
123 ini_file.clear();
124 152
125 return ini_file; 153 #else
154 // The default location of the profile folder containing user data is
155 // under user HOME directory in .mozilla/firefox folder on Linux.
156 const char *home = getenv("HOME");
157 if (home && home[0]) {
158 ini_file = FilePath(home).Append(".mozilla/firefox/profiles.ini");
159 }
160 #endif
161 if (file_util::PathExists(ini_file))
162 return ini_file;
163
164 return FilePath();
126 } 165 }
127 166
128 void ParseProfileINI(std::wstring file, DictionaryValue* root) { 167 void ParseProfileINI(std::wstring file, DictionaryValue* root) {
129 // Reads the whole INI file. 168 // Reads the whole INI file.
130 std::string content; 169 std::string content;
131 file_util::ReadFileToString(file, &content); 170 file_util::ReadFileToString(file, &content);
132 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n"); 171 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
133 std::vector<std::string> lines; 172 std::vector<std::string> lines;
134 SplitString(content, '\n', &lines); 173 SplitString(content, '\n', &lines);
135 174
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 805 }
767 // Version 3 has an extra line for further use. 806 // Version 3 has an extra line for further use.
768 if (version == 3) { 807 if (version == 3) {
769 ++begin; 808 ++begin;
770 } 809 }
771 810
772 forms->push_back(form); 811 forms->push_back(form);
773 } 812 }
774 } 813 }
775 } 814 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698