diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 17:11:41 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-08 17:11:41 +0000 |
commit | 02712874c2d623d1dd41c0b3350b769d2855b9f2 (patch) | |
tree | 7205e95c9ceb2cb33162b68621ac04d6ce0e1715 /ppapi | |
parent | 46e2912bee9e94634cf3c99c80766ea4a02a4744 (diff) | |
download | chromium_src-02712874c2d623d1dd41c0b3350b769d2855b9f2.zip chromium_src-02712874c2d623d1dd41c0b3350b769d2855b9f2.tar.gz chromium_src-02712874c2d623d1dd41c0b3350b769d2855b9f2.tar.bz2 |
Pepper: Make users of pp:NetworkMonitorPrivate less likely to leak resources.
a) Make NetworkListPrivate's constructor (that takes a PP_Resource) take
ownership of that resource.
b) Add an explicit PASS_REF to that constructor, to make its semantics clear.
TEST=PPAPI tests
Review URL: https://chromiumcodereview.appspot.com/10381002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135856 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/cpp/private/network_list_private.cc | 4 | ||||
-rw-r--r-- | ppapi/cpp/private/network_list_private.h | 3 | ||||
-rw-r--r-- | ppapi/tests/test_network_monitor_private.cc | 30 | ||||
-rw-r--r-- | ppapi/utility/private/network_list_observer_private.cc | 3 |
4 files changed, 12 insertions, 28 deletions
diff --git a/ppapi/cpp/private/network_list_private.cc b/ppapi/cpp/private/network_list_private.cc index 84990a2..35bb66a 100644 --- a/ppapi/cpp/private/network_list_private.cc +++ b/ppapi/cpp/private/network_list_private.cc @@ -20,8 +20,8 @@ template <> const char* interface_name<PPB_NetworkList_Private>() { NetworkListPrivate::NetworkListPrivate() { } -NetworkListPrivate::NetworkListPrivate(PP_Resource resource) - : Resource(resource) { +NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { } // static diff --git a/ppapi/cpp/private/network_list_private.h b/ppapi/cpp/private/network_list_private.h index d614362..31cd9b5 100644 --- a/ppapi/cpp/private/network_list_private.h +++ b/ppapi/cpp/private/network_list_private.h @@ -9,6 +9,7 @@ #include <vector> #include "ppapi/c/private/ppb_network_list_private.h" +#include "ppapi/cpp/pass_ref.h" #include "ppapi/cpp/resource.h" namespace pp { @@ -16,7 +17,7 @@ namespace pp { class NetworkListPrivate : public Resource { public: NetworkListPrivate(); - explicit NetworkListPrivate(PP_Resource resource); + NetworkListPrivate(PassRef, PP_Resource resource); /// Returns true if the required interface is available. static bool IsAvailable(); diff --git a/ppapi/tests/test_network_monitor_private.cc b/ppapi/tests/test_network_monitor_private.cc index 7757dee..f552686 100644 --- a/ppapi/tests/test_network_monitor_private.cc +++ b/ppapi/tests/test_network_monitor_private.cc @@ -23,33 +23,27 @@ struct CallbackData { explicit CallbackData(PP_Instance instance) : event(instance), call_counter(0), - list_resource(0), delete_monitor(false), monitor(NULL) { } ~CallbackData() { - if (list_resource) - pp::Module::Get()->core()->ReleaseResource(list_resource); } NestedEvent event; int call_counter; - PP_Resource list_resource; + pp::NetworkListPrivate network_list; bool delete_monitor; pp::NetworkMonitorPrivate* monitor; }; -void TestCallback(void* user_data, PP_Resource network_list) { +void TestCallback(void* user_data, PP_Resource pp_network_list) { CallbackData* data = static_cast<CallbackData*>(user_data); data->call_counter++; - if (data->list_resource) - pp::Module::Get()->core()->ReleaseResource(data->list_resource); - data->list_resource = network_list; + data->network_list = pp::NetworkListPrivate(pp::PASS_REF, pp_network_list); if (data->delete_monitor) delete data->monitor; - if (data->call_counter == 1) data->event.Signal(); } @@ -90,12 +84,6 @@ void TestNetworkMonitorPrivate::RunTests(const std::string& filter) { RUN_TEST_FORCEASYNC_AND_NOT(ListObserver, filter); } -std::string TestNetworkMonitorPrivate::VerifyNetworkListResource( - PP_Resource network_list_resource) { - pp::NetworkListPrivate network_list(network_list_resource); - return VerifyNetworkList(network_list); -} - std::string TestNetworkMonitorPrivate::VerifyNetworkList( const pp::NetworkListPrivate& network_list) { // Verify that there is at least one network interface. @@ -183,8 +171,7 @@ std::string TestNetworkMonitorPrivate::TestBasic() { callback_data.event.Wait(); ASSERT_EQ(callback_data.call_counter, 1); - ASSERT_SUBTEST_SUCCESS( - VerifyNetworkListResource(callback_data.list_resource)); + ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.network_list)); PASS(); } @@ -197,8 +184,7 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() { callback_data.event.Wait(); ASSERT_EQ(callback_data.call_counter, 1); - ASSERT_SUBTEST_SUCCESS( - VerifyNetworkListResource(callback_data.list_resource)); + ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.network_list)); CallbackData callback_data_2(instance_->pp_instance()); @@ -207,8 +193,7 @@ std::string TestNetworkMonitorPrivate::Test2Monitors() { callback_data_2.event.Wait(); ASSERT_EQ(callback_data_2.call_counter, 1); - ASSERT_SUBTEST_SUCCESS( - VerifyNetworkListResource(callback_data_2.list_resource)); + ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data_2.network_list)); PASS(); } @@ -224,8 +209,7 @@ std::string TestNetworkMonitorPrivate::TestDeleteInCallback() { callback_data.event.Wait(); ASSERT_EQ(callback_data.call_counter, 1); - ASSERT_SUBTEST_SUCCESS( - VerifyNetworkListResource(callback_data.list_resource)); + ASSERT_SUBTEST_SUCCESS(VerifyNetworkList(callback_data.network_list)); PASS(); } diff --git a/ppapi/utility/private/network_list_observer_private.cc b/ppapi/utility/private/network_list_observer_private.cc index f41e81b..1969ee1 100644 --- a/ppapi/utility/private/network_list_observer_private.cc +++ b/ppapi/utility/private/network_list_observer_private.cc @@ -26,9 +26,8 @@ void NetworkListObserverPrivate::NetworkListCallbackHandler( PP_Resource list_resource) { NetworkListObserverPrivate* object = static_cast<NetworkListObserverPrivate*>(user_data); - NetworkListPrivate list(list_resource); + NetworkListPrivate list(PASS_REF, list_resource); object->OnNetworkListChanged(list); - Module::Get()->core()->ReleaseResource(list_resource); } } // namespace pp |