| Index: chrome/browser/extensions/extension_idle_api.cc
|
| diff --git a/chrome/browser/extensions/extension_idle_api.cc b/chrome/browser/extensions/extension_idle_api.cc
|
| index 05080882587f099348727daf24d14fe7465c81e3..8df6ac84892dff692f8a462bf05c0b96435e92d1 100644
|
| --- a/chrome/browser/extensions/extension_idle_api.cc
|
| +++ b/chrome/browser/extensions/extension_idle_api.cc
|
| @@ -133,21 +133,19 @@ int CheckThresholdBounds(int timeout) {
|
| if (timeout > kMaxThreshold) return kMaxThreshold;
|
| return timeout;
|
| }
|
| -}; // namespace
|
|
|
| -void ExtensionIdleQueryStateFunction::IdleStateCallback(int threshold,
|
| - IdleState state) {
|
| - // If our state is not active, make sure we're running a polling task to check
|
| - // for active state and report it when it changes to active.
|
| - if (state != IDLE_STATE_ACTIVE) {
|
| - ExtensionIdlePollingTask::CreateNewPollTask(threshold, state, profile_);
|
| - }
|
| -
|
| - result_.reset(CreateIdleValue(state));
|
| +}; // namespace
|
|
|
| - ExtensionIdleCache::UpdateCache(threshold, state);
|
| +void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile,
|
| + IdleState state) {
|
| + // Prepare the single argument of the current state.
|
| + ListValue args;
|
| + args.Append(CreateIdleValue(state));
|
| + std::string json_args;
|
| + base::JSONWriter::Write(&args, &json_args);
|
|
|
| - SendResponse(true);
|
| + profile->GetExtensionEventRouter()->DispatchEventToRenderers(
|
| + keys::kOnStateChanged, json_args, profile, GURL());
|
| }
|
|
|
| bool ExtensionIdleQueryStateFunction::RunImpl() {
|
| @@ -169,16 +167,19 @@ bool ExtensionIdleQueryStateFunction::RunImpl() {
|
| return true;
|
| }
|
|
|
| -void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile,
|
| - IdleState state) {
|
| - // Prepare the single argument of the current state.
|
| - ListValue args;
|
| - args.Append(CreateIdleValue(state));
|
| - std::string json_args;
|
| - base::JSONWriter::Write(&args, &json_args);
|
| +void ExtensionIdleQueryStateFunction::IdleStateCallback(int threshold,
|
| + IdleState state) {
|
| + // If our state is not active, make sure we're running a polling task to check
|
| + // for active state and report it when it changes to active.
|
| + if (state != IDLE_STATE_ACTIVE) {
|
| + ExtensionIdlePollingTask::CreateNewPollTask(threshold, state, profile_);
|
| + }
|
|
|
| - profile->GetExtensionEventRouter()->DispatchEventToRenderers(
|
| - keys::kOnStateChanged, json_args, profile, GURL());
|
| + result_.reset(CreateIdleValue(state));
|
| +
|
| + ExtensionIdleCache::UpdateCache(threshold, state);
|
| +
|
| + SendResponse(true);
|
| }
|
|
|
| ExtensionIdleCache::CacheData ExtensionIdleCache::cached_data =
|
| @@ -188,6 +189,10 @@ IdleState ExtensionIdleCache::CalculateIdleState(int threshold) {
|
| return CalculateState(threshold, base::Time::Now().ToDoubleT());
|
| }
|
|
|
| +void ExtensionIdleCache::UpdateCache(int threshold, IdleState state) {
|
| + Update(threshold, state, base::Time::Now().ToDoubleT());
|
| +}
|
| +
|
| IdleState ExtensionIdleCache::CalculateState(int threshold, double now) {
|
| if (threshold < kMinThreshold)
|
| return IDLE_STATE_UNKNOWN;
|
| @@ -221,10 +226,6 @@ IdleState ExtensionIdleCache::CalculateState(int threshold, double now) {
|
| return IDLE_STATE_UNKNOWN;
|
| }
|
|
|
| -void ExtensionIdleCache::UpdateCache(int threshold, IdleState state) {
|
| - Update(threshold, state, base::Time::Now().ToDoubleT());
|
| -}
|
| -
|
| void ExtensionIdleCache::Update(int threshold, IdleState state, double now) {
|
| if (threshold < kMinThreshold)
|
| return;
|
|
|