| 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 #include "chrome/browser/extensions/extension_idle_api.h" | 5 #include "chrome/browser/extensions/extension_idle_api.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <string> | 9 #include <string> | 
| 10 | 10 | 
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 148       keys::kOnStateChanged, json_args, profile, GURL(), EventFilteringInfo()); | 148       keys::kOnStateChanged, json_args, profile, GURL(), EventFilteringInfo()); | 
| 149 } | 149 } | 
| 150 | 150 | 
| 151 bool ExtensionIdleQueryStateFunction::RunImpl() { | 151 bool ExtensionIdleQueryStateFunction::RunImpl() { | 
| 152   int threshold; | 152   int threshold; | 
| 153   EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold)); | 153   EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold)); | 
| 154   threshold = CheckThresholdBounds(threshold); | 154   threshold = CheckThresholdBounds(threshold); | 
| 155 | 155 | 
| 156   IdleState state = ExtensionIdleCache::CalculateIdleState(threshold); | 156   IdleState state = ExtensionIdleCache::CalculateIdleState(threshold); | 
| 157   if (state != IDLE_STATE_UNKNOWN) { | 157   if (state != IDLE_STATE_UNKNOWN) { | 
| 158     result_.reset(CreateIdleValue(state)); | 158     SetResult(CreateIdleValue(state)); | 
| 159     SendResponse(true); | 159     SendResponse(true); | 
| 160     return true; | 160     return true; | 
| 161   } | 161   } | 
| 162 | 162 | 
| 163   CalculateIdleState(threshold, | 163   CalculateIdleState(threshold, | 
| 164       base::Bind(&ExtensionIdleQueryStateFunction::IdleStateCallback, | 164       base::Bind(&ExtensionIdleQueryStateFunction::IdleStateCallback, | 
| 165                  this, threshold)); | 165                  this, threshold)); | 
| 166   // Don't send the response, it'll be sent by our callback | 166   // Don't send the response, it'll be sent by our callback | 
| 167   return true; | 167   return true; | 
| 168 } | 168 } | 
| 169 | 169 | 
| 170 void ExtensionIdleQueryStateFunction::IdleStateCallback(int threshold, | 170 void ExtensionIdleQueryStateFunction::IdleStateCallback(int threshold, | 
| 171                                                         IdleState state) { | 171                                                         IdleState state) { | 
| 172   // If our state is not active, make sure we're running a polling task to check | 172   // If our state is not active, make sure we're running a polling task to check | 
| 173   // for active state and report it when it changes to active. | 173   // for active state and report it when it changes to active. | 
| 174   if (state != IDLE_STATE_ACTIVE) { | 174   if (state != IDLE_STATE_ACTIVE) { | 
| 175     ExtensionIdlePollingTask::CreateNewPollTask(threshold, state, profile_); | 175     ExtensionIdlePollingTask::CreateNewPollTask(threshold, state, profile_); | 
| 176   } | 176   } | 
| 177 | 177 | 
| 178   result_.reset(CreateIdleValue(state)); | 178   SetResult(CreateIdleValue(state)); | 
| 179 | 179 | 
| 180   ExtensionIdleCache::UpdateCache(threshold, state); | 180   ExtensionIdleCache::UpdateCache(threshold, state); | 
| 181 | 181 | 
| 182   SendResponse(true); | 182   SendResponse(true); | 
| 183 } | 183 } | 
| 184 | 184 | 
| 185 ExtensionIdleCache::CacheData ExtensionIdleCache::cached_data = | 185 ExtensionIdleCache::CacheData ExtensionIdleCache::cached_data = | 
| 186     {-1, -1, -1, -1}; | 186     {-1, -1, -1, -1}; | 
| 187 | 187 | 
| 188 IdleState ExtensionIdleCache::CalculateIdleState(int threshold) { | 188 IdleState ExtensionIdleCache::CalculateIdleState(int threshold) { | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 262   } | 262   } | 
| 263 } | 263 } | 
| 264 | 264 | 
| 265 int ExtensionIdleCache::get_min_threshold() { | 265 int ExtensionIdleCache::get_min_threshold() { | 
| 266   return kMinThreshold; | 266   return kMinThreshold; | 
| 267 } | 267 } | 
| 268 | 268 | 
| 269 double ExtensionIdleCache::get_throttle_interval() { | 269 double ExtensionIdleCache::get_throttle_interval() { | 
| 270   return static_cast<double>(kThrottleInterval); | 270   return static_cast<double>(kThrottleInterval); | 
| 271 } | 271 } | 
| OLD | NEW | 
|---|