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 #import "content/browser/renderer_host/text_input_client_mac.h" | 5 #import "content/browser/renderer_host/text_input_client_mac.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/threading/thread_restrictions.h" |
9 #include "base/time.h" | 10 #include "base/time.h" |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
11 #include "content/common/text_input_client_messages.h" | 12 #include "content/common/text_input_client_messages.h" |
12 | 13 |
13 using content::RenderWidgetHost; | 14 using content::RenderWidgetHost; |
14 using content::RenderWidgetHostImpl; | 15 using content::RenderWidgetHostImpl; |
15 | 16 |
16 // The amount of time in milliseconds that the browser process will wait for a | 17 // The amount of time in milliseconds that the browser process will wait for a |
17 // response from the renderer. | 18 // response from the renderer. |
18 // TODO(rsesek): Using the histogram data, find the best upper-bound for this | 19 // TODO(rsesek): Using the histogram data, find the best upper-bound for this |
(...skipping 15 matching lines...) Expand all Loading... |
34 } | 35 } |
35 | 36 |
36 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, | 37 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, |
37 gfx::Point point) { | 38 gfx::Point point) { |
38 base::TimeTicks start = base::TimeTicks::Now(); | 39 base::TimeTicks start = base::TimeTicks::Now(); |
39 | 40 |
40 BeforeRequest(); | 41 BeforeRequest(); |
41 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 42 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
42 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), | 43 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), |
43 point)); | 44 point)); |
| 45 // http://crbug.com/121917 |
| 46 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
44 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 47 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
45 AfterRequest(); | 48 AfterRequest(); |
46 | 49 |
47 base::TimeDelta delta(base::TimeTicks::Now() - start); | 50 base::TimeDelta delta(base::TimeTicks::Now() - start); |
48 UMA_HISTOGRAM_TIMES("TextInputClient.CharacterIndex", | 51 UMA_HISTOGRAM_TIMES("TextInputClient.CharacterIndex", |
49 delta * base::Time::kMicrosecondsPerMillisecond); | 52 delta * base::Time::kMicrosecondsPerMillisecond); |
50 | 53 |
51 return character_index_; | 54 return character_index_; |
52 } | 55 } |
53 | 56 |
54 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, | 57 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, |
55 NSRange range) { | 58 NSRange range) { |
56 base::TimeTicks start = base::TimeTicks::Now(); | 59 base::TimeTicks start = base::TimeTicks::Now(); |
57 | 60 |
58 BeforeRequest(); | 61 BeforeRequest(); |
59 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 62 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
60 rwhi->Send( | 63 rwhi->Send( |
61 new TextInputClientMsg_FirstRectForCharacterRange(rwhi->GetRoutingID(), | 64 new TextInputClientMsg_FirstRectForCharacterRange(rwhi->GetRoutingID(), |
62 ui::Range(range))); | 65 ui::Range(range))); |
| 66 // http://crbug.com/121917 |
| 67 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
63 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 68 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
64 AfterRequest(); | 69 AfterRequest(); |
65 | 70 |
66 base::TimeDelta delta(base::TimeTicks::Now() - start); | 71 base::TimeDelta delta(base::TimeTicks::Now() - start); |
67 UMA_HISTOGRAM_TIMES("TextInputClient.FirstRect", | 72 UMA_HISTOGRAM_TIMES("TextInputClient.FirstRect", |
68 delta * base::Time::kMicrosecondsPerMillisecond); | 73 delta * base::Time::kMicrosecondsPerMillisecond); |
69 | 74 |
70 return first_rect_; | 75 return first_rect_; |
71 } | 76 } |
72 | 77 |
73 NSAttributedString* TextInputClientMac::GetAttributedSubstringFromRange( | 78 NSAttributedString* TextInputClientMac::GetAttributedSubstringFromRange( |
74 RenderWidgetHost* rwh, | 79 RenderWidgetHost* rwh, |
75 NSRange range) { | 80 NSRange range) { |
76 base::TimeTicks start = base::TimeTicks::Now(); | 81 base::TimeTicks start = base::TimeTicks::Now(); |
77 | 82 |
78 BeforeRequest(); | 83 BeforeRequest(); |
79 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 84 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
80 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), | 85 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), |
81 ui::Range(range))); | 86 ui::Range(range))); |
| 87 // http://crbug.com/121917 |
| 88 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
82 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 89 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
83 AfterRequest(); | 90 AfterRequest(); |
84 | 91 |
85 base::TimeDelta delta(base::TimeTicks::Now() - start); | 92 base::TimeDelta delta(base::TimeTicks::Now() - start); |
86 UMA_HISTOGRAM_TIMES("TextInputClient.Substring", | 93 UMA_HISTOGRAM_TIMES("TextInputClient.Substring", |
87 delta * base::Time::kMicrosecondsPerMillisecond); | 94 delta * base::Time::kMicrosecondsPerMillisecond); |
88 | 95 |
89 // Lookup.framework calls this method repeatedly and expects that repeated | 96 // Lookup.framework calls this method repeatedly and expects that repeated |
90 // calls don't deallocate previous results immediately. Returning an | 97 // calls don't deallocate previous results immediately. Returning an |
91 // autoreleased string is better convention anyway. | 98 // autoreleased string is better convention anyway. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 delta * base::Time::kMicrosecondsPerMillisecond); | 130 delta * base::Time::kMicrosecondsPerMillisecond); |
124 | 131 |
125 character_index_ = NSNotFound; | 132 character_index_ = NSNotFound; |
126 first_rect_ = NSZeroRect; | 133 first_rect_ = NSZeroRect; |
127 substring_.reset(); | 134 substring_.reset(); |
128 } | 135 } |
129 | 136 |
130 void TextInputClientMac::AfterRequest() { | 137 void TextInputClientMac::AfterRequest() { |
131 lock_.Release(); | 138 lock_.Release(); |
132 } | 139 } |
OLD | NEW |