OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/utility/importer/bookmark_html_reader.h" | 5 #include "chrome/utility/importer/bookmark_html_reader.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/icu_string_conversions.h" | 9 #include "base/i18n/icu_string_conversions.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 } // namespace | 85 } // namespace |
86 | 86 |
87 namespace bookmark_html_reader { | 87 namespace bookmark_html_reader { |
88 | 88 |
89 void ImportBookmarksFile( | 89 void ImportBookmarksFile( |
90 const base::Callback<bool(void)>& cancellation_callback, | 90 const base::Callback<bool(void)>& cancellation_callback, |
91 const base::Callback<bool(const GURL&)>& valid_url_callback, | 91 const base::Callback<bool(const GURL&)>& valid_url_callback, |
92 const base::FilePath& file_path, | 92 const base::FilePath& file_path, |
93 std::vector<ImportedBookmarkEntry>* bookmarks, | 93 std::vector<ImportedBookmarkEntry>* bookmarks, |
94 std::vector<ImportedFaviconUsage>* favicons) { | 94 std::vector<ImportedFaviconUsage>* favicons) { |
95 const std::string kHrTag = "<HR>"; | |
gab
2013/08/09 13:27:30
All string constants should be of the form:
stat
| |
95 std::string content; | 96 std::string content; |
96 file_util::ReadFileToString(file_path, &content); | 97 file_util::ReadFileToString(file_path, &content); |
97 std::vector<std::string> lines; | 98 std::vector<std::string> lines; |
98 base::SplitString(content, '\n', &lines); | 99 base::SplitString(content, '\n', &lines); |
99 | 100 |
100 base::string16 last_folder; | 101 base::string16 last_folder; |
101 bool last_folder_on_toolbar = false; | 102 bool last_folder_on_toolbar = false; |
102 bool last_folder_is_empty = true; | 103 bool last_folder_is_empty = true; |
103 bool has_subfolder = false; | 104 bool has_subfolder = false; |
104 base::Time last_folder_add_date; | 105 base::Time last_folder_add_date; |
105 std::vector<base::string16> path; | 106 std::vector<base::string16> path; |
106 size_t toolbar_folder_index = 0; | 107 size_t toolbar_folder_index = 0; |
107 std::string charset; | 108 std::string charset; |
108 for (size_t i = 0; | 109 for (size_t i = 0; |
109 i < lines.size() && | 110 i < lines.size() && |
110 (cancellation_callback.is_null() || !cancellation_callback.Run()); | 111 (cancellation_callback.is_null() || !cancellation_callback.Run()); |
111 ++i) { | 112 ++i) { |
112 std::string line; | 113 std::string line; |
113 TrimString(lines[i], " ", &line); | 114 TrimString(lines[i], " ", &line); |
114 | 115 |
116 // Remove "<HR>" if |line| starts with it. See http://crbug.com/257474. | |
117 if (StartsWithASCII(line, kHrTag, false)) | |
118 TrimString(line.substr(kHrTag.size()), " ", &line); | |
gab
2013/08/09 13:27:30
use "arraysize(kHrTag)" here instead of kHrTag.siz
gab
2013/08/09 13:27:30
This line is slightly tricky and it creates a new
zhchbin
2013/08/09 14:20:00
Can you accept
line.erase(0, arraysize(kHrTag) -
gab
2013/08/09 14:29:03
Ah, right, yes, because the actual arraysize inclu
| |
119 | |
115 // Get the encoding of the bookmark file. | 120 // Get the encoding of the bookmark file. |
116 if (internal::ParseCharsetFromLine(line, &charset)) | 121 if (internal::ParseCharsetFromLine(line, &charset)) |
117 continue; | 122 continue; |
118 | 123 |
119 // Get the folder name. | 124 // Get the folder name. |
120 if (internal::ParseFolderNameFromLine(line, | 125 if (internal::ParseFolderNameFromLine(line, |
121 charset, | 126 charset, |
122 &last_folder, | 127 &last_folder, |
123 &last_folder_on_toolbar, | 128 &last_folder_on_toolbar, |
124 &last_folder_add_date)) { | 129 &last_folder_add_date)) { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 *url = GURL(value); | 428 *url = GURL(value); |
424 } | 429 } |
425 } | 430 } |
426 | 431 |
427 return true; | 432 return true; |
428 } | 433 } |
429 | 434 |
430 } // namespace internal | 435 } // namespace internal |
431 | 436 |
432 } // namespace bookmark_html_reader | 437 } // namespace bookmark_html_reader |
OLD | NEW |