| OLD | NEW |
| 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/firefox3_importer.h" | 5 #include "chrome/browser/importer/firefox3_importer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // Original definition is in http://mxr.mozilla.org/firefox/source/toolkit/ | 35 // Original definition is in http://mxr.mozilla.org/firefox/source/toolkit/ |
| 36 // components/places/public/nsINavBookmarksService.idl | 36 // components/places/public/nsINavBookmarksService.idl |
| 37 enum BookmarkItemType { | 37 enum BookmarkItemType { |
| 38 TYPE_BOOKMARK = 1, | 38 TYPE_BOOKMARK = 1, |
| 39 TYPE_FOLDER = 2, | 39 TYPE_FOLDER = 2, |
| 40 TYPE_SEPARATOR = 3, | 40 TYPE_SEPARATOR = 3, |
| 41 TYPE_DYNAMIC_CONTAINER = 4 | 41 TYPE_DYNAMIC_CONTAINER = 4 |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // Creates a TemplateURL with the |keyword| and |url|. |title| may be empty. |
| 45 // This function transfers ownership of the created TemplateURL to the caller. |
| 46 TemplateURL* CreateTemplateURL(const string16& title, |
| 47 const string16& keyword, |
| 48 const GURL& url) { |
| 49 // Skip if the keyword or url is invalid. |
| 50 if (keyword.empty() || !url.is_valid()) |
| 51 return NULL; |
| 52 |
| 53 TemplateURLData data; |
| 54 // We set short name by using the title if it exists. |
| 55 // Otherwise, we use the shortcut. |
| 56 data.short_name = title.empty() ? keyword : title; |
| 57 data.SetKeyword(keyword); |
| 58 data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec()))); |
| 59 return new TemplateURL(NULL, data); |
| 60 } |
| 61 |
| 44 } // namespace | 62 } // namespace |
| 45 | 63 |
| 46 struct Firefox3Importer::BookmarkItem { | 64 struct Firefox3Importer::BookmarkItem { |
| 47 int parent; | 65 int parent; |
| 48 int id; | 66 int id; |
| 49 GURL url; | 67 GURL url; |
| 50 string16 title; | 68 string16 title; |
| 51 BookmarkItemType type; | 69 BookmarkItemType type; |
| 52 std::string keyword; | 70 std::string keyword; |
| 53 base::Time date_added; | 71 base::Time date_added; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 entry.in_toolbar = is_in_toolbar; | 284 entry.in_toolbar = is_in_toolbar; |
| 267 entry.is_folder = item->type == TYPE_FOLDER; | 285 entry.is_folder = item->type == TYPE_FOLDER; |
| 268 | 286 |
| 269 bookmarks.push_back(entry); | 287 bookmarks.push_back(entry); |
| 270 | 288 |
| 271 if (item->type == TYPE_BOOKMARK) { | 289 if (item->type == TYPE_BOOKMARK) { |
| 272 if (item->favicon) | 290 if (item->favicon) |
| 273 favicon_map[item->favicon].insert(item->url); | 291 favicon_map[item->favicon].insert(item->url); |
| 274 | 292 |
| 275 // This bookmark has a keyword, we import it to our TemplateURL model. | 293 // This bookmark has a keyword, we import it to our TemplateURL model. |
| 276 TemplateURL* t_url = Firefox2Importer::CreateTemplateURL( | 294 TemplateURL* t_url = CreateTemplateURL( |
| 277 item->title, UTF8ToUTF16(item->keyword), item->url); | 295 item->title, UTF8ToUTF16(item->keyword), item->url); |
| 278 if (t_url) | 296 if (t_url) |
| 279 template_urls.push_back(t_url); | 297 template_urls.push_back(t_url); |
| 280 } | 298 } |
| 281 } | 299 } |
| 282 | 300 |
| 283 STLDeleteElements(&list); | 301 STLDeleteElements(&list); |
| 284 | 302 |
| 285 // Write into profile. | 303 // Write into profile. |
| 286 if (!bookmarks.empty() && !cancelled()) { | 304 if (!bookmarks.empty() && !cancelled()) { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 | 580 |
| 563 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 581 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
| 564 continue; // Unable to decode. | 582 continue; // Unable to decode. |
| 565 | 583 |
| 566 usage.urls = i->second; | 584 usage.urls = i->second; |
| 567 favicons->push_back(usage); | 585 favicons->push_back(usage); |
| 568 } | 586 } |
| 569 s.Reset(true); | 587 s.Reset(true); |
| 570 } | 588 } |
| 571 } | 589 } |
| OLD | NEW |