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 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 buckets_[id] = b; | 817 buckets_[id] = b; |
818 } | 818 } |
819 return b; | 819 return b; |
820 } | 820 } |
821 private: | 821 private: |
822 std::map<BucketIdType, Bucket*> buckets_; | 822 std::map<BucketIdType, Bucket*> buckets_; |
823 }; | 823 }; |
824 | 824 |
825 // Mapper for 'bookmarks.create'. Maps "same input to bookmarks.create" to a | 825 // Mapper for 'bookmarks.create'. Maps "same input to bookmarks.create" to a |
826 // unique bucket. | 826 // unique bucket. |
827 class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> { | 827 class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> { |
not at google - send to devlin
2014/07/23 19:15:22
you can delete this code too, and a bunch of the t
Mike Wittman
2014/07/23 19:42:53
Done.
| |
828 public: | 828 public: |
829 explicit CreateBookmarkBucketMapper(BrowserContext* context) | 829 explicit CreateBookmarkBucketMapper(BrowserContext* context) |
830 : browser_context_(context) {} | 830 : browser_context_(context) {} |
831 // TODO(tim): This should share code with BookmarksCreateFunction::RunOnReady, | 831 // TODO(tim): This should share code with BookmarksCreateFunction::RunOnReady, |
832 // but I can't figure out a good way to do that with all the macros. | 832 // but I can't figure out a good way to do that with all the macros. |
833 virtual void GetBucketsForArgs(const base::ListValue* args, | 833 virtual void GetBucketsForArgs(const base::ListValue* args, |
834 BucketList* buckets) OVERRIDE { | 834 BucketList* buckets) OVERRIDE { |
835 const base::DictionaryValue* json; | 835 const base::DictionaryValue* json; |
836 if (!args->GetDictionary(0, &json)) | 836 if (!args->GetDictionary(0, &json)) |
837 return; | 837 return; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 BucketList* buckets) { | 914 BucketList* buckets) { |
915 IdList ids; | 915 IdList ids; |
916 bool invalid_id = false; | 916 bool invalid_id = false; |
917 if (!FunctionType::ExtractIds(args, &ids, &invalid_id) || invalid_id) | 917 if (!FunctionType::ExtractIds(args, &ids, &invalid_id) || invalid_id) |
918 return; | 918 return; |
919 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) | 919 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) |
920 buckets->push_back(GetBucket(*it)); | 920 buckets->push_back(GetBucket(*it)); |
921 } | 921 } |
922 }; | 922 }; |
923 | 923 |
924 // Builds heuristics for all BookmarkFunctions using specialized BucketMappers. | |
925 class BookmarksQuotaLimitFactory { | |
926 public: | |
927 // For id-based bookmark functions. | |
928 template <class FunctionType> | |
929 static void Build(QuotaLimitHeuristics* heuristics) { | |
930 BuildWithMappers(heuristics, new BookmarkIdMapper<FunctionType>(), | |
931 new BookmarkIdMapper<FunctionType>()); | |
932 } | |
933 | |
934 // For bookmarks.create. | |
935 static void BuildForCreate(QuotaLimitHeuristics* heuristics, | |
936 BrowserContext* context) { | |
937 BuildWithMappers(heuristics, | |
938 new CreateBookmarkBucketMapper(context), | |
939 new CreateBookmarkBucketMapper(context)); | |
940 } | |
941 | |
942 // For bookmarks.remove. | |
943 static void BuildForRemove(QuotaLimitHeuristics* heuristics, | |
944 BrowserContext* context) { | |
945 BuildWithMappers(heuristics, | |
946 new RemoveBookmarksBucketMapper(context), | |
947 new RemoveBookmarksBucketMapper(context)); | |
948 } | |
949 | |
950 private: | |
951 static void BuildWithMappers(QuotaLimitHeuristics* heuristics, | |
952 BucketMapper* short_mapper, BucketMapper* long_mapper) { | |
953 const Config kSustainedLimitConfig = { | |
954 // See bookmarks.json for current value. | |
955 bookmarks::MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE, | |
956 TimeDelta::FromMinutes(1) | |
957 }; | |
958 heuristics->push_back(new SustainedLimit( | |
959 TimeDelta::FromMinutes(10), | |
960 kSustainedLimitConfig, | |
961 short_mapper, | |
962 "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE")); | |
963 | |
964 const Config kTimedLimitConfig = { | |
965 // See bookmarks.json for current value. | |
966 bookmarks::MAX_WRITE_OPERATIONS_PER_HOUR, | |
967 TimeDelta::FromHours(1) | |
968 }; | |
969 heuristics->push_back(new TimedLimit( | |
970 kTimedLimitConfig, | |
971 long_mapper, | |
972 "MAX_WRITE_OPERATIONS_PER_HOUR")); | |
973 } | |
974 | |
975 DISALLOW_IMPLICIT_CONSTRUCTORS(BookmarksQuotaLimitFactory); | |
976 }; | |
977 | |
978 // And finally, building the individual heuristics for each function. | |
979 void BookmarksRemoveFunction::GetQuotaLimitHeuristics( | |
980 QuotaLimitHeuristics* heuristics) const { | |
981 BookmarksQuotaLimitFactory::BuildForRemove(heuristics, GetProfile()); | |
982 } | |
983 | |
984 void BookmarksMoveFunction::GetQuotaLimitHeuristics( | |
985 QuotaLimitHeuristics* heuristics) const { | |
986 BookmarksQuotaLimitFactory::Build<BookmarksMoveFunction>(heuristics); | |
987 } | |
988 | |
989 void BookmarksUpdateFunction::GetQuotaLimitHeuristics( | |
990 QuotaLimitHeuristics* heuristics) const { | |
991 BookmarksQuotaLimitFactory::Build<BookmarksUpdateFunction>(heuristics); | |
992 } | |
993 | |
994 void BookmarksCreateFunction::GetQuotaLimitHeuristics( | |
995 QuotaLimitHeuristics* heuristics) const { | |
996 BookmarksQuotaLimitFactory::BuildForCreate(heuristics, GetProfile()); | |
997 } | |
998 | |
999 BookmarksIOFunction::BookmarksIOFunction() {} | 924 BookmarksIOFunction::BookmarksIOFunction() {} |
1000 | 925 |
1001 BookmarksIOFunction::~BookmarksIOFunction() { | 926 BookmarksIOFunction::~BookmarksIOFunction() { |
1002 // There may be pending file dialogs, we need to tell them that we've gone | 927 // There may be pending file dialogs, we need to tell them that we've gone |
1003 // away so they don't try and call back to us. | 928 // away so they don't try and call back to us. |
1004 if (select_file_dialog_.get()) | 929 if (select_file_dialog_.get()) |
1005 select_file_dialog_->ListenerDestroyed(); | 930 select_file_dialog_->ListenerDestroyed(); |
1006 } | 931 } |
1007 | 932 |
1008 void BookmarksIOFunction::SelectFile(ui::SelectFileDialog::Type type) { | 933 void BookmarksIOFunction::SelectFile(ui::SelectFileDialog::Type type) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 1035 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
1111 int index, | 1036 int index, |
1112 void* params) { | 1037 void* params) { |
1113 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 1038 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
1114 // Android. | 1039 // Android. |
1115 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 1040 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
1116 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 1041 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
1117 } | 1042 } |
1118 | 1043 |
1119 } // namespace extensions | 1044 } // namespace extensions |
OLD | NEW |