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

Side by Side 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, 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 410 }
411 411
412 // String values have double quotes we don't need to return to the caller. 412 // String values have double quotes we don't need to return to the caller.
413 if (content[start] == '\"' && content[stop - 1] == '\"') { 413 if (content[start] == '\"' && content[stop - 1] == '\"') {
414 ++start; 414 ++start;
415 --stop; 415 --stop;
416 } 416 }
417 417
418 return content.substr(start, stop - start); 418 return content.substr(start, stop - start);
419 } 419 }
420
421 std::string GetFirefoxBrandingName(const FilePath& app_path) {
422 const FilePath app_ini_file = app_path.Append("application.ini");
423 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
424 std::string content;
425 file_util::ReadFileToString(app_ini_file, &content);
426 ReplaceSubstringsAfterOffset(&content, 0, "\r\n", "\n");
427 std::vector<std::string> lines;
428 base::SplitString(content, '\n', &lines);
429 bool in_app_section = false;
430 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.
431 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.
432 TrimWhitespace(lines[i], TRIM_ALL, &lines[i]);
433 if (in_app_section) {
434 if (lines[i].find(name_attr) == 0) {
435 return lines[i].substr(name_attr.size());
436 } 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.
437 break;
438 }
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.
439 } else if (lines[i] == "[App]") {
440 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.
441 }
442 }
443 LOG_IF(WARNING, in_app_section) << "There is no line starting with "
444 << name_attr << " in the [App] section of "
445 << app_ini_file.value();
446 LOG_IF(WARNING, !in_app_section) << app_ini_file.value()
447 << " 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.
448 } else {
449 LOG(WARNING) << "Could not detect Firefox branding name since "
450 << 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.
451 }
452 return std::string();
453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698