Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: content/browser/renderer_host/text_input_client_mac.mm

Issue 1326763003: Clean up the useless GetAttributedSubstringFromRange() and the related IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 void (^reply_handler)(NSAttributedString*, NSPoint)) { 57 void (^reply_handler)(NSAttributedString*, NSPoint)) {
58 DCHECK(replyForRangeHandler_.get() == nil); 58 DCHECK(replyForRangeHandler_.get() == nil);
59 replyForRangeHandler_.reset(reply_handler, base::scoped_policy::RETAIN); 59 replyForRangeHandler_.reset(reply_handler, base::scoped_policy::RETAIN);
60 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 60 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
61 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), 61 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(),
62 gfx::Range(range))); 62 gfx::Range(range)));
63 } 63 }
64 64
65 void TextInputClientMac::GetStringFromRangeReply(NSAttributedString* string, 65 void TextInputClientMac::GetStringFromRangeReply(NSAttributedString* string,
66 NSPoint point) { 66 NSPoint point) {
67 SetSubstringAndSignal(string);
68 if (replyForRangeHandler_.get()) { 67 if (replyForRangeHandler_.get()) {
69 replyForRangeHandler_.get()(string, point); 68 replyForRangeHandler_.get()(string, point);
70 replyForRangeHandler_.reset(); 69 replyForRangeHandler_.reset();
71 } 70 }
72 } 71 }
73 72
74 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, 73 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh,
75 gfx::Point point) { 74 gfx::Point point) {
76 base::TimeTicks start = base::TimeTicks::Now(); 75 base::TimeTicks start = base::TimeTicks::Now();
77 76
(...skipping 27 matching lines...) Expand all
105 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); 104 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
106 AfterRequest(); 105 AfterRequest();
107 106
108 base::TimeDelta delta(base::TimeTicks::Now() - start); 107 base::TimeDelta delta(base::TimeTicks::Now() - start);
109 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect", 108 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.FirstRect",
110 delta * base::Time::kMicrosecondsPerMillisecond); 109 delta * base::Time::kMicrosecondsPerMillisecond);
111 110
112 return first_rect_; 111 return first_rect_;
113 } 112 }
114 113
115 NSAttributedString* TextInputClientMac::GetAttributedSubstringFromRange(
116 RenderWidgetHost* rwh,
117 NSRange range) {
118 base::TimeTicks start = base::TimeTicks::Now();
119
120 BeforeRequest();
121 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
122 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(),
123 gfx::Range(range)));
124 // http://crbug.com/121917
125 base::ThreadRestrictions::ScopedAllowWait allow_wait;
126 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
127 AfterRequest();
128
129 base::TimeDelta delta(base::TimeTicks::Now() - start);
130 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.Substring",
131 delta * base::Time::kMicrosecondsPerMillisecond);
132
133 // Lookup.framework calls this method repeatedly and expects that repeated
134 // calls don't deallocate previous results immediately. Returning an
135 // autoreleased string is better convention anyway.
136 return [[substring_.get() retain] autorelease];
137 }
138
139 void TextInputClientMac::SetCharacterIndexAndSignal(NSUInteger index) { 114 void TextInputClientMac::SetCharacterIndexAndSignal(NSUInteger index) {
140 lock_.Acquire(); 115 lock_.Acquire();
141 character_index_ = index; 116 character_index_ = index;
142 lock_.Release(); 117 lock_.Release();
143 condition_.Signal(); 118 condition_.Signal();
144 } 119 }
145 120
146 void TextInputClientMac::SetFirstRectAndSignal(NSRect first_rect) { 121 void TextInputClientMac::SetFirstRectAndSignal(NSRect first_rect) {
147 lock_.Acquire(); 122 lock_.Acquire();
148 first_rect_ = first_rect; 123 first_rect_ = first_rect;
149 lock_.Release(); 124 lock_.Release();
150 condition_.Signal(); 125 condition_.Signal();
151 } 126 }
152 127
153 void TextInputClientMac::SetSubstringAndSignal(NSAttributedString* string) {
154 lock_.Acquire();
155 substring_.reset([string copy]);
156 lock_.Release();
157 condition_.Signal();
158 }
159
160 void TextInputClientMac::BeforeRequest() { 128 void TextInputClientMac::BeforeRequest() {
161 base::TimeTicks start = base::TimeTicks::Now(); 129 base::TimeTicks start = base::TimeTicks::Now();
162 130
163 lock_.Acquire(); 131 lock_.Acquire();
164 132
165 base::TimeDelta delta(base::TimeTicks::Now() - start); 133 base::TimeDelta delta(base::TimeTicks::Now() - start);
166 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.LockWait", 134 UMA_HISTOGRAM_LONG_TIMES("TextInputClient.LockWait",
167 delta * base::Time::kMicrosecondsPerMillisecond); 135 delta * base::Time::kMicrosecondsPerMillisecond);
168 136
169 character_index_ = NSNotFound; 137 character_index_ = NSNotFound;
170 first_rect_ = NSZeroRect; 138 first_rect_ = NSZeroRect;
171 substring_.reset();
172 } 139 }
173 140
174 void TextInputClientMac::AfterRequest() { 141 void TextInputClientMac::AfterRequest() {
175 lock_.Release(); 142 lock_.Release();
176 } 143 }
177 144
178 } // namespace content 145 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/text_input_client_mac.h ('k') | content/browser/renderer_host/text_input_client_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698