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

Side by Side Diff: chrome/browser/extensions/extension_idle_api.cc

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and review changes. Created 8 years, 5 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 | Annotate | Revision Log
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 #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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (timeout < kMinThreshold) return kMinThreshold; 132 if (timeout < kMinThreshold) return kMinThreshold;
133 if (timeout > kMaxThreshold) return kMaxThreshold; 133 if (timeout > kMaxThreshold) return kMaxThreshold;
134 return timeout; 134 return timeout;
135 } 135 }
136 136
137 }; // namespace 137 }; // namespace
138 138
139 void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile, 139 void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile,
140 IdleState state) { 140 IdleState state) {
141 // Prepare the single argument of the current state. 141 // Prepare the single argument of the current state.
142 ListValue args; 142 ListValue* args = new ListValue();
143 args.Append(CreateIdleValue(state)); 143 args->Append(CreateIdleValue(state));
144 std::string json_args;
145 base::JSONWriter::Write(&args, &json_args);
146 144
147 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 145 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
148 keys::kOnStateChanged, json_args, profile, GURL(), EventFilteringInfo()); 146 keys::kOnStateChanged, args, profile, GURL(), EventFilteringInfo());
149 } 147 }
150 148
151 bool ExtensionIdleQueryStateFunction::RunImpl() { 149 bool ExtensionIdleQueryStateFunction::RunImpl() {
152 int threshold; 150 int threshold;
153 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold)); 151 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
154 threshold = CheckThresholdBounds(threshold); 152 threshold = CheckThresholdBounds(threshold);
155 153
156 IdleState state = ExtensionIdleCache::CalculateIdleState(threshold); 154 IdleState state = ExtensionIdleCache::CalculateIdleState(threshold);
157 if (state != IDLE_STATE_UNKNOWN) { 155 if (state != IDLE_STATE_UNKNOWN) {
158 result_.reset(CreateIdleValue(state)); 156 result_.reset(CreateIdleValue(state));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 260 }
263 } 261 }
264 262
265 int ExtensionIdleCache::get_min_threshold() { 263 int ExtensionIdleCache::get_min_threshold() {
266 return kMinThreshold; 264 return kMinThreshold;
267 } 265 }
268 266
269 double ExtensionIdleCache::get_throttle_interval() { 267 double ExtensionIdleCache::get_throttle_interval() {
270 return static_cast<double>(kThrottleInterval); 268 return static_cast<double>(kThrottleInterval);
271 } 269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698