OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // CancelableRequestProviders and Consumers work together to make requests that | 5 // CancelableRequestProviders and Consumers work together to make requests that |
6 // execute on a background thread in the provider and return data to the | 6 // execute on a background thread in the provider and return data to the |
7 // consumer. These classes collaborate to keep a list of open requests and to | 7 // consumer. These classes collaborate to keep a list of open requests and to |
8 // make sure that requests do not outlive either of the objects involved in the | 8 // make sure that requests do not outlive either of the objects involved in the |
9 // transaction. | 9 // transaction. |
10 // | 10 // |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 public CancelableRequestBase { | 769 public CancelableRequestBase { |
770 public: | 770 public: |
771 typedef base::Callback<void(A1)> CallbackType; | 771 typedef base::Callback<void(A1)> CallbackType; |
772 | 772 |
773 explicit CancelableRequest(const CallbackType& callback) | 773 explicit CancelableRequest(const CallbackType& callback) |
774 : CancelableRequestBase(), | 774 : CancelableRequestBase(), |
775 callback_(callback) { | 775 callback_(callback) { |
776 DCHECK(!callback.is_null()) << "Callback must be initialized."; | 776 DCHECK(!callback.is_null()) << "Callback must be initialized."; |
777 } | 777 } |
778 | 778 |
779 void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1) { | 779 void ForwardResult( |
| 780 typename base::internal::CallbackParamTraits<A1>::ForwardType a1) { |
780 if (canceled()) return; | 781 if (canceled()) return; |
781 DoForward(base::Bind(callback_, a1), false); | 782 DoForward(base::Bind(callback_, a1), false); |
782 } | 783 } |
783 | 784 |
784 void ForwardResultAsync( | 785 void ForwardResultAsync( |
785 typename base::internal::ParamTraits<A1>::ForwardType a1) { | 786 typename base::internal::CallbackParamTraits<A1>::ForwardType a1) { |
786 if (canceled()) return; | 787 if (canceled()) return; |
787 DoForward(base::Bind(callback_, a1), true); | 788 DoForward(base::Bind(callback_, a1), true); |
788 } | 789 } |
789 | 790 |
790 protected: | 791 protected: |
791 virtual ~CancelableRequest() {} | 792 virtual ~CancelableRequest() {} |
792 | 793 |
793 private: | 794 private: |
794 CallbackType callback_; | 795 CallbackType callback_; |
795 }; | 796 }; |
796 | 797 |
797 template<typename A1, typename A2> | 798 template<typename A1, typename A2> |
798 class CancelableRequest<base::Callback<void(A1,A2)> > : | 799 class CancelableRequest<base::Callback<void(A1,A2)> > : |
799 public CancelableRequestBase { | 800 public CancelableRequestBase { |
800 public: | 801 public: |
801 typedef base::Callback<void(A1,A2)> CallbackType; | 802 typedef base::Callback<void(A1,A2)> CallbackType; |
802 | 803 |
803 explicit CancelableRequest(const CallbackType& callback) | 804 explicit CancelableRequest(const CallbackType& callback) |
804 : CancelableRequestBase(), | 805 : CancelableRequestBase(), |
805 callback_(callback) { | 806 callback_(callback) { |
806 DCHECK(!callback.is_null()) << "Callback must be initialized."; | 807 DCHECK(!callback.is_null()) << "Callback must be initialized."; |
807 } | 808 } |
808 | 809 |
809 void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1, | 810 void ForwardResult( |
810 typename base::internal::ParamTraits<A2>::ForwardType a2) { | 811 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
| 812 typename base::internal::CallbackParamTraits<A2>::ForwardType a2) { |
811 if (canceled()) return; | 813 if (canceled()) return; |
812 DoForward(base::Bind(callback_, a1, a2), false); | 814 DoForward(base::Bind(callback_, a1, a2), false); |
813 } | 815 } |
814 | 816 |
815 void ForwardResultAsync( | 817 void ForwardResultAsync( |
816 typename base::internal::ParamTraits<A1>::ForwardType a1, | 818 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
817 typename base::internal::ParamTraits<A2>::ForwardType a2) { | 819 typename base::internal::CallbackParamTraits<A2>::ForwardType a2) { |
818 if (canceled()) return; | 820 if (canceled()) return; |
819 DoForward(base::Bind(callback_, a1, a2), true); | 821 DoForward(base::Bind(callback_, a1, a2), true); |
820 } | 822 } |
821 | 823 |
822 protected: | 824 protected: |
823 virtual ~CancelableRequest() {} | 825 virtual ~CancelableRequest() {} |
824 | 826 |
825 private: | 827 private: |
826 CallbackType callback_; | 828 CallbackType callback_; |
827 }; | 829 }; |
828 | 830 |
829 template<typename A1, typename A2, typename A3> | 831 template<typename A1, typename A2, typename A3> |
830 class CancelableRequest<base::Callback<void(A1,A2,A3)> > : | 832 class CancelableRequest<base::Callback<void(A1,A2,A3)> > : |
831 public CancelableRequestBase { | 833 public CancelableRequestBase { |
832 public: | 834 public: |
833 typedef base::Callback<void(A1,A2,A3)> CallbackType; | 835 typedef base::Callback<void(A1,A2,A3)> CallbackType; |
834 | 836 |
835 explicit CancelableRequest(const CallbackType& callback) | 837 explicit CancelableRequest(const CallbackType& callback) |
836 : CancelableRequestBase(), | 838 : CancelableRequestBase(), |
837 callback_(callback) { | 839 callback_(callback) { |
838 DCHECK(!callback.is_null()) << "Callback must be initialized."; | 840 DCHECK(!callback.is_null()) << "Callback must be initialized."; |
839 } | 841 } |
840 | 842 |
841 void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1, | 843 void ForwardResult( |
842 typename base::internal::ParamTraits<A2>::ForwardType a2, | 844 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
843 typename base::internal::ParamTraits<A3>::ForwardType a3) { | 845 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
| 846 typename base::internal::CallbackParamTraits<A3>::ForwardType a3) { |
844 if (canceled()) return; | 847 if (canceled()) return; |
845 DoForward(base::Bind(callback_, a1, a2, a3), false); | 848 DoForward(base::Bind(callback_, a1, a2, a3), false); |
846 } | 849 } |
847 | 850 |
848 void ForwardResultAsync( | 851 void ForwardResultAsync( |
849 typename base::internal::ParamTraits<A1>::ForwardType a1, | 852 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
850 typename base::internal::ParamTraits<A2>::ForwardType a2, | 853 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
851 typename base::internal::ParamTraits<A3>::ForwardType a3) { | 854 typename base::internal::CallbackParamTraits<A3>::ForwardType a3) { |
852 if (canceled()) return; | 855 if (canceled()) return; |
853 DoForward(base::Bind(callback_, a1, a2, a3), true); | 856 DoForward(base::Bind(callback_, a1, a2, a3), true); |
854 } | 857 } |
855 | 858 |
856 protected: | 859 protected: |
857 virtual ~CancelableRequest() {} | 860 virtual ~CancelableRequest() {} |
858 | 861 |
859 private: | 862 private: |
860 CallbackType callback_; | 863 CallbackType callback_; |
861 }; | 864 }; |
862 | 865 |
863 template<typename A1, typename A2, typename A3, typename A4> | 866 template<typename A1, typename A2, typename A3, typename A4> |
864 class CancelableRequest<base::Callback<void(A1, A2, A3, A4)> > : | 867 class CancelableRequest<base::Callback<void(A1, A2, A3, A4)> > : |
865 public CancelableRequestBase { | 868 public CancelableRequestBase { |
866 public: | 869 public: |
867 typedef base::Callback<void(A1, A2, A3, A4)> CallbackType; | 870 typedef base::Callback<void(A1, A2, A3, A4)> CallbackType; |
868 | 871 |
869 explicit CancelableRequest(const CallbackType& callback) | 872 explicit CancelableRequest(const CallbackType& callback) |
870 : CancelableRequestBase(), | 873 : CancelableRequestBase(), |
871 callback_(callback) { | 874 callback_(callback) { |
872 DCHECK(!callback.is_null()) << "Callback must be initialized."; | 875 DCHECK(!callback.is_null()) << "Callback must be initialized."; |
873 } | 876 } |
874 | 877 |
875 void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1, | 878 void ForwardResult( |
876 typename base::internal::ParamTraits<A2>::ForwardType a2, | 879 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
877 typename base::internal::ParamTraits<A3>::ForwardType a3, | 880 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
878 typename base::internal::ParamTraits<A4>::ForwardType a4) { | 881 typename base::internal::CallbackParamTraits<A3>::ForwardType a3, |
| 882 typename base::internal::CallbackParamTraits<A4>::ForwardType a4) { |
879 if (canceled()) return; | 883 if (canceled()) return; |
880 DoForward(base::Bind(callback_, a1, a2, a3, a4), false); | 884 DoForward(base::Bind(callback_, a1, a2, a3, a4), false); |
881 } | 885 } |
882 | 886 |
883 void ForwardResultAsync( | 887 void ForwardResultAsync( |
884 typename base::internal::ParamTraits<A1>::ForwardType a1, | 888 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
885 typename base::internal::ParamTraits<A2>::ForwardType a2, | 889 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
886 typename base::internal::ParamTraits<A3>::ForwardType a3, | 890 typename base::internal::CallbackParamTraits<A3>::ForwardType a3, |
887 typename base::internal::ParamTraits<A4>::ForwardType a4) { | 891 typename base::internal::CallbackParamTraits<A4>::ForwardType a4) { |
888 if (canceled()) return; | 892 if (canceled()) return; |
889 DoForward(base::Bind(callback_, a1, a2, a3, a4), true); | 893 DoForward(base::Bind(callback_, a1, a2, a3, a4), true); |
890 } | 894 } |
891 | 895 |
892 protected: | 896 protected: |
893 virtual ~CancelableRequest() {} | 897 virtual ~CancelableRequest() {} |
894 | 898 |
895 private: | 899 private: |
896 CallbackType callback_; | 900 CallbackType callback_; |
897 }; | 901 }; |
898 | 902 |
899 template<typename A1, typename A2, typename A3, typename A4, typename A5> | 903 template<typename A1, typename A2, typename A3, typename A4, typename A5> |
900 class CancelableRequest<base::Callback<void(A1, A2, A3, A4, A5)> > : | 904 class CancelableRequest<base::Callback<void(A1, A2, A3, A4, A5)> > : |
901 public CancelableRequestBase { | 905 public CancelableRequestBase { |
902 public: | 906 public: |
903 typedef base::Callback<void(A1, A2, A3, A4, A5)> CallbackType; | 907 typedef base::Callback<void(A1, A2, A3, A4, A5)> CallbackType; |
904 | 908 |
905 explicit CancelableRequest(const CallbackType& callback) | 909 explicit CancelableRequest(const CallbackType& callback) |
906 : CancelableRequestBase(), | 910 : CancelableRequestBase(), |
907 callback_(callback) { | 911 callback_(callback) { |
908 DCHECK(!callback.is_null()) << "Callback must be initialized."; | 912 DCHECK(!callback.is_null()) << "Callback must be initialized."; |
909 } | 913 } |
910 | 914 |
911 void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1, | 915 void ForwardResult( |
912 typename base::internal::ParamTraits<A2>::ForwardType a2, | 916 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
913 typename base::internal::ParamTraits<A3>::ForwardType a3, | 917 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
914 typename base::internal::ParamTraits<A4>::ForwardType a4, | 918 typename base::internal::CallbackParamTraits<A3>::ForwardType a3, |
915 typename base::internal::ParamTraits<A5>::ForwardType a5) { | 919 typename base::internal::CallbackParamTraits<A4>::ForwardType a4, |
| 920 typename base::internal::CallbackParamTraits<A5>::ForwardType a5) { |
916 if (canceled()) return; | 921 if (canceled()) return; |
917 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5), false); | 922 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5), false); |
918 } | 923 } |
919 | 924 |
920 void ForwardResultAsync( | 925 void ForwardResultAsync( |
921 typename base::internal::ParamTraits<A1>::ForwardType a1, | 926 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
922 typename base::internal::ParamTraits<A2>::ForwardType a2, | 927 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
923 typename base::internal::ParamTraits<A3>::ForwardType a3, | 928 typename base::internal::CallbackParamTraits<A3>::ForwardType a3, |
924 typename base::internal::ParamTraits<A4>::ForwardType a4, | 929 typename base::internal::CallbackParamTraits<A4>::ForwardType a4, |
925 typename base::internal::ParamTraits<A5>::ForwardType a5) { | 930 typename base::internal::CallbackParamTraits<A5>::ForwardType a5) { |
926 if (canceled()) return; | 931 if (canceled()) return; |
927 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5), true); | 932 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5), true); |
928 } | 933 } |
929 | 934 |
930 protected: | 935 protected: |
931 virtual ~CancelableRequest() {} | 936 virtual ~CancelableRequest() {} |
932 | 937 |
933 private: | 938 private: |
934 CallbackType callback_; | 939 CallbackType callback_; |
935 }; | 940 }; |
936 | 941 |
937 template<typename A1, typename A2, typename A3, typename A4, typename A5, | 942 template<typename A1, typename A2, typename A3, typename A4, typename A5, |
938 typename A6> | 943 typename A6> |
939 class CancelableRequest<base::Callback<void(A1, A2, A3, A4, A5, A6)> > : | 944 class CancelableRequest<base::Callback<void(A1, A2, A3, A4, A5, A6)> > : |
940 public CancelableRequestBase { | 945 public CancelableRequestBase { |
941 public: | 946 public: |
942 typedef base::Callback<void(A1, A2, A3, A4, A5, A6)> CallbackType; | 947 typedef base::Callback<void(A1, A2, A3, A4, A5, A6)> CallbackType; |
943 | 948 |
944 explicit CancelableRequest(const CallbackType& callback) | 949 explicit CancelableRequest(const CallbackType& callback) |
945 : CancelableRequestBase(), | 950 : CancelableRequestBase(), |
946 callback_(callback) { | 951 callback_(callback) { |
947 DCHECK(!callback.is_null()) << "Callback must be initialized."; | 952 DCHECK(!callback.is_null()) << "Callback must be initialized."; |
948 } | 953 } |
949 | 954 |
950 void ForwardResult(typename base::internal::ParamTraits<A1>::ForwardType a1, | 955 void ForwardResult( |
951 typename base::internal::ParamTraits<A2>::ForwardType a2, | 956 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
952 typename base::internal::ParamTraits<A3>::ForwardType a3, | 957 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
953 typename base::internal::ParamTraits<A4>::ForwardType a4, | 958 typename base::internal::CallbackParamTraits<A3>::ForwardType a3, |
954 typename base::internal::ParamTraits<A5>::ForwardType a5, | 959 typename base::internal::CallbackParamTraits<A4>::ForwardType a4, |
955 typename base::internal::ParamTraits<A6>::ForwardType a6) { | 960 typename base::internal::CallbackParamTraits<A5>::ForwardType a5, |
| 961 typename base::internal::CallbackParamTraits<A6>::ForwardType a6) { |
956 if (canceled()) return; | 962 if (canceled()) return; |
957 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5, a6), false); | 963 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5, a6), false); |
958 } | 964 } |
959 | 965 |
960 void ForwardResultAsync( | 966 void ForwardResultAsync( |
961 typename base::internal::ParamTraits<A1>::ForwardType a1, | 967 typename base::internal::CallbackParamTraits<A1>::ForwardType a1, |
962 typename base::internal::ParamTraits<A2>::ForwardType a2, | 968 typename base::internal::CallbackParamTraits<A2>::ForwardType a2, |
963 typename base::internal::ParamTraits<A3>::ForwardType a3, | 969 typename base::internal::CallbackParamTraits<A3>::ForwardType a3, |
964 typename base::internal::ParamTraits<A4>::ForwardType a4, | 970 typename base::internal::CallbackParamTraits<A4>::ForwardType a4, |
965 typename base::internal::ParamTraits<A5>::ForwardType a5, | 971 typename base::internal::CallbackParamTraits<A5>::ForwardType a5, |
966 typename base::internal::ParamTraits<A6>::ForwardType a6) { | 972 typename base::internal::CallbackParamTraits<A6>::ForwardType a6) { |
967 if (canceled()) return; | 973 if (canceled()) return; |
968 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5, a6), true); | 974 DoForward(base::Bind(callback_, a1, a2, a3, a4, a5, a6), true); |
969 } | 975 } |
970 | 976 |
971 protected: | 977 protected: |
972 virtual ~CancelableRequest() {} | 978 virtual ~CancelableRequest() {} |
973 | 979 |
974 private: | 980 private: |
975 CallbackType callback_; | 981 CallbackType callback_; |
976 }; | 982 }; |
(...skipping 27 matching lines...) Expand all Loading... |
1004 } | 1010 } |
1005 | 1011 |
1006 // The value. | 1012 // The value. |
1007 Type value; | 1013 Type value; |
1008 | 1014 |
1009 protected: | 1015 protected: |
1010 virtual ~CancelableRequest1() {} | 1016 virtual ~CancelableRequest1() {} |
1011 }; | 1017 }; |
1012 | 1018 |
1013 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ | 1019 #endif // CONTENT_BROWSER_CANCELABLE_REQUEST_H_ |
OLD | NEW |