| Index: chrome/browser/renderer_host/text_input_client_mac.mm
|
| diff --git a/chrome/browser/renderer_host/text_input_client_mac.mm b/chrome/browser/renderer_host/text_input_client_mac.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5869d8437bf8ecdf4548f71d94cd2c7555f941ed
|
| --- /dev/null
|
| +++ b/chrome/browser/renderer_host/text_input_client_mac.mm
|
| @@ -0,0 +1,94 @@
|
| +// 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.
|
| +
|
| +#import "chrome/browser/renderer_host/text_input_client_mac.h"
|
| +
|
| +#include "base/metrics/histogram.h"
|
| +#include "base/singleton.h"
|
| +#include "base/time.h"
|
| +
|
| +// The amount of time in milliseconds that the browser process will wait for a
|
| +// response from the renderer.
|
| +// TODO(rsesek): Using the histogram data, find the best upper-bound for this
|
| +// value.
|
| +const float kWaitTimeout = 1500;
|
| +
|
| +TextInputClientMac::TextInputClientMac()
|
| + : character_index_(NSNotFound),
|
| + lock_(),
|
| + condition_(&lock_) {
|
| +}
|
| +
|
| +// static
|
| +TextInputClientMac* TextInputClientMac::GetInstance() {
|
| + return Singleton<TextInputClientMac>::get();
|
| +}
|
| +
|
| +void TextInputClientMac::BeforeRequest() {
|
| + lock_.Acquire();
|
| + character_index_ = NSNotFound;
|
| + first_rect_ = NSZeroRect;
|
| + substring_.reset();
|
| +}
|
| +
|
| +void TextInputClientMac::AfterRequest() {
|
| + lock_.Release();
|
| +}
|
| +
|
| +NSUInteger TextInputClientMac::WaitForCharacterIndex() {
|
| + base::TimeTicks start = base::TimeTicks::Now();
|
| +
|
| + condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
|
| +
|
| + base::TimeDelta delta(base::TimeTicks::Now() - start);
|
| + UMA_HISTOGRAM_TIMES("TextInputClientMac.CharacterIndex",
|
| + delta * base::Time::kMicrosecondsPerMillisecond);
|
| +
|
| + return character_index_;
|
| +}
|
| +
|
| +NSRect TextInputClientMac::WaitForFirstRect() {
|
| + base::TimeTicks start = base::TimeTicks::Now();
|
| +
|
| + condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
|
| +
|
| + base::TimeDelta delta(base::TimeTicks::Now() - start);
|
| + UMA_HISTOGRAM_TIMES("TextInputClientMac.FirstRect",
|
| + delta * base::Time::kMicrosecondsPerMillisecond);
|
| +
|
| + return first_rect_;
|
| +}
|
| +
|
| +NSAttributedString* TextInputClientMac::WaitForSubstring() {
|
| + base::TimeTicks start = base::TimeTicks::Now();
|
| +
|
| + condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
|
| +
|
| + base::TimeDelta delta(base::TimeTicks::Now() - start);
|
| + UMA_HISTOGRAM_TIMES("TextInputClientMac.Substring",
|
| + delta * base::Time::kMicrosecondsPerMillisecond);
|
| +
|
| + return substring_.get();
|
| +}
|
| +
|
| +void TextInputClientMac::SetCharacterIndexAndSignal(NSUInteger index) {
|
| + lock_.Acquire();
|
| + character_index_ = index;
|
| + lock_.Release();
|
| + condition_.Signal();
|
| +}
|
| +
|
| +void TextInputClientMac::SetFirstRectAndSignal(NSRect first_rect) {
|
| + lock_.Acquire();
|
| + first_rect_ = first_rect;
|
| + lock_.Release();
|
| + condition_.Signal();
|
| +}
|
| +
|
| +void TextInputClientMac::SetSubstringAndSignal(NSAttributedString* string) {
|
| + lock_.Acquire();
|
| + substring_.reset([string copy]);
|
| + lock_.Release();
|
| + condition_.Signal();
|
| +}
|
|
|