| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" | 7 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 json->GetString(keys::kTitleKey, &title); | 854 json->GetString(keys::kTitleKey, &title); |
| 855 std::string url_string; | 855 std::string url_string; |
| 856 json->GetString(keys::kUrlKey, &url_string); | 856 json->GetString(keys::kUrlKey, &url_string); |
| 857 | 857 |
| 858 bucket_id += title; | 858 bucket_id += title; |
| 859 bucket_id += url_string; | 859 bucket_id += url_string; |
| 860 // 20 bytes (SHA1 hash length) is very likely less than most of the | 860 // 20 bytes (SHA1 hash length) is very likely less than most of the |
| 861 // |bucket_id| strings we construct here, so we hash it to save space. | 861 // |bucket_id| strings we construct here, so we hash it to save space. |
| 862 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id))); | 862 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id))); |
| 863 } | 863 } |
| 864 |
| 864 private: | 865 private: |
| 865 BrowserContext* browser_context_; | 866 BrowserContext* browser_context_; |
| 866 }; | 867 }; |
| 867 | 868 |
| 868 // Mapper for 'bookmarks.remove'. | 869 // Mapper for 'bookmarks.remove'. |
| 869 class RemoveBookmarksBucketMapper : public BookmarkBucketMapper<std::string> { | 870 class RemoveBookmarksBucketMapper : public BookmarkBucketMapper<std::string> { |
| 870 public: | 871 public: |
| 871 explicit RemoveBookmarksBucketMapper(BrowserContext* context) | 872 explicit RemoveBookmarksBucketMapper(BrowserContext* context) |
| 872 : browser_context_(context) {} | 873 : browser_context_(context) {} |
| 873 virtual void GetBucketsForArgs(const base::ListValue* args, | 874 virtual void GetBucketsForArgs(const base::ListValue* args, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 887 if (!node || node->is_root()) | 888 if (!node || node->is_root()) |
| 888 return; | 889 return; |
| 889 | 890 |
| 890 std::string bucket_id; | 891 std::string bucket_id; |
| 891 bucket_id += base::UTF16ToUTF8(node->parent()->GetTitle()); | 892 bucket_id += base::UTF16ToUTF8(node->parent()->GetTitle()); |
| 892 bucket_id += base::UTF16ToUTF8(node->GetTitle()); | 893 bucket_id += base::UTF16ToUTF8(node->GetTitle()); |
| 893 bucket_id += node->url().spec(); | 894 bucket_id += node->url().spec(); |
| 894 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id))); | 895 buckets->push_back(GetBucket(base::SHA1HashString(bucket_id))); |
| 895 } | 896 } |
| 896 } | 897 } |
| 898 |
| 897 private: | 899 private: |
| 898 BrowserContext* browser_context_; | 900 BrowserContext* browser_context_; |
| 899 }; | 901 }; |
| 900 | 902 |
| 901 // Mapper for any bookmark function accepting bookmark IDs as parameters, where | 903 // Mapper for any bookmark function accepting bookmark IDs as parameters, where |
| 902 // a distinct ID corresponds to a single item in terms of quota limiting. This | 904 // a distinct ID corresponds to a single item in terms of quota limiting. This |
| 903 // is inappropriate for bookmarks.remove, for example, since repeated removals | 905 // is inappropriate for bookmarks.remove, for example, since repeated removals |
| 904 // of the same item will actually have a different ID each time. | 906 // of the same item will actually have a different ID each time. |
| 905 template <class FunctionType> | 907 template <class FunctionType> |
| 906 class BookmarkIdMapper : public BookmarkBucketMapper<int64> { | 908 class BookmarkIdMapper : public BookmarkBucketMapper<int64> { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 bool BookmarksImportFunction::RunOnReady() { | 1078 bool BookmarksImportFunction::RunOnReady() { |
| 1077 if (!EditBookmarksEnabled()) | 1079 if (!EditBookmarksEnabled()) |
| 1078 return false; | 1080 return false; |
| 1079 SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); | 1081 SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); |
| 1080 return true; | 1082 return true; |
| 1081 } | 1083 } |
| 1082 | 1084 |
| 1083 void BookmarksImportFunction::FileSelected(const base::FilePath& path, | 1085 void BookmarksImportFunction::FileSelected(const base::FilePath& path, |
| 1084 int index, | 1086 int index, |
| 1085 void* params) { | 1087 void* params) { |
| 1086 #if !defined(OS_ANDROID) | |
| 1087 // Android does not have support for the standard importers. | |
| 1088 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | |
| 1089 // Android. | |
| 1090 // Deletes itself. | 1088 // Deletes itself. |
| 1091 ExternalProcessImporterHost* importer_host = new ExternalProcessImporterHost; | 1089 ExternalProcessImporterHost* importer_host = new ExternalProcessImporterHost; |
| 1092 importer::SourceProfile source_profile; | 1090 importer::SourceProfile source_profile; |
| 1093 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | 1091 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
| 1094 source_profile.source_path = path; | 1092 source_profile.source_path = path; |
| 1095 importer_host->StartImportSettings(source_profile, | 1093 importer_host->StartImportSettings(source_profile, |
| 1096 GetProfile(), | 1094 GetProfile(), |
| 1097 importer::FAVORITES, | 1095 importer::FAVORITES, |
| 1098 new ProfileWriter(GetProfile())); | 1096 new ProfileWriter(GetProfile())); |
| 1099 | 1097 |
| 1100 importer::LogImporterUseToMetrics("BookmarksAPI", | 1098 importer::LogImporterUseToMetrics("BookmarksAPI", |
| 1101 importer::TYPE_BOOKMARKS_FILE); | 1099 importer::TYPE_BOOKMARKS_FILE); |
| 1102 #endif | |
| 1103 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 1100 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 1104 } | 1101 } |
| 1105 | 1102 |
| 1106 bool BookmarksExportFunction::RunOnReady() { | 1103 bool BookmarksExportFunction::RunOnReady() { |
| 1107 SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); | 1104 SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); |
| 1108 return true; | 1105 return true; |
| 1109 } | 1106 } |
| 1110 | 1107 |
| 1111 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 1108 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
| 1112 int index, | 1109 int index, |
| 1113 void* params) { | 1110 void* params) { |
| 1114 #if !defined(OS_ANDROID) | |
| 1115 // Android does not have support for the standard exporter. | |
| 1116 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 1111 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
| 1117 // Android. | 1112 // Android. |
| 1118 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 1113 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
| 1119 #endif | |
| 1120 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 1114 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 1121 } | 1115 } |
| 1122 | 1116 |
| 1123 } // namespace extensions | 1117 } // namespace extensions |
| OLD | NEW |