| 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/api/idle/idle_api.h" | 5 #include "chrome/browser/extensions/api/idle/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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 if (timeout < kMinThreshold) return kMinThreshold; | 137 if (timeout < kMinThreshold) return kMinThreshold; |
| 138 if (timeout > kMaxThreshold) return kMaxThreshold; | 138 if (timeout > kMaxThreshold) return kMaxThreshold; |
| 139 return timeout; | 139 return timeout; |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace | 142 } // namespace |
| 143 | 143 |
| 144 void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile, | 144 void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile, |
| 145 IdleState state) { | 145 IdleState state) { |
| 146 // Prepare the single argument of the current state. | 146 // Prepare the single argument of the current state. |
| 147 ListValue args; | 147 scoped_ptr<ListValue> args(new ListValue()); |
| 148 args.Append(CreateIdleValue(state)); | 148 args->Append(CreateIdleValue(state)); |
| 149 std::string json_args; | |
| 150 base::JSONWriter::Write(&args, &json_args); | |
| 151 | 149 |
| 152 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 150 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 153 keys::kOnStateChanged, json_args, profile, | 151 keys::kOnStateChanged, args.Pass(), profile, |
| 154 GURL(), extensions::EventFilteringInfo()); | 152 GURL(), extensions::EventFilteringInfo()); |
| 155 } | 153 } |
| 156 | 154 |
| 157 bool ExtensionIdleQueryStateFunction::RunImpl() { | 155 bool ExtensionIdleQueryStateFunction::RunImpl() { |
| 158 int threshold; | 156 int threshold; |
| 159 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold)); | 157 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold)); |
| 160 threshold = CheckThresholdBounds(threshold); | 158 threshold = CheckThresholdBounds(threshold); |
| 161 | 159 |
| 162 IdleState state = ExtensionIdleCache::CalculateIdleState(threshold); | 160 IdleState state = ExtensionIdleCache::CalculateIdleState(threshold); |
| 163 if (state != IDLE_STATE_UNKNOWN) { | 161 if (state != IDLE_STATE_UNKNOWN) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 } | 266 } |
| 269 } | 267 } |
| 270 | 268 |
| 271 int ExtensionIdleCache::get_min_threshold() { | 269 int ExtensionIdleCache::get_min_threshold() { |
| 272 return kMinThreshold; | 270 return kMinThreshold; |
| 273 } | 271 } |
| 274 | 272 |
| 275 double ExtensionIdleCache::get_throttle_interval() { | 273 double ExtensionIdleCache::get_throttle_interval() { |
| 276 return static_cast<double>(kThrottleInterval); | 274 return static_cast<double>(kThrottleInterval); |
| 277 } | 275 } |
| OLD | NEW |