diff options
Diffstat (limited to 'webkit/plugins/ppapi')
26 files changed, 103 insertions, 849 deletions
diff --git a/webkit/plugins/ppapi/callbacks.cc b/webkit/plugins/ppapi/callbacks.cc deleted file mode 100644 index 84fffd0..0000000 --- a/webkit/plugins/ppapi/callbacks.cc +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/plugins/ppapi/callbacks.h" - -#include <algorithm> - -#include "base/bind.h" -#include "base/compiler_specific.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_errors.h" - -namespace webkit { -namespace ppapi { - -// CallbackTracker ------------------------------------------------------------- - -CallbackTracker::CallbackTracker() { -} - -void CallbackTracker::AbortAll() { - // Iterate over a copy since |Abort()| calls |Remove()| (indirectly). - // TODO(viettrungluu): This obviously isn't so efficient. - CallbackSetMap pending_callbacks_copy = pending_callbacks_; - for (CallbackSetMap::iterator it1 = pending_callbacks_copy.begin(); - it1 != pending_callbacks_copy.end(); ++it1) { - for (CallbackSet::iterator it2 = it1->second.begin(); - it2 != it1->second.end(); ++it2) { - (*it2)->Abort(); - } - } -} - -void CallbackTracker::PostAbortForResource(PP_Resource resource_id) { - CHECK(resource_id != 0); - CallbackSetMap::iterator it1 = pending_callbacks_.find(resource_id); - if (it1 == pending_callbacks_.end()) - return; - for (CallbackSet::iterator it2 = it1->second.begin(); - it2 != it1->second.end(); ++it2) { - // Post the abort. - (*it2)->PostAbort(); - } -} - -CallbackTracker::~CallbackTracker() { - // All callbacks must be aborted before destruction. - CHECK_EQ(0u, pending_callbacks_.size()); -} - -void CallbackTracker::Add( - const scoped_refptr<TrackedCallback>& tracked_callback) { - PP_Resource resource_id = tracked_callback->resource_id(); - DCHECK(pending_callbacks_[resource_id].find(tracked_callback) == - pending_callbacks_[resource_id].end()); - pending_callbacks_[resource_id].insert(tracked_callback); -} - -void CallbackTracker::Remove( - const scoped_refptr<TrackedCallback>& tracked_callback) { - CallbackSetMap::iterator map_it = - pending_callbacks_.find(tracked_callback->resource_id()); - DCHECK(map_it != pending_callbacks_.end()); - CallbackSet::iterator it = map_it->second.find(tracked_callback); - DCHECK(it != map_it->second.end()); - map_it->second.erase(it); - - // If there are no pending callbacks left for this ID, get rid of the entry. - if (map_it->second.empty()) - pending_callbacks_.erase(map_it); -} - -// TrackedCallback ------------------------------------------------------------- - -TrackedCallback::TrackedCallback(const scoped_refptr<CallbackTracker>& tracker, - PP_Resource resource_id) - : ALLOW_THIS_IN_INITIALIZER_LIST(abort_impl_factory_(this)), - tracker_(tracker), - resource_id_(resource_id), - completed_(false), - aborted_(false) { - tracker_->Add(make_scoped_refptr(this)); -} - -void TrackedCallback::Abort() { - if (!completed()) { - aborted_ = true; - AbortImpl(); - } -} - -void TrackedCallback::PostAbort() { - if (!completed()) { - aborted_ = true; - // Post a task for the abort (only if necessary). - if (!abort_impl_factory_.HasWeakPtrs()) { - MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&TrackedCallback::AbortImpl, - abort_impl_factory_.GetWeakPtr())); - } - } -} - -TrackedCallback::~TrackedCallback() { - // The tracker must ensure that the callback is completed (maybe abortively). - DCHECK(completed_); -} - -void TrackedCallback::MarkAsCompleted() { - DCHECK(!completed()); - - // We will be removed; maintain a reference to ensure we won't be deleted - // until we're done. - scoped_refptr<TrackedCallback> thiz = this; - completed_ = true; - tracker_->Remove(thiz); - tracker_ = NULL; -} - -// TrackedCompletionCallback --------------------------------------------------- - -TrackedCompletionCallback::TrackedCompletionCallback( - const scoped_refptr<CallbackTracker>& tracker, - PP_Resource resource_id, - const PP_CompletionCallback& callback) - : TrackedCallback(tracker, resource_id), - callback_(callback) { -} - -void TrackedCompletionCallback::Run(int32_t result) { - if (!completed()) { - // Cancel any pending calls. - abort_impl_factory_.InvalidateWeakPtrs(); - - // Copy |callback_| and look at |aborted()| now, since |MarkAsCompleted()| - // may delete us. - PP_CompletionCallback callback = callback_; - if (aborted()) - result = PP_ERROR_ABORTED; - - // Do this before running the callback in case of reentrancy (which - // shouldn't happen, but avoid strange failures). - MarkAsCompleted(); - PP_RunCompletionCallback(&callback, result); - } -} - -void TrackedCompletionCallback::AbortImpl() { - Run(PP_ERROR_ABORTED); -} - -} // namespace ppapi -} // namespace webkit diff --git a/webkit/plugins/ppapi/callbacks.h b/webkit/plugins/ppapi/callbacks.h deleted file mode 100644 index 3f92a01..0000000 --- a/webkit/plugins/ppapi/callbacks.h +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_GLUE_PLUGINS_PEPPER_CALLBACKS_H_ -#define WEBKIT_GLUE_PLUGINS_PEPPER_CALLBACKS_H_ - -#include <map> -#include <set> - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" -#include "base/task.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_resource.h" -#include "webkit/plugins/webkit_plugins_export.h" - -namespace webkit { -namespace ppapi { - -class TrackedCallback; - -// Pepper callbacks have the following semantics (unless otherwise specified; -// in particular, the below apply to all completion callbacks): -// - Callbacks are always run on the main thread. -// - Callbacks are always called from the main message loop. In particular, -// calling into Pepper will not result in the plugin being re-entered via a -// synchronously-run callback. -// - Each callback will be executed (a.k.a. completed) exactly once. -// - Each callback may be *aborted*, which means that it will be executed with -// result |PP_ERROR_ABORTED| (in the case of completion callbacks). -// - Before |PPP_ShutdownModule()| is called, every pending callback (for that -// module) will be aborted. -// - Callbacks are usually associated to a resource, whose "deletion" provides -// a "cancellation" (or abort) mechanism -- see below. -// - When a plugin releases its last reference to resource, all callbacks -// associated to that resource are aborted. Even if a non-abortive completion -// of such a callback had previously been scheduled (i.e., posted), that -// callback must now be aborted. The aborts should be scheduled immediately -// (upon the last reference being given up) and should not rely on anything -// else (e.g., a background task to complete or further action from the -// plugin). -// - Abortive completion gives no information about the status of the -// asynchronous operation: The operation may have not yet begun, may be in -// progress, or may be completed (successfully or not). In fact, the -// operation may still proceed after the callback has been aborted. -// - Any output data buffers provided to Pepper are associated with a resource. -// Once that resource is released, no subsequent writes to those buffers. (If -// background threads are set up to write into such buffers, the final -// release operation should not return into the plugin until it can -// guaranteed that those threads will no longer write into the buffers.) -// -// Thread-safety notes: -// Currently, everything should happen on the main thread. The objects are -// thread-safe ref-counted, so objects which live on different threads may keep -// references. Releasing a reference to |TrackedCallback| on a different thread -// (possibly causing destruction) is also okay. Otherwise, all methods should be -// called only from the main thread. - -// |CallbackTracker| tracks pending Pepper callbacks for a single module. It -// also tracks, for each resource ID, which callbacks are pending. When a -// callback is (just about to be) completed, it is removed from the tracker. We -// use |CallbackTracker| for two things: (1) to ensure that all callbacks are -// properly aborted before module shutdown, and (2) to ensure that all callbacks -// associated to a given resource are aborted when a plugin (module) releases -// its last reference to that resource. -class CallbackTracker : public base::RefCountedThreadSafe<CallbackTracker> { - public: - CallbackTracker(); - - // Abort all callbacks (synchronously). - void AbortAll(); - - // Abort all callbacks associated to the given resource ID (which must be - // valid, i.e., nonzero) by posting a task (or tasks). - void PostAbortForResource(PP_Resource resource_id); - - private: - friend class base::RefCountedThreadSafe<CallbackTracker>; - WEBKIT_PLUGINS_EXPORT ~CallbackTracker(); - - // |TrackedCallback| are expected to automatically add and - // remove themselves from their provided |CallbackTracker|. - friend class TrackedCallback; - void Add(const scoped_refptr<TrackedCallback>& tracked_callback); - void Remove(const scoped_refptr<TrackedCallback>& tracked_callback); - - // For each resource ID with a pending callback, store a set with its pending - // callbacks. (Resource ID 0 is used for callbacks not associated to a valid - // resource.) If a resource ID is re-used for another resource, there may be - // aborted callbacks corresponding to the original resource in that set; these - // will be removed when they are completed (abortively). - typedef std::set<scoped_refptr<TrackedCallback> > CallbackSet; - typedef std::map<PP_Resource, CallbackSet> CallbackSetMap; - CallbackSetMap pending_callbacks_; - - DISALLOW_COPY_AND_ASSIGN(CallbackTracker); -}; - -// |TrackedCallback| represents a tracked Pepper callback (from the browser to -// the plugin), typically still pending. Such callbacks have the standard Pepper -// callback semantics. Execution (i.e., completion) of callbacks happens through -// objects of subclasses of |TrackedCallback|. Two things are ensured: (1) that -// the callback is executed at most once, and (2) once a callback is marked to -// be aborted, any subsequent completion is abortive (even if a non-abortive -// completion had previously been scheduled). -// -// The details of non-abortive completion depend on the type of callback (e.g., -// different parameters may be required), but basic abort functionality is core. -// The ability to post aborts is needed in many situations to ensure that the -// plugin is not re-entered into. (Note that posting a task to just run -// |Abort()| is different and not correct; calling |PostAbort()| additionally -// guarantees that all subsequent completions will be abortive.) -// -// This class is reference counted so that different things can hang on to it, -// and not worry too much about ensuring Pepper callback semantics. Note that -// the "owning" |CallbackTracker| will keep a reference until the callback is -// completed. -// -// Subclasses must do several things: -// - They must ensure that the callback is executed at most once (by looking at -// |completed()| before running the callback). -// - They must ensure that the callback is run abortively if it is marked as to -// be aborted (by looking at |aborted()| before running the callback). -// - They must call |MarkAsCompleted()| immediately before actually running the -// callback; see the comment for |MarkAsCompleted()| for a caveat. -class TrackedCallback : public base::RefCountedThreadSafe<TrackedCallback> { - public: - // The constructor will add the new object to the tracker. The resource ID is - // optional -- set it to 0 if no resource is associated to the callback. - TrackedCallback(const scoped_refptr<CallbackTracker>& tracker, - PP_Resource resource_id); - - // These run the callback in an abortive manner, or post a task to do so (but - // immediately marking the callback as to be aborted). - WEBKIT_PLUGINS_EXPORT void Abort(); - void PostAbort(); - - // Returns the ID of the resource which "owns" the callback, or 0 if the - // callback is not associated with any resource. - PP_Resource resource_id() const { return resource_id_; } - - // Returns true if the callback was completed (possibly aborted). - bool completed() const { return completed_; } - - // Returns true if the callback was or should be aborted; this will be the - // case whenever |Abort()| or |PostAbort()| is called before a non-abortive - // completion. - bool aborted() const { return aborted_; } - - protected: - // This class is ref counted. - friend class base::RefCountedThreadSafe<TrackedCallback>; - virtual ~TrackedCallback(); - - // To be implemented by subclasses: Actually run the callback abortively. - virtual void AbortImpl() = 0; - - // Mark this object as complete and remove it from the tracker. This must only - // be called once. Note that running this may result in this object being - // deleted (so keep a reference if it'll still be needed). - void MarkAsCompleted(); - - // Factory used by |PostAbort()|. Note that it's safe to cancel any pending - // posted aborts on destruction -- before it's destroyed, the "owning" - // |CallbackTracker| must have gone through and done (synchronous) |Abort()|s. - base::WeakPtrFactory<TrackedCallback> abort_impl_factory_; - - private: - scoped_refptr<CallbackTracker> tracker_; - PP_Resource resource_id_; - bool completed_; - bool aborted_; - - DISALLOW_COPY_AND_ASSIGN(TrackedCallback); -}; - -// |TrackedCompletionCallback| represents a tracked Pepper completion callback. -class TrackedCompletionCallback : public TrackedCallback { - public: - // Create a tracked completion callback and register it with the tracker. The - // resource ID may be 0 if the callback is not associated to any resource. - WEBKIT_PLUGINS_EXPORT TrackedCompletionCallback( - const scoped_refptr<CallbackTracker>& tracker, - PP_Resource resource_id, - const PP_CompletionCallback& callback); - - // Run the callback with the given result. If the callback had previously been - // marked as to be aborted (by |PostAbort()|), |result| will be ignored and - // the callback will be run with result |PP_ERROR_ABORTED|. - WEBKIT_PLUGINS_EXPORT void Run(int32_t result); - - protected: - // |TrackedCallback| method: - virtual void AbortImpl(); - - private: - PP_CompletionCallback callback_; - - DISALLOW_COPY_AND_ASSIGN(TrackedCompletionCallback); -}; - -} // namespace ppapi -} // namespace webkit - -#endif // WEBKIT_PLUGINS_PPAPI_CALLBACKS_H_ diff --git a/webkit/plugins/ppapi/callbacks_unittest.cc b/webkit/plugins/ppapi/callbacks_unittest.cc deleted file mode 100644 index 8e90b31..0000000 --- a/webkit/plugins/ppapi/callbacks_unittest.cc +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/plugins/ppapi/ppapi_unittest.h" - -#include "base/memory/ref_counted.h" -#include "base/message_loop.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/shared_impl/resource_tracker.h" -#include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/host_globals.h" -#include "webkit/plugins/ppapi/mock_resource.h" -#include "webkit/plugins/ppapi/plugin_module.h" -#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/resource_helper.h" - -namespace webkit { -namespace ppapi { - -struct CallbackRunInfo { - // All valid results (PP_OK, PP_ERROR_...) are nonpositive. - CallbackRunInfo() : run_count(0), result(1) {} - unsigned run_count; - int32_t result; -}; - -namespace { - -void TestCallback(void* user_data, int32_t result) { - CallbackRunInfo* info = reinterpret_cast<CallbackRunInfo*>(user_data); - info->run_count++; - if (info->run_count == 1) - info->result = result; -} - -} // namespace - -// CallbackShutdownTest -------------------------------------------------------- - -// Tests that callbacks are properly aborted on module shutdown. -class CallbackShutdownTest : public PpapiUnittest { - public: - CallbackShutdownTest() {} - - // Cases: - // (1) A callback which is run (so shouldn't be aborted on shutdown). - // (2) A callback which is aborted (so shouldn't be aborted on shutdown). - // (3) A callback which isn't run (so should be aborted on shutdown). - CallbackRunInfo& info_did_run() { return info_did_run_; } // (1) - CallbackRunInfo& info_did_abort() { return info_did_abort_; } // (2) - CallbackRunInfo& info_didnt_run() { return info_didnt_run_; } // (3) - - private: - CallbackRunInfo info_did_run_; - CallbackRunInfo info_did_abort_; - CallbackRunInfo info_didnt_run_; -}; - -TEST_F(CallbackShutdownTest, AbortOnShutdown) { - // Set up case (1) (see above). - EXPECT_EQ(0U, info_did_run().run_count); - scoped_refptr<TrackedCompletionCallback> callback_did_run = - new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), - 0, - PP_MakeCompletionCallback(&TestCallback, &info_did_run())); - EXPECT_EQ(0U, info_did_run().run_count); - callback_did_run->Run(PP_OK); - EXPECT_EQ(1U, info_did_run().run_count); - EXPECT_EQ(PP_OK, info_did_run().result); - - // Set up case (2). - EXPECT_EQ(0U, info_did_abort().run_count); - scoped_refptr<TrackedCompletionCallback> callback_did_abort = - new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), - 0, - PP_MakeCompletionCallback(&TestCallback, &info_did_abort())); - EXPECT_EQ(0U, info_did_abort().run_count); - callback_did_abort->Abort(); - EXPECT_EQ(1U, info_did_abort().run_count); - EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort().result); - - - // Set up case (3). - EXPECT_EQ(0U, info_didnt_run().run_count); - scoped_refptr<TrackedCompletionCallback> callback_didnt_run = - new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), - 0, - PP_MakeCompletionCallback(&TestCallback, &info_didnt_run())); - EXPECT_EQ(0U, info_didnt_run().run_count); - - ShutdownModule(); - - // Check case (1). - EXPECT_EQ(1U, info_did_run().run_count); - - // Check case (2). - EXPECT_EQ(1U, info_did_abort().run_count); - - // Check case (3). - EXPECT_EQ(1U, info_didnt_run().run_count); - EXPECT_EQ(PP_ERROR_ABORTED, info_didnt_run().result); -} - -// ----------------------------------------------------------------------------- - -namespace { - -class CallbackMockResource : public MockResource { - public: - CallbackMockResource(PP_Instance instance) : MockResource(instance) {} - ~CallbackMockResource() {} - - PP_Resource SetupForTest() { - PP_Resource resource_id = GetReference(); - EXPECT_NE(0, resource_id); - - PluginModule* module = ResourceHelper::GetPluginModule(this); - - callback_did_run_ = new TrackedCompletionCallback( - module->GetCallbackTracker(), - resource_id, - PP_MakeCompletionCallback(&TestCallback, &info_did_run_)); - EXPECT_EQ(0U, info_did_run_.run_count); - - callback_did_abort_ = new TrackedCompletionCallback( - module->GetCallbackTracker(), - resource_id, - PP_MakeCompletionCallback(&TestCallback, &info_did_abort_)); - EXPECT_EQ(0U, info_did_abort_.run_count); - - callback_didnt_run_ = new TrackedCompletionCallback( - module->GetCallbackTracker(), - resource_id, - PP_MakeCompletionCallback(&TestCallback, &info_didnt_run_)); - EXPECT_EQ(0U, info_didnt_run_.run_count); - - callback_did_run_->Run(PP_OK); - callback_did_abort_->Abort(); - - CheckIntermediateState(); - - return resource_id; - } - - void CheckIntermediateState() { - EXPECT_EQ(1U, info_did_run_.run_count); - EXPECT_EQ(PP_OK, info_did_run_.result); - - EXPECT_EQ(1U, info_did_abort_.run_count); - EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.result); - - EXPECT_EQ(0U, info_didnt_run_.run_count); - } - - void CheckFinalState() { - EXPECT_EQ(1U, info_did_run_.run_count); - EXPECT_EQ(PP_OK, info_did_run_.result); - EXPECT_EQ(1U, info_did_abort_.run_count); - EXPECT_EQ(PP_ERROR_ABORTED, info_did_abort_.result); - EXPECT_EQ(1U, info_didnt_run_.run_count); - EXPECT_EQ(PP_ERROR_ABORTED, info_didnt_run_.result); - } - - scoped_refptr<TrackedCompletionCallback> callback_did_run_; - CallbackRunInfo info_did_run_; - - scoped_refptr<TrackedCompletionCallback> callback_did_abort_; - CallbackRunInfo info_did_abort_; - - scoped_refptr<TrackedCompletionCallback> callback_didnt_run_; - CallbackRunInfo info_didnt_run_; -}; - -} // namespace - -class CallbackResourceTest : public PpapiUnittest { - public: - CallbackResourceTest() {} -}; - -// Test that callbacks get aborted on the last resource unref. -TEST_F(CallbackResourceTest, AbortOnNoRef) { - HostResourceTracker* resource_tracker = - HostGlobals::Get()->host_resource_tracker(); - - // Test several things: Unref-ing a resource (to zero refs) with callbacks - // which (1) have been run, (2) have been aborted, (3) haven't been completed. - // Check that the uncompleted one gets aborted, and that the others don't get - // called again. - scoped_refptr<CallbackMockResource> resource_1( - new CallbackMockResource(instance()->pp_instance())); - PP_Resource resource_1_id = resource_1->SetupForTest(); - - // Also do the same for a second resource, and make sure that unref-ing the - // first resource doesn't much up the second resource. - scoped_refptr<CallbackMockResource> resource_2( - new CallbackMockResource(instance()->pp_instance())); - PP_Resource resource_2_id = resource_2->SetupForTest(); - - // Double-check that resource #1 is still okay. - resource_1->CheckIntermediateState(); - - // Kill resource #1, spin the message loop to run posted calls, and check that - // things are in the expected states. - resource_tracker->ReleaseResource(resource_1_id); - MessageLoop::current()->RunAllPending(); - resource_1->CheckFinalState(); - resource_2->CheckIntermediateState(); - - // Kill resource #2. - resource_tracker->ReleaseResource(resource_2_id); - MessageLoop::current()->RunAllPending(); - resource_1->CheckFinalState(); - resource_2->CheckFinalState(); - - // This shouldn't be needed, but make sure there are no stranded tasks. - MessageLoop::current()->RunAllPending(); -} - -// Test that "resurrecting" a resource (getting a new ID for a |Resource|) -// doesn't resurrect callbacks. -TEST_F(CallbackResourceTest, Resurrection) { - HostResourceTracker* resource_tracker = - HostGlobals::Get()->host_resource_tracker(); - - scoped_refptr<CallbackMockResource> resource( - new CallbackMockResource(instance()->pp_instance())); - PP_Resource resource_id = resource->SetupForTest(); - - // Unref it, spin the message loop to run posted calls, and check that things - // are in the expected states. - resource_tracker->ReleaseResource(resource_id); - MessageLoop::current()->RunAllPending(); - resource->CheckFinalState(); - - // "Resurrect" it and check that the callbacks are still dead. - PP_Resource new_resource_id = resource->GetReference(); - MessageLoop::current()->RunAllPending(); - resource->CheckFinalState(); - - // Unref it again and do the same. - resource_tracker->ReleaseResource(new_resource_id); - MessageLoop::current()->RunAllPending(); - resource->CheckFinalState(); - - // This shouldn't be needed, but make sure there are no stranded tasks. - MessageLoop::current()->RunAllPending(); -} - -} // namespace ppapi -} // namespace webkit diff --git a/webkit/plugins/ppapi/file_callbacks.cc b/webkit/plugins/ppapi/file_callbacks.cc index ce84c41..e9e1aee 100644 --- a/webkit/plugins/ppapi/file_callbacks.cc +++ b/webkit/plugins/ppapi/file_callbacks.cc @@ -10,27 +10,26 @@ #include "ppapi/c/ppb_file_system.h" #include "ppapi/shared_impl/file_type_conversion.h" #include "ppapi/shared_impl/time_conversion.h" +#include "ppapi/shared_impl/tracked_callback.h" #include "webkit/fileapi/file_system_types.h" -#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" #include "webkit/plugins/ppapi/ppb_file_system_impl.h" +using ppapi::Resource; using ppapi::TimeToPPTime; +using ppapi::TrackedCallback; namespace webkit { namespace ppapi { FileCallbacks::FileCallbacks( - const base::WeakPtr<PluginModule>& module, - PP_Resource resource_id, + Resource* resource, PP_CompletionCallback callback, PP_FileInfo* info, scoped_refptr<PPB_FileSystem_Impl> file_system, scoped_refptr<PPB_DirectoryReader_Impl> directory_reader) - : callback_(new TrackedCompletionCallback(module->GetCallbackTracker(), - resource_id, - callback)), + : callback_(new TrackedCallback(resource, callback)), info_(info), file_system_(file_system), directory_reader_(directory_reader) { diff --git a/webkit/plugins/ppapi/file_callbacks.h b/webkit/plugins/ppapi/file_callbacks.h index 878c278..8c00336 100644 --- a/webkit/plugins/ppapi/file_callbacks.h +++ b/webkit/plugins/ppapi/file_callbacks.h @@ -21,19 +21,21 @@ namespace base { class FilePath; } +namespace ppapi { +class Resource; +class TrackedCallback; +} + namespace webkit { namespace ppapi { class PPB_DirectoryReader_Impl; class PPB_FileSystem_Impl; -class PluginModule; -class TrackedCompletionCallback; // Instances of this class are deleted by FileSystemDispatcher. class FileCallbacks : public fileapi::FileSystemCallbackDispatcher { public: - FileCallbacks(const base::WeakPtr<PluginModule>& module, - PP_Resource resource_id, + FileCallbacks(::ppapi::Resource* resource, PP_CompletionCallback callback, PP_FileInfo* info, scoped_refptr<PPB_FileSystem_Impl> file_system, @@ -52,12 +54,12 @@ class FileCallbacks : public fileapi::FileSystemCallbackDispatcher { virtual void DidFail(base::PlatformFileError error_code); virtual void DidWrite(int64 bytes, bool complete); - scoped_refptr<TrackedCompletionCallback> GetTrackedCompletionCallback() const; + scoped_refptr< ::ppapi::TrackedCallback> GetTrackedCallback() const; private: void RunCallback(base::PlatformFileError error_code); - scoped_refptr<TrackedCompletionCallback> callback_; + scoped_refptr< ::ppapi::TrackedCallback> callback_; PP_FileInfo* info_; scoped_refptr<PPB_FileSystem_Impl> file_system_; scoped_refptr<PPB_DirectoryReader_Impl> directory_reader_; diff --git a/webkit/plugins/ppapi/host_globals.cc b/webkit/plugins/ppapi/host_globals.cc index 56eb90a..ab51983 100644 --- a/webkit/plugins/ppapi/host_globals.cc +++ b/webkit/plugins/ppapi/host_globals.cc @@ -51,7 +51,7 @@ HostGlobals::~HostGlobals() { } ::ppapi::ResourceTracker* HostGlobals::GetResourceTracker() { - return &host_resource_tracker_; + return &resource_tracker_; } ::ppapi::VarTracker* HostGlobals::GetVarTracker() { @@ -65,7 +65,7 @@ HostGlobals::~HostGlobals() { if (found == instance_map_.end()) return NULL; - return found->second->instance->module()->GetNewCallbackTracker(); + return found->second->instance->module()->GetCallbackTracker(); } ::ppapi::FunctionGroupBase* HostGlobals::GetFunctionAPI(PP_Instance pp_instance, @@ -173,18 +173,18 @@ PP_Instance HostGlobals::AddInstance(PluginInstance* instance) { instance_map_[new_instance] = linked_ptr<InstanceData>(new InstanceData); instance_map_[new_instance]->instance = instance; - host_resource_tracker_.DidCreateInstance(new_instance); + resource_tracker_.DidCreateInstance(new_instance); return new_instance; } void HostGlobals::InstanceDeleted(PP_Instance instance) { - host_resource_tracker_.DidDeleteInstance(instance); + resource_tracker_.DidDeleteInstance(instance); host_var_tracker_.ForceFreeNPObjectsForInstance(instance); instance_map_.erase(instance); } void HostGlobals::InstanceCrashed(PP_Instance instance) { - host_resource_tracker_.DidDeleteInstance(instance); + resource_tracker_.DidDeleteInstance(instance); host_var_tracker_.ForceFreeNPObjectsForInstance(instance); } diff --git a/webkit/plugins/ppapi/host_globals.h b/webkit/plugins/ppapi/host_globals.h index 914be3a..db840aa 100644 --- a/webkit/plugins/ppapi/host_globals.h +++ b/webkit/plugins/ppapi/host_globals.h @@ -8,8 +8,8 @@ #include "base/compiler_specific.h" #include "ppapi/shared_impl/callback_tracker.h" #include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/resource_tracker.h" #include "ppapi/shared_impl/var_tracker.h" -#include "webkit/plugins/ppapi/host_resource_tracker.h" #include "webkit/plugins/ppapi/host_var_tracker.h" #include "webkit/plugins/webkit_plugins_export.h" @@ -39,9 +39,6 @@ class HostGlobals : public ::ppapi::PpapiGlobals { ::ppapi::ApiID id) OVERRIDE; virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; - HostResourceTracker* host_resource_tracker() { - return &host_resource_tracker_; - } HostVarTracker* host_var_tracker() { return &host_var_tracker_; } @@ -83,7 +80,7 @@ class HostGlobals : public ::ppapi::PpapiGlobals { WEBKIT_PLUGINS_EXPORT static HostGlobals* host_globals_; - HostResourceTracker host_resource_tracker_; + ::ppapi::ResourceTracker resource_tracker_; HostVarTracker host_var_tracker_; // Tracks all live instances and their associated data. diff --git a/webkit/plugins/ppapi/host_resource_tracker.cc b/webkit/plugins/ppapi/host_resource_tracker.cc deleted file mode 100644 index 70b5157..0000000 --- a/webkit/plugins/ppapi/host_resource_tracker.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/plugins/ppapi/host_resource_tracker.h" - -#include "ppapi/shared_impl/resource.h" -#include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/plugin_module.h" -#include "webkit/plugins/ppapi/resource_helper.h" - -namespace webkit { -namespace ppapi { - -HostResourceTracker::HostResourceTracker() { -} - -HostResourceTracker::~HostResourceTracker() { -} - -void HostResourceTracker::LastPluginRefWasDeleted(::ppapi::Resource* object) { - ::ppapi::ResourceTracker::LastPluginRefWasDeleted(object); - - // TODO(brettw) this should be removed when we have the callback tracker - // moved to the shared_impl. This will allow the logic to post aborts for - // any callbacks directly in the Resource::LastPluginRefWasDeleted function - // and we can remove this function altogether. - PluginModule* plugin_module = ResourceHelper::GetPluginModule(object); - if (plugin_module) { - plugin_module->GetCallbackTracker()->PostAbortForResource( - object->pp_resource()); - } -} - -} // namespace ppapi -} // namespace webkit diff --git a/webkit/plugins/ppapi/host_resource_tracker.h b/webkit/plugins/ppapi/host_resource_tracker.h deleted file mode 100644 index 503b9ee..0000000 --- a/webkit/plugins/ppapi/host_resource_tracker.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_PLUGINS_PPAPI_HOST_RESOURCE_TRACKER_H_ -#define WEBKIT_PLUGINS_PPAPI_HOST_RESOURCE_TRACKER_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ppapi/shared_impl/resource_tracker.h" - -namespace webkit { -namespace ppapi { - -class HostResourceTracker : public ::ppapi::ResourceTracker { - public: - HostResourceTracker(); - virtual ~HostResourceTracker(); - - // ppapi::ResourceTracker overrides. - virtual void LastPluginRefWasDeleted(::ppapi::Resource* object) OVERRIDE; - - private: - DISALLOW_COPY_AND_ASSIGN(HostResourceTracker); -}; - -} // namespace ppapi -} // namespace webkit - -#endif // WEBKIT_PLUGINS_PPAPI_HOST_RESOURCE_TRACKER_H_ diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 2340200..8b90fa8 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -93,10 +93,8 @@ #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" #include "webkit/plugins/plugin_switches.h" -#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/host_globals.h" -#include "webkit/plugins/ppapi/host_resource_tracker.h" #include "webkit/plugins/ppapi/ppapi_interface_factory.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" @@ -221,7 +219,7 @@ void QuitMessageLoop(PP_Instance instance) { } uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { - return HostGlobals::Get()->host_resource_tracker()->GetLiveObjectsForInstance( + return HostGlobals::Get()->GetResourceTracker()->GetLiveObjectsForInstance( instance_id); } @@ -417,7 +415,6 @@ PluginModule::PluginModule(const std::string& name, const FilePath& path, PluginDelegate::ModuleLifetime* lifetime_delegate) : lifetime_delegate_(lifetime_delegate), - old_callback_tracker_(new CallbackTracker), callback_tracker_(new ::ppapi::CallbackTracker), is_in_destructor_(false), is_crashed_(false), @@ -448,7 +445,6 @@ PluginModule::~PluginModule() { GetLivePluginSet()->erase(this); - old_callback_tracker_->AbortAll(); callback_tracker_->AbortAll(); if (entry_points_.shutdown_module) @@ -557,11 +553,7 @@ void PluginModule::InstanceDeleted(PluginInstance* instance) { instances_.erase(instance); } -scoped_refptr<CallbackTracker> PluginModule::GetCallbackTracker() { - return old_callback_tracker_; -} - -scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetNewCallbackTracker() { +scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetCallbackTracker() { return callback_tracker_; } diff --git a/webkit/plugins/ppapi/plugin_module.h b/webkit/plugins/ppapi/plugin_module.h index 708c8ac..c1e1c02 100644 --- a/webkit/plugins/ppapi/plugin_module.h +++ b/webkit/plugins/ppapi/plugin_module.h @@ -35,7 +35,6 @@ class WebKitForwarding; namespace webkit { namespace ppapi { -class CallbackTracker; class PluginDelegate; class PluginInstance; @@ -117,8 +116,7 @@ class WEBKIT_PLUGINS_EXPORT PluginModule : void InstanceCreated(PluginInstance* instance); void InstanceDeleted(PluginInstance* instance); - scoped_refptr<CallbackTracker> GetCallbackTracker(); - scoped_refptr< ::ppapi::CallbackTracker> GetNewCallbackTracker(); + scoped_refptr< ::ppapi::CallbackTracker> GetCallbackTracker(); // Called when running out of process and the plugin crashed. This will // release relevant resources and update all affected instances. @@ -156,10 +154,6 @@ class WEBKIT_PLUGINS_EXPORT PluginModule : // Tracker for completion callbacks, used mainly to ensure that all callbacks // are properly aborted on module shutdown. - // - // TODO(brettw) remove this in favor of the ::ppapi:: one below. - scoped_refptr<CallbackTracker> old_callback_tracker_; - scoped_refptr< ::ppapi::CallbackTracker> callback_tracker_; PP_Module pp_module_; diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc index 9696899..42273a1 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.cc +++ b/webkit/plugins/ppapi/ppb_broker_impl.cc @@ -10,8 +10,9 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/resource_helper.h" -using ::ppapi::PlatformFileToInt; -using ::ppapi::thunk::PPB_Broker_API; +using ppapi::PlatformFileToInt; +using ppapi::thunk::PPB_Broker_API; +using ppapi::TrackedCallback; namespace webkit { namespace ppapi { @@ -60,15 +61,11 @@ int32_t PPB_Broker_Impl::Connect(PP_CompletionCallback connect_callback) { // and BrokerConnected is called before ConnectToPpapiBroker returns. // Because it must be created now, it must be aborted and cleared if // ConnectToPpapiBroker fails. - connect_callback_ = new TrackedCompletionCallback( - plugin_instance->module()->GetCallbackTracker(), pp_resource(), - connect_callback); + connect_callback_ = new TrackedCallback(this, connect_callback); broker_ = plugin_instance->delegate()->ConnectToPpapiBroker(this); if (!broker_) { - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(connect_callback_); - callback->Abort(); + TrackedCallback::ClearAndAbort(&connect_callback_); return PP_ERROR_FAILED; } @@ -92,11 +89,9 @@ void PPB_Broker_Impl::BrokerConnected(int32_t handle, int32_t result) { pipe_handle_ = handle; // Synchronous calls are not supported. - DCHECK(connect_callback_.get() && !connect_callback_->completed()); + DCHECK(TrackedCallback::IsPending(connect_callback_)); - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(connect_callback_); - callback->Run(result); // Will complete abortively if necessary. + TrackedCallback::ClearAndRun(&connect_callback_, result); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h index 9d20a4d..2a95122 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.h +++ b/webkit/plugins/ppapi/ppb_broker_impl.h @@ -11,10 +11,10 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" #include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/tracked_callback.h" #include "ppapi/thunk/ppb_broker_api.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/webkit_plugins_export.h" namespace webkit { @@ -43,7 +43,7 @@ class WEBKIT_PLUGINS_EXPORT PPB_Broker_Impl PluginDelegate::PpapiBroker* broker_; // Callback invoked from BrokerConnected. - scoped_refptr<TrackedCompletionCallback> connect_callback_; + scoped_refptr< ::ppapi::TrackedCallback> connect_callback_; // Pipe handle for the plugin instance to use to communicate with the broker. // Never owned by this object. diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc index 36843f4..7992ce7 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc @@ -97,8 +97,7 @@ int32_t PPB_DirectoryReader_Impl::GetNextEntry( if (!plugin_instance->delegate()->ReadDirectory( directory_ref_->GetFileSystemURL(), - new FileCallbacks(plugin_instance->module()->AsWeakPtr(), - pp_resource(), callback, NULL, NULL, this))) + new FileCallbacks(this, callback, NULL, NULL, this))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc index 1a5167b..38e8f16 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc @@ -13,6 +13,7 @@ #include "base/sys_string_conversions.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/shared_impl/tracked_callback.h" #include "ppapi/shared_impl/var.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserCompletion.h" @@ -20,7 +21,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" #include "webkit/glue/webkit_glue.h" -#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/plugin_delegate.h" @@ -30,6 +30,7 @@ using ppapi::StringVar; using ppapi::thunk::PPB_FileChooser_API; +using ppapi::TrackedCallback; using WebKit::WebCString; using WebKit::WebFileChooserCompletion; using WebKit::WebFileChooserParams; @@ -123,7 +124,7 @@ int32_t PPB_FileChooser_Impl::ValidateCallback( if (!callback.func) return PP_ERROR_BLOCKS_MAIN_THREAD; - if (callback_.get() && !callback_->completed()) + if (TrackedCallback::IsPending(callback_)) return PP_ERROR_INPROGRESS; return PP_OK; @@ -132,20 +133,17 @@ int32_t PPB_FileChooser_Impl::ValidateCallback( void PPB_FileChooser_Impl::RegisterCallback( const PP_CompletionCallback& callback) { DCHECK(callback.func); - DCHECK(!callback_.get() || callback_->completed()); + DCHECK(!TrackedCallback::IsPending(callback_)); PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); if (!plugin_module) return; - callback_ = new TrackedCompletionCallback(plugin_module->GetCallbackTracker(), - pp_resource(), callback); + callback_ = new TrackedCallback(this, callback); } void PPB_FileChooser_Impl::RunCallback(int32_t result) { - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(callback_); - callback->Run(result); // Will complete abortively if necessary. + TrackedCallback::ClearAndRun(&callback_, result); } int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h index 8b76c4f..2ba9c5c 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.h @@ -17,6 +17,10 @@ struct PP_CompletionCallback; +namespace ppapi { +class TrackedCallback; +} + namespace WebKit { class WebString; } @@ -25,7 +29,6 @@ namespace webkit { namespace ppapi { class PPB_FileRef_Impl; -class TrackedCompletionCallback; class PPB_FileChooser_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_FileChooser_API { @@ -77,7 +80,7 @@ class PPB_FileChooser_Impl : public ::ppapi::Resource, private: PP_FileChooserMode_Dev mode_; std::string accept_mime_types_; - scoped_refptr<TrackedCompletionCallback> callback_; + scoped_refptr< ::ppapi::TrackedCallback> callback_; std::vector< scoped_refptr<PPB_FileRef_Impl> > chosen_files_; size_t next_chosen_file_index_; }; diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index 8cdcd76..4e9abc5 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -173,8 +173,7 @@ int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, return PP_ERROR_FAILED; if (!plugin_instance->delegate()->MakeDirectory( GetFileSystemURL(), PP_ToBool(make_ancestors), - new FileCallbacks(plugin_instance->module()->AsWeakPtr(), - pp_resource(), callback, NULL, NULL, NULL))) + new FileCallbacks(this, callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -194,8 +193,7 @@ int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, GetFileSystemURL(), PPTimeToTime(last_access_time), PPTimeToTime(last_modified_time), - new FileCallbacks(plugin_instance->module()->AsWeakPtr(), - pp_resource(), callback, NULL, NULL, NULL))) + new FileCallbacks(this, callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -211,8 +209,7 @@ int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { return PP_ERROR_FAILED; if (!plugin_instance->delegate()->Delete( GetFileSystemURL(), - new FileCallbacks(plugin_instance->module()->AsWeakPtr(), - pp_resource(), callback, NULL, NULL, NULL))) + new FileCallbacks(this, callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } @@ -238,8 +235,7 @@ int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, return PP_ERROR_FAILED; if (!plugin_instance->delegate()->Rename( GetFileSystemURL(), new_file_ref->GetFileSystemURL(), - new FileCallbacks(plugin_instance->module()->AsWeakPtr(), - pp_resource(), callback, NULL, NULL, NULL))) + new FileCallbacks(this, callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; } diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.cc b/webkit/plugins/ppapi/ppb_file_system_impl.cc index b7576bc..6d6df5d 100644 --- a/webkit/plugins/ppapi/ppb_file_system_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_system_impl.cc @@ -83,8 +83,7 @@ int32_t PPB_FileSystem_Impl::Open(int64_t expected_size, if (!plugin_instance->delegate()->OpenFileSystem( plugin_instance->container()->element().document().url(), file_system_type, expected_size, - new FileCallbacks(plugin_instance->module()->AsWeakPtr(), - pp_resource(), callback, NULL, + new FileCallbacks(this, callback, NULL, scoped_refptr<PPB_FileSystem_Impl>(this), NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc index 895aa4d..6c181d0 100644 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc @@ -14,7 +14,8 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource_helper.h" -using ::ppapi::thunk::PPB_Flash_Menu_API; +using ppapi::thunk::PPB_Flash_Menu_API; +using ppapi::TrackedCallback; namespace webkit { namespace ppapi { @@ -138,7 +139,7 @@ int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, if (!callback.func) return PP_ERROR_BLOCKS_MAIN_THREAD; - if (callback_.get() && !callback_->completed()) + if (TrackedCallback::IsPending(callback_)) return PP_ERROR_INPROGRESS; PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); @@ -149,9 +150,7 @@ int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, plugin_instance, this, gfx::Point(location->x, location->y)); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. - callback_ = new TrackedCompletionCallback( - plugin_instance->module()->GetCallbackTracker(), - pp_resource(), callback); + callback_ = new TrackedCallback(this, callback); selected_id_out_ = selected_id_out; } else { // This should never be completed synchronously successfully. @@ -182,11 +181,8 @@ void PPB_Flash_Menu_Impl::CompleteShow(int32_t result, } } - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(callback_); selected_id_out_ = NULL; - - callback->Run(rv); // Will complete abortively if necessary. + TrackedCallback::ClearAndRun(&callback_, rv); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.h b/webkit/plugins/ppapi/ppb_flash_menu_impl.h index 5f454f9..92daa64 100644 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.h @@ -12,9 +12,9 @@ #include "base/memory/ref_counted.h" #include "ppapi/c/pp_point.h" #include "ppapi/c/private/ppb_flash_menu.h" +#include "ppapi/shared_impl/tracked_callback.h" #include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_flash_menu_api.h" -#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/webkit_plugins_export.h" struct WebMenuItem; @@ -57,7 +57,7 @@ class PPB_Flash_Menu_Impl : public ::ppapi::Resource, std::vector<int32_t> menu_id_map_; // Any pending callback (for |Show()|). - scoped_refptr<TrackedCompletionCallback> callback_; + scoped_refptr< ::ppapi::TrackedCallback> callback_; // Output buffers to be filled in when the callback is completed successfully. int32_t* selected_id_out_; diff --git a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc index 13999592..62ad9b9 100644 --- a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc @@ -12,7 +12,8 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource_helper.h" -using ::ppapi::thunk::PPB_Flash_NetConnector_API; +using ppapi::thunk::PPB_Flash_NetConnector_API; +using ppapi::TrackedCallback; namespace webkit { namespace ppapi { @@ -46,7 +47,7 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcp( if (!callback.func) return PP_ERROR_BLOCKS_MAIN_THREAD; - if (callback_.get() && !callback_->completed()) + if (TrackedCallback::IsPending(callback_)) return PP_ERROR_INPROGRESS; PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); @@ -55,9 +56,7 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcp( int32_t rv = plugin_instance->delegate()->ConnectTcp(this, host, port); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. - callback_ = new TrackedCompletionCallback( - plugin_instance->module()->GetCallbackTracker(), - pp_resource(), callback); + callback_ = new TrackedCallback(this, callback); socket_out_ = socket_out; local_addr_out_ = local_addr_out; remote_addr_out_ = remote_addr_out; @@ -81,7 +80,7 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress( if (!callback.func) return PP_ERROR_BLOCKS_MAIN_THREAD; - if (callback_.get() && !callback_->completed()) + if (TrackedCallback::IsPending(callback_)) return PP_ERROR_INPROGRESS; PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); @@ -90,9 +89,7 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress( int32_t rv = plugin_instance->delegate()->ConnectTcpAddress(this, addr); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. - callback_ = new TrackedCompletionCallback( - plugin_instance->module()->GetCallbackTracker(), - pp_resource(), callback); + callback_ = new TrackedCallback(this, callback); socket_out_ = socket_out; local_addr_out_ = local_addr_out; remote_addr_out_ = remote_addr_out; @@ -124,16 +121,10 @@ void PPB_Flash_NetConnector_Impl::CompleteConnectTcp( } } - // Theoretically, the plugin should be allowed to try another |ConnectTcp()| - // from the callback. - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(callback_); - // Wipe everything else out for safety. socket_out_ = NULL; local_addr_out_ = NULL; remote_addr_out_ = NULL; - - callback->Run(rv); // Will complete abortively if necessary. + TrackedCallback::ClearAndRun(&callback_, rv); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h index 56fd60d..801ba2e 100644 --- a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h @@ -10,8 +10,8 @@ #include "base/memory/ref_counted.h" #include "ppapi/c/private/ppb_flash_net_connector.h" #include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/tracked_callback.h" #include "ppapi/thunk/ppb_flash_net_connector_api.h" -#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/webkit_plugins_export.h" namespace webkit { @@ -49,7 +49,7 @@ class PPB_Flash_NetConnector_Impl private: // Any pending callback (for |ConnectTcp()| or |ConnectTcpAddress()|). - scoped_refptr<TrackedCompletionCallback> callback_; + scoped_refptr< ::ppapi::TrackedCallback> callback_; // Output buffers to be filled in when the callback is completed successfully // (|{local,remote}_addr_out| are optional and may be null). diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc index 23c5ab8..e0d90ad 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.cc +++ b/webkit/plugins/ppapi/ppb_transport_impl.cc @@ -13,6 +13,8 @@ #include "ppapi/c/dev/ppb_transport_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "ppapi/shared_impl/callback_tracker.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/var.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" @@ -24,6 +26,7 @@ using ppapi::StringVar; using ppapi::thunk::PPB_Transport_API; +using ppapi::TrackedCallback; using webkit_glue::P2PTransport; namespace webkit { @@ -258,8 +261,7 @@ int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { if (!plugin_module) return PP_ERROR_FAILED; - connect_callback_ = new TrackedCompletionCallback( - plugin_module->GetCallbackTracker(), pp_resource(), callback); + connect_callback_ = new TrackedCallback(this, callback); return PP_OK_COMPLETIONPENDING; } @@ -270,7 +272,7 @@ int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address, if (!p2p_transport_.get()) return PP_ERROR_FAILED; - if (next_address_callback_.get() && !next_address_callback_->completed()) + if (TrackedCallback::IsPending(next_address_callback_)) return PP_ERROR_INPROGRESS; PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); @@ -283,8 +285,7 @@ int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address, return PP_OK; } - next_address_callback_ = new TrackedCompletionCallback( - plugin_module->GetCallbackTracker(), pp_resource(), callback); + next_address_callback_ = new TrackedCallback(this, callback); return PP_OK_COMPLETIONPENDING; } @@ -307,7 +308,7 @@ int32_t PPB_Transport_Impl::Recv(void* data, uint32_t len, if (!p2p_transport_.get()) return PP_ERROR_FAILED; - if (recv_callback_.get() && !recv_callback_->completed()) + if (TrackedCallback::IsPending(recv_callback_)) return PP_ERROR_INPROGRESS; net::Socket* channel = p2p_transport_->GetChannel(); @@ -323,10 +324,8 @@ int32_t PPB_Transport_Impl::Recv(void* data, uint32_t len, int result = MapNetError( channel->Read(buffer, len, base::Bind(&PPB_Transport_Impl::OnRead, base::Unretained(this)))); - if (result == PP_OK_COMPLETIONPENDING) { - recv_callback_ = new TrackedCompletionCallback( - plugin_module->GetCallbackTracker(), pp_resource(), callback); - } + if (result == PP_OK_COMPLETIONPENDING) + recv_callback_ = new TrackedCallback(this, callback); return result; } @@ -338,7 +337,7 @@ int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, if (!p2p_transport_.get()) return PP_ERROR_FAILED; - if (send_callback_.get() && !send_callback_->completed()) + if (TrackedCallback::IsPending(send_callback_)) return PP_ERROR_INPROGRESS; net::Socket* channel = p2p_transport_->GetChannel(); @@ -354,10 +353,8 @@ int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, int result = MapNetError( channel->Write(buffer, len, base::Bind(&PPB_Transport_Impl::OnWritten, base::Unretained(this)))); - if (result == PP_OK_COMPLETIONPENDING) { - send_callback_ = new TrackedCompletionCallback( - plugin_module->GetCallbackTracker(), pp_resource(), callback); - } + if (result == PP_OK_COMPLETIONPENDING) + send_callback_ = new TrackedCallback(this, callback); return result; } @@ -368,9 +365,8 @@ int32_t PPB_Transport_Impl::Close() { p2p_transport_.reset(); - PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); - if (plugin_module) - plugin_module->GetCallbackTracker()->AbortAll(); + ::ppapi::PpapiGlobals::Get()->GetCallbackTrackerForInstance( + pp_instance())->PostAbortForResource(pp_resource()); return PP_OK; } @@ -378,45 +374,30 @@ void PPB_Transport_Impl::OnCandidateReady(const std::string& address) { // Store the candidate first before calling the callback. local_candidates_.push_back(address); - if (next_address_callback_.get() && !next_address_callback_->completed()) { - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(next_address_callback_); - callback->Run(PP_OK); - } + if (TrackedCallback::IsPending(next_address_callback_)) + TrackedCallback::ClearAndRun(&next_address_callback_, PP_OK); } void PPB_Transport_Impl::OnStateChange(webkit_glue::P2PTransport::State state) { writable_ = (state | webkit_glue::P2PTransport::STATE_WRITABLE) != 0; - if (writable_ && connect_callback_.get() && !connect_callback_->completed()) { - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(connect_callback_); - callback->Run(PP_OK); - } + if (writable_ && TrackedCallback::IsPending(connect_callback_)) + TrackedCallback::ClearAndRun(&connect_callback_, PP_OK); } void PPB_Transport_Impl::OnError(int error) { writable_ = false; - if (connect_callback_.get() && !connect_callback_->completed()) { - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(connect_callback_); - callback->Run(PP_ERROR_FAILED); - } + if (TrackedCallback::IsPending(connect_callback_)) + TrackedCallback::ClearAndRun(&connect_callback_, PP_ERROR_FAILED); } void PPB_Transport_Impl::OnRead(int result) { - DCHECK(recv_callback_.get() && !recv_callback_->completed()); - - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(recv_callback_); - callback->Run(MapNetError(result)); + DCHECK(TrackedCallback::IsPending(recv_callback_)); + TrackedCallback::ClearAndRun(&recv_callback_, MapNetError(result)); } void PPB_Transport_Impl::OnWritten(int result) { - DCHECK(send_callback_.get() && !send_callback_->completed()); - - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(send_callback_); - callback->Run(MapNetError(result)); + DCHECK(TrackedCallback::IsPending(send_callback_)); + TrackedCallback::ClearAndRun(&send_callback_, MapNetError(result)); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_transport_impl.h b/webkit/plugins/ppapi/ppb_transport_impl.h index 1e5ecfa..34393e4 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.h +++ b/webkit/plugins/ppapi/ppb_transport_impl.h @@ -11,10 +11,10 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "net/base/completion_callback.h" +#include "ppapi/shared_impl/tracked_callback.h" #include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_transport_api.h" #include "webkit/glue/p2p_transport.h" -#include "webkit/plugins/ppapi/callbacks.h" namespace webkit { namespace ppapi { @@ -67,11 +67,11 @@ class PPB_Transport_Impl : public ::ppapi::Resource, bool writable_; std::list<std::string> local_candidates_; - scoped_refptr<TrackedCompletionCallback> connect_callback_; - scoped_refptr<TrackedCompletionCallback> next_address_callback_; + scoped_refptr< ::ppapi::TrackedCallback> connect_callback_; + scoped_refptr< ::ppapi::TrackedCallback> next_address_callback_; - scoped_refptr<TrackedCompletionCallback> recv_callback_; - scoped_refptr<TrackedCompletionCallback> send_callback_; + scoped_refptr< ::ppapi::TrackedCallback> recv_callback_; + scoped_refptr< ::ppapi::TrackedCallback> send_callback_; DISALLOW_COPY_AND_ASSIGN(PPB_Transport_Impl); }; diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.cc b/webkit/plugins/ppapi/ppb_url_loader_impl.cc index d989fcd..9b96b8a 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.cc @@ -36,6 +36,7 @@ using ppapi::Resource; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_URLLoader_API; using ppapi::thunk::PPB_URLRequestInfo_API; +using ppapi::TrackedCallback; using WebKit::WebFrame; using WebKit::WebString; using WebKit::WebURL; @@ -317,7 +318,7 @@ void PPB_URLLoader_Impl::didReceiveData(WebURLLoader* loader, if (user_buffer_) { RunCallback(FillUserBuffer()); } else { - DCHECK(!pending_callback_.get() || pending_callback_->completed()); + DCHECK(!TrackedCallback::IsPending(pending_callback_)); } // To avoid letting the network stack download an entire stream all at once, @@ -374,7 +375,7 @@ void PPB_URLLoader_Impl::FinishLoading(int32_t done_status) { // If the client hasn't called any function that takes a callback since // the initial call to Open, or called ReadResponseBody and got a // synchronous return, then the callback will be NULL. - if (pending_callback_.get() && !pending_callback_->completed()) + if (TrackedCallback::IsPending(pending_callback_)) RunCallback(done_status_); } @@ -383,7 +384,7 @@ int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) { if (!callback.func) return PP_ERROR_BLOCKS_MAIN_THREAD; - if (pending_callback_.get() && !pending_callback_->completed()) + if (TrackedCallback::IsPending(pending_callback_)) return PP_ERROR_INPROGRESS; return PP_OK; @@ -391,14 +392,13 @@ int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) { void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) { DCHECK(callback.func); - DCHECK(!pending_callback_.get() || pending_callback_->completed()); + DCHECK(!TrackedCallback::IsPending(pending_callback_)); PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); if (!plugin_module) return; - pending_callback_ = new TrackedCompletionCallback( - plugin_module->GetCallbackTracker(), pp_resource(), callback); + pending_callback_ = new TrackedCallback(this, callback); } void PPB_URLLoader_Impl::RunCallback(int32_t result) { @@ -407,10 +407,7 @@ void PPB_URLLoader_Impl::RunCallback(int32_t result) { CHECK(main_document_loader_); return; } - - scoped_refptr<TrackedCompletionCallback> callback; - callback.swap(pending_callback_); - callback->Run(result); // Will complete abortively if necessary. + TrackedCallback::ClearAndRun(&pending_callback_, result); } size_t PPB_URLLoader_Impl::FillUserBuffer() { diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.h b/webkit/plugins/ppapi/ppb_url_loader_impl.h index 326568e..948f928 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.h +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.h @@ -13,9 +13,9 @@ #include "ppapi/c/trusted/ppb_url_loader_trusted.h" #include "ppapi/shared_impl/ppb_url_request_info_shared.h" #include "ppapi/shared_impl/resource.h" +#include "ppapi/shared_impl/tracked_callback.h" #include "ppapi/thunk/ppb_url_loader_api.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLLoaderClient.h" -#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" namespace WebKit { @@ -140,7 +140,7 @@ class PPB_URLLoader_Impl : public ::ppapi::Resource, scoped_ptr<WebKit::WebURLLoader> loader_; scoped_refptr<PPB_URLResponseInfo_Impl> response_info_; - scoped_refptr<TrackedCompletionCallback> pending_callback_; + scoped_refptr< ::ppapi::TrackedCallback> pending_callback_; std::deque<char> buffer_; int64_t bytes_sent_; int64_t total_bytes_to_be_sent_; |