Commit 22677ea5 authored by yzshen@chromium.org's avatar yzshen@chromium.org

Make sure ppapi::WebKitForwarding::Font is deleted on the WebKit thread.

We need to do so because we now have asserts which make sure ref/deref of RefCounted happen on the right thread.

TEST=None
BUG=None


Review URL: http://codereview.chromium.org/7629006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96595 0039d316-1c4b-4281-b951-d872f2087c98
parent 893857a0
...@@ -101,17 +101,17 @@ Font::Font(const HostResource& resource, ...@@ -101,17 +101,17 @@ Font::Font(const HostResource& resource,
WebKitForwarding* forwarding = GetDispatcher()->GetWebKitForwarding(); WebKitForwarding* forwarding = GetDispatcher()->GetWebKitForwarding();
WebKitForwarding::Font* result = NULL; RunOnWebKitThread(true,
RunOnWebKitThread(base::Bind(&WebKitForwarding::CreateFontForwarding, base::Bind(&WebKitForwarding::CreateFontForwarding,
base::Unretained(forwarding), base::Unretained(forwarding),
&webkit_event_, desc, &webkit_event_, desc,
face.get() ? face->value() : std::string(), face.get() ? face->value() : std::string(),
GetDispatcher()->preferences(), GetDispatcher()->preferences(),
&result)); &font_forwarding_));
font_forwarding_.reset(result);
} }
Font::~Font() { Font::~Font() {
RunOnWebKitThread(false, base::Bind(&DeleteFontForwarding, font_forwarding_));
} }
ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() { ppapi::thunk::PPB_Font_API* Font::AsPPB_Font_API() {
...@@ -127,8 +127,9 @@ PP_Bool Font::Describe(PP_FontDescription_Dev* description, ...@@ -127,8 +127,9 @@ PP_Bool Font::Describe(PP_FontDescription_Dev* description,
TRACE_EVENT0("ppapi proxy", "Font::Describe"); TRACE_EVENT0("ppapi proxy", "Font::Describe");
std::string face; std::string face;
PP_Bool result = PP_FALSE; PP_Bool result = PP_FALSE;
RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::Describe, RunOnWebKitThread(true,
base::Unretained(font_forwarding_.get()), base::Bind(&WebKitForwarding::Font::Describe,
base::Unretained(font_forwarding_),
&webkit_event_, description, &face, metrics, &webkit_event_, description, &face, metrics,
&result)); &result));
...@@ -168,12 +169,13 @@ PP_Bool Font::DrawTextAt(PP_Resource pp_image_data, ...@@ -168,12 +169,13 @@ PP_Bool Font::DrawTextAt(PP_Resource pp_image_data,
image_data->Unmap(); image_data->Unmap();
return PP_FALSE; return PP_FALSE;
} }
RunOnWebKitThread(base::Bind( RunOnWebKitThread(
&WebKitForwarding::Font::DrawTextAt, true,
base::Unretained(font_forwarding_.get()), base::Bind(&WebKitForwarding::Font::DrawTextAt,
&webkit_event_, base::Unretained(font_forwarding_), &webkit_event_,
WebKitForwarding::Font::DrawTextParams(canvas, run, position, color, WebKitForwarding::Font::DrawTextParams(canvas, run, position,
clip, image_data_is_opaque))); color, clip,
image_data_is_opaque)));
if (needs_unmapping) if (needs_unmapping)
image_data->Unmap(); image_data->Unmap();
...@@ -186,8 +188,9 @@ int32_t Font::MeasureText(const PP_TextRun_Dev* text) { ...@@ -186,8 +188,9 @@ int32_t Font::MeasureText(const PP_TextRun_Dev* text) {
if (!PPTextRunToTextRun(text, &run)) if (!PPTextRunToTextRun(text, &run))
return -1; return -1;
int32_t result = -1; int32_t result = -1;
RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::MeasureText, RunOnWebKitThread(true,
base::Unretained(font_forwarding_.get()), base::Bind(&WebKitForwarding::Font::MeasureText,
base::Unretained(font_forwarding_),
&webkit_event_, run, &result)); &webkit_event_, run, &result));
return result; return result;
} }
...@@ -199,8 +202,9 @@ uint32_t Font::CharacterOffsetForPixel(const PP_TextRun_Dev* text, ...@@ -199,8 +202,9 @@ uint32_t Font::CharacterOffsetForPixel(const PP_TextRun_Dev* text,
if (!PPTextRunToTextRun(text, &run)) if (!PPTextRunToTextRun(text, &run))
return -1; return -1;
uint32_t result = -1; uint32_t result = -1;
RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::CharacterOffsetForPixel, RunOnWebKitThread(true,
base::Unretained(font_forwarding_.get()), base::Bind(&WebKitForwarding::Font::CharacterOffsetForPixel,
base::Unretained(font_forwarding_),
&webkit_event_, run, pixel_position, &result)); &webkit_event_, run, pixel_position, &result));
return result; return result;
} }
...@@ -212,15 +216,23 @@ int32_t Font::PixelOffsetForCharacter(const PP_TextRun_Dev* text, ...@@ -212,15 +216,23 @@ int32_t Font::PixelOffsetForCharacter(const PP_TextRun_Dev* text,
if (!PPTextRunToTextRun(text, &run)) if (!PPTextRunToTextRun(text, &run))
return -1; return -1;
int32_t result = -1; int32_t result = -1;
RunOnWebKitThread(base::Bind(&WebKitForwarding::Font::PixelOffsetForCharacter, RunOnWebKitThread(true,
base::Unretained(font_forwarding_.get()), base::Bind(&WebKitForwarding::Font::PixelOffsetForCharacter,
base::Unretained(font_forwarding_),
&webkit_event_, run, char_offset, &result)); &webkit_event_, run, char_offset, &result));
return result; return result;
} }
void Font::RunOnWebKitThread(const base::Closure& task) { void Font::RunOnWebKitThread(bool blocking, const base::Closure& task) {
GetDispatcher()->PostToWebKitThread(FROM_HERE, task); GetDispatcher()->PostToWebKitThread(FROM_HERE, task);
webkit_event_.Wait(); if (blocking)
webkit_event_.Wait();
}
// static
void Font::DeleteFontForwarding(
ppapi::WebKitForwarding::Font* font_forwarding) {
delete font_forwarding;
} }
} // namespace proxy } // namespace proxy
......
...@@ -75,13 +75,20 @@ class Font : public PluginResource, ...@@ -75,13 +75,20 @@ class Font : public PluginResource,
uint32_t char_offset) OVERRIDE; uint32_t char_offset) OVERRIDE;
private: private:
// Posts the given closure to the WebKit thread and waits on the // Posts the given closure to the WebKit thread.
// webkit_event_ for the task to continue. // If |blocking| is true, the method waits on |webkit_event_| for the task to
void RunOnWebKitThread(const base::Closure& task); // continue.
void RunOnWebKitThread(bool blocking, const base::Closure& task);
static void DeleteFontForwarding(
ppapi::WebKitForwarding::Font* font_forwarding);
base::WaitableEvent webkit_event_; base::WaitableEvent webkit_event_;
scoped_ptr<ppapi::WebKitForwarding::Font> font_forwarding_; // This class owns |font_forwarding_|.
// |font_forwarding_| should always be used on the WebKit thread (including
// destruction).
ppapi::WebKitForwarding::Font* font_forwarding_;
DISALLOW_COPY_AND_ASSIGN(Font); DISALLOW_COPY_AND_ASSIGN(Font);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment