15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright (c) 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This is a utility executable used for generating hashes for pepper
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// interfaces for inclusion in tools/metrics/histograms/histograms.xml. Every
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// interface-version pair must have a corresponding entry in the enum there.
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// The hashing logic here must match the hashing logic at
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// ppapi/proxy/interface_list.cc.
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <stdio.h>
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <stdlib.h>
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string.h>
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/hash.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/macros.h"
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int main(int argc, char **argv) {
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (argc < 2) {
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fprintf(stderr, "Usage: %s <interface1> <interface2> <...>\n", argv[0]);
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fprintf(stderr, "\n");
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fprintf(stderr, "Prints hashes for interface names.\n");
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    fprintf(stderr, "Example: %s \"PPB_Var;1.1\" \"PPB_FileIO;1.2\"\n",
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            argv[0]);
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return 1;
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (int i = 1; i < argc; i++) {
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    uint32 data = base::Hash(argv[i], strlen(argv[i]));
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Strip off the signed bit because UMA doesn't support negative values,
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // but takes a signed int as input.
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int hash = static_cast<int>(data & 0x7fffffff);
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    printf("<int value=\"%d\" label=\"%s\"/>\n", hash, argv[i]);
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return 0;
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
38