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

Side by Side Diff: chrome/browser/extensions/api/idle/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: Fixing memory leak in a test. Created 8 years, 4 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/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
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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | chrome/browser/extensions/api/input_ime/input_ime_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698