| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/id_generator_custom_bindings.h" | 5 #include "extensions/renderer/id_generator_custom_bindings.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 | 10 |
| 9 namespace extensions { | 11 namespace extensions { |
| 10 | 12 |
| 11 IdGeneratorCustomBindings::IdGeneratorCustomBindings(ScriptContext* context) | 13 IdGeneratorCustomBindings::IdGeneratorCustomBindings(ScriptContext* context) |
| 12 : ObjectBackedNativeHandler(context) { | 14 : ObjectBackedNativeHandler(context) { |
| 13 RouteFunction("GetNextId", | 15 RouteFunction("GetNextId", |
| 14 base::Bind(&IdGeneratorCustomBindings::GetNextId, | 16 base::Bind(&IdGeneratorCustomBindings::GetNextId, |
| 15 base::Unretained(this))); | 17 base::Unretained(this))); |
| 16 } | 18 } |
| 17 | 19 |
| 18 void IdGeneratorCustomBindings::GetNextId( | 20 void IdGeneratorCustomBindings::GetNextId( |
| 19 const v8::FunctionCallbackInfo<v8::Value>& args) { | 21 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 20 static int32_t next_id = 0; | 22 static int32_t next_id = 0; |
| 21 ++next_id; | 23 ++next_id; |
| 22 // Make sure 0 is never returned because some APIs (particularly WebRequest) | 24 // Make sure 0 is never returned because some APIs (particularly WebRequest) |
| 23 // have special meaning for 0 IDs. | 25 // have special meaning for 0 IDs. |
| 24 if (next_id == 0) | 26 if (next_id == 0) |
| 25 next_id = 1; | 27 next_id = 1; |
| 26 args.GetReturnValue().Set(next_id); | 28 args.GetReturnValue().Set(next_id); |
| 27 } | 29 } |
| 28 | 30 |
| 29 } // namespace extensions | 31 } // namespace extensions |
| OLD | NEW |