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

Unified Diff: chrome/browser/importer/firefox_importer_utils.cc

Issue 10830098: Get the Firefox branding name dynamically (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/importer/firefox_importer_utils.cc
===================================================================
--- chrome/browser/importer/firefox_importer_utils.cc (revision 148898)
+++ chrome/browser/importer/firefox_importer_utils.cc (working copy)
@@ -417,3 +417,37 @@
return content.substr(start, stop - start);
}
+
+std::string GetFirefoxBrandingName(const FilePath& app_path) {
+ const FilePath app_ini_file = app_path.Append("application.ini");
+ if (file_util::PathExists(app_ini_file)) {
Ilya Sherman 2012/08/03 23:12:29 nit: To reduce nesting, prefer writing code like t
cristian.patrasciuc 2012/08/07 15:46:49 Now, if the file does not exist we don't just retu
+ std::string content;
+ file_util::ReadFileToString(app_ini_file, &content);
+ ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
+ std::vector<std::string> lines;
+ base::SplitString(content, '\n', &lines);
+ bool in_app_section = false;
+ const std::string name_attr("Name=");
Ilya Sherman 2012/08/03 23:12:29 nit: This looks like it should be a file-level con
cristian.patrasciuc 2012/08/06 15:12:39 It is only used here. Should I really make it a fi
Ilya Sherman 2012/08/06 21:07:37 It's fine either way. Typically, we prefer to hav
cristian.patrasciuc 2012/08/07 15:46:49 Done.
+ for (unsigned int i = 0; i < lines.size(); ++i) {
Ilya Sherman 2012/08/03 23:12:29 nit: For Chromium code, prefer |size_t| to |unsign
cristian.patrasciuc 2012/08/07 15:46:49 Done.
+ TrimWhitespace(lines[i], TRIM_ALL, &lines[i]);
+ if (in_app_section) {
+ if (lines[i].find(name_attr) == 0) {
+ return lines[i].substr(name_attr.size());
+ } else if (lines[i][0] == '[') {
Ilya Sherman 2012/08/06 21:07:37 You should check whether lines[i] is empty prior t
cristian.patrasciuc 2012/08/07 15:46:49 Done.
+ break;
+ }
Ilya Sherman 2012/08/03 23:12:29 nit: Since the if- and else-statements have one-li
cristian.patrasciuc 2012/08/06 15:12:39 I added the curly braces because otherwise the com
Ilya Sherman 2012/08/06 21:07:37 The else is not ambiguous if the outer if-stmt has
cristian.patrasciuc 2012/08/07 15:46:49 Done.
+ } else if (lines[i] == "[App]") {
+ in_app_section = true;
Ilya Sherman 2012/08/03 23:12:29 Are there any other sections for which "Name=" can
cristian.patrasciuc 2012/08/06 15:12:39 When you are in the [App] section and another sect
Ilya Sherman 2012/08/06 21:07:37 Ah, you're right. Apologies for missing that.
+ }
+ }
+ LOG_IF(WARNING, in_app_section) << "There is no line starting with "
+ << name_attr << " in the [App] section of "
+ << app_ini_file.value();
+ LOG_IF(WARNING, !in_app_section) << app_ini_file.value()
+ << " has no [App] section";
Ilya Sherman 2012/08/03 23:12:29 nit: Ditto to the comment below for these logging
cristian.patrasciuc 2012/08/07 15:46:49 Done.
+ } else {
+ LOG(WARNING) << "Could not detect Firefox branding name since "
+ << app_ini_file.value() << " does not exist.";
Ilya Sherman 2012/08/03 23:12:29 nit: No need to log a warning in this case. Log s
cristian.patrasciuc 2012/08/07 15:46:49 Done.
+ }
+ return std::string();
+}

Powered by Google App Engine
This is Rietveld 408576698