| 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/threading/thread_restrictions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 85 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
| 86 AfterRequest(); | 86 AfterRequest(); |
| 87 | 87 |
| 88 base::TimeDelta delta(base::TimeTicks::Now() - start); | 88 base::TimeDelta delta(base::TimeTicks::Now() - start); |
| 89 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect", | 89 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect", |
| 90 delta * base::Time::kMicrosecondsPerMillisecond); | 90 delta * base::Time::kMicrosecondsPerMillisecond); |
| 91 | 91 |
| 92 return first_rect_; | 92 return first_rect_; |
| 93 } | 93 } |
| 94 | 94 |
| 95 NSAttributedString* TextInputClientMac::GetAttributedSubstringFromRange( | |
| 96 RenderWidgetHost* rwh, | |
| 97 NSRange range) { | |
| 98 base::TimeTicks start = base::TimeTicks::Now(); | |
| 99 | |
| 100 BeforeRequest(); | |
| 101 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | |
| 102 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), | |
| 103 gfx::Range(range))); | |
| 104 // http://crbug.com/121917 | |
| 105 base::ThreadRestrictions::ScopedAllowWait allow_wait; | |
| 106 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | |
| 107 AfterRequest(); | |
| 108 | |
| 109 base::TimeDelta delta(base::TimeTicks::Now() - start); | |
| 110 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.Substring", | |
| 111 delta * base::Time::kMicrosecondsPerMillisecond); | |
| 112 | |
| 113 // Lookup.framework calls this method repeatedly and expects that repeated | |
| 114 // calls don't deallocate previous results immediately. Returning an | |
| 115 // autoreleased string is better convention anyway. | |
| 116 return [[substring_.get() retain] autorelease]; | |
| 117 } | |
| 118 | |
| 119 void TextInputClientMac::SetCharacterIndexAndSignal(NSUInteger index) { | 95 void TextInputClientMac::SetCharacterIndexAndSignal(NSUInteger index) { |
| 120 lock_.Acquire(); | 96 lock_.Acquire(); |
| 121 character_index_ = index; | 97 character_index_ = index; |
| 122 lock_.Release(); | 98 lock_.Release(); |
| 123 condition_.Signal(); | 99 condition_.Signal(); |
| 124 } | 100 } |
| 125 | 101 |
| 126 void TextInputClientMac::SetFirstRectAndSignal(NSRect first_rect) { | 102 void TextInputClientMac::SetFirstRectAndSignal(NSRect first_rect) { |
| 127 lock_.Acquire(); | 103 lock_.Acquire(); |
| 128 first_rect_ = first_rect; | 104 first_rect_ = first_rect; |
| 129 lock_.Release(); | 105 lock_.Release(); |
| 130 condition_.Signal(); | 106 condition_.Signal(); |
| 131 } | 107 } |
| 132 | 108 |
| 133 void TextInputClientMac::SetSubstringAndSignal(NSAttributedString* string) { | |
| 134 lock_.Acquire(); | |
| 135 substring_.reset([string copy]); | |
| 136 lock_.Release(); | |
| 137 condition_.Signal(); | |
| 138 } | |
| 139 | |
| 140 void TextInputClientMac::BeforeRequest() { | 109 void TextInputClientMac::BeforeRequest() { |
| 141 base::TimeTicks start = base::TimeTicks::Now(); | 110 base::TimeTicks start = base::TimeTicks::Now(); |
| 142 | 111 |
| 143 lock_.Acquire(); | 112 lock_.Acquire(); |
| 144 | 113 |
| 145 base::TimeDelta delta(base::TimeTicks::Now() - start); | 114 base::TimeDelta delta(base::TimeTicks::Now() - start); |
| 146 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.LockWait", | 115 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.LockWait", |
| 147 delta * base::Time::kMicrosecondsPerMillisecond); | 116 delta * base::Time::kMicrosecondsPerMillisecond); |
| 148 | 117 |
| 149 character_index_ = NSNotFound; | 118 character_index_ = NSNotFound; |
| 150 first_rect_ = NSZeroRect; | 119 first_rect_ = NSZeroRect; |
| 151 substring_.reset(); | |
| 152 } | 120 } |
| 153 | 121 |
| 154 void TextInputClientMac::AfterRequest() { | 122 void TextInputClientMac::AfterRequest() { |
| 155 lock_.Release(); | 123 lock_.Release(); |
| 156 } | 124 } |
| 157 | 125 |
| 158 } // namespace content | 126 } // namespace content |
| OLD | NEW |