summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/id_generator_custom_bindings.cc
blob: f9c593ba7a73766f46df5a07b2292a8821efffff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/renderer/id_generator_custom_bindings.h"

#include "base/bind.h"

namespace extensions {

IdGeneratorCustomBindings::IdGeneratorCustomBindings(ScriptContext* context)
    : ObjectBackedNativeHandler(context) {
  RouteFunction("GetNextId",
                base::Bind(&IdGeneratorCustomBindings::GetNextId,
                           base::Unretained(this)));
}

void IdGeneratorCustomBindings::GetNextId(
    const v8::FunctionCallbackInfo<v8::Value>& args) {
  static int32_t next_id = 0;
  ++next_id;
  // Make sure 0 is never returned because some APIs (particularly WebRequest)
  // have special meaning for 0 IDs.
  if (next_id == 0)
    next_id = 1;
  args.GetReturnValue().Set(next_id);
}

}  // namespace extensions