blob: e52a13f3c70f60989355e65f00a349d80b9cd82f [file] [log] [blame]
Ben Chanc46c4552013-06-10 18:55:13 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef MIST_CONFIG_LOADER_H_
6#define MIST_CONFIG_LOADER_H_
7
8#include <base/basictypes.h>
9#include <base/file_path.h>
10#include <base/memory/scoped_ptr.h>
11#include <gtest/gtest_prod.h>
12
13namespace mist {
14
15class Config;
16class UsbModemInfo;
17
18// A configuration file loader, which loads information about USB modems
19// supported by mist from a configuration file based on the text format of
20// protocol buffers. The protocol buffers for the configuration file are defined
21// in proto/*.proto.
22class ConfigLoader {
23 public:
24 ConfigLoader();
Ben Chan42065c52013-06-14 17:41:10 -070025 virtual ~ConfigLoader();
Ben Chanc46c4552013-06-10 18:55:13 -070026
Ben Chan866571e2013-06-12 18:06:20 -070027 // Loads the default configuration. Returns true on success.
Ben Chan42065c52013-06-14 17:41:10 -070028 virtual bool LoadDefaultConfig();
Ben Chan866571e2013-06-12 18:06:20 -070029
Ben Chanc46c4552013-06-10 18:55:13 -070030 // Loads a configuration from |config_file|. Returns true on success.
Ben Chan42065c52013-06-14 17:41:10 -070031 virtual bool LoadConfig(const base::FilePath& config_file);
Ben Chanc46c4552013-06-10 18:55:13 -070032
33 // Returns the info of the USB modem with its vendor ID equal to |vendor_id|
34 // and its product ID equal to |product_id| from the loaded configuration.
35 // Returns NULL if no matching USB modem is found. The returned UsbModemInfo
36 // object becomes invalid, and thus should not be held, beyond the lifetime
37 // of the loaded configuration held by |config_|.
Ben Chan42065c52013-06-14 17:41:10 -070038 virtual const UsbModemInfo* GetUsbModemInfo(uint16 vendor_id,
39 uint16 product_id) const;
Ben Chanc46c4552013-06-10 18:55:13 -070040
41 private:
42 FRIEND_TEST(ConfigLoaderTest, GetUsbModemInfo);
43 FRIEND_TEST(ConfigLoaderTest, LoadEmptyConfigFile);
44 FRIEND_TEST(ConfigLoaderTest, LoadInvalidConfigFile);
45 FRIEND_TEST(ConfigLoaderTest, LoadNonExistentConfigFile);
46 FRIEND_TEST(ConfigLoaderTest, LoadValidConfigFile);
47
48 scoped_ptr<Config> config_;
49
50 DISALLOW_COPY_AND_ASSIGN(ConfigLoader);
51};
52
53} // namespace mist
54
55#endif // MIST_CONFIG_LOADER_H_