blob: e8d6a4ad4e66b61c67fc6f3d2f408a8894d09f46 [file] [log] [blame]
// 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.
#ifndef COMMON_OPTIONS_H_
#define COMMON_OPTIONS_H_
#include <map>
#include <string>
#include <vector>
#include "common/private/minimal_base.h"
template <typename T> struct DefaultSingletonTraits;
namespace arc {
// Options are key value pairs sent from JavaScript when the plugin was
// created. A lot of the options are metadata as defined in
// src/build/metadata/definitions.json. Some options are generated by
// JavaScript code.
struct Options {
// Retrieve options of various types. If name does not exist and no default
// value is provided then we abort.
bool GetBool(const std::string& name) const;
bool GetBool(const std::string& name, bool default_value) const;
double GetDouble(const std::string& name) const;
int GetInt(const std::string& name) const;
std::string GetString(const std::string& name) const;
std::string GetString(const std::string& name,
const std::string& default_value) const;
std::vector<std::string> GetStringVector(const std::string& name) const;
// Should probably only be used by instance_dispatcher and testing code.
// Some values are cached locally so changing the value here might not take
// effect after startup. Also Put is NOT thread safe with itself or any Get*
// functions. Currently we only call it early in the initialization process
// before threads are created.
void Put(const std::string& name, const std::string& value);
// Singleton
static Options* GetInstance();
private:
Options();
~Options();
friend struct DefaultSingletonTraits<Options>;
std::map<std::string, std::string> options_map_;
COMMON_DISALLOW_COPY_AND_ASSIGN(Options);
};
} // namespace arc
#endif // COMMON_OPTIONS_H_