7945138b453b9fadd959ef1d8fed11c698dc9728
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / common / xwalk_runtime_features.h
1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_RUNTIME_COMMON_XWALK_RUNTIME_FEATURES_H_
6 #define XWALK_RUNTIME_COMMON_XWALK_RUNTIME_FEATURES_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/command_line.h"
12 #include "base/memory/singleton.h"
13
14 namespace xwalk {
15
16 #define DECLARE_RUNTIME_FEATURE(NAME) static bool is ##NAME## Enabled() \
17   { return GetInstance()->isFeatureEnabled( #NAME ); }
18
19 class XWalkRuntimeFeatures {
20  public:
21   // Declare new features here and and define them in xwalk_runtime_features.cc.
22   DECLARE_RUNTIME_FEATURE(SysApps);
23   DECLARE_RUNTIME_FEATURE(RawSocketsAPI);
24   DECLARE_RUNTIME_FEATURE(DeviceCapabilitiesAPI);
25   DECLARE_RUNTIME_FEATURE(StorageAPI);
26   DECLARE_RUNTIME_FEATURE(DialogAPI);
27
28   void Initialize(const CommandLine* cmd);
29   void DumpFeaturesFlags();
30   static XWalkRuntimeFeatures* GetInstance();
31
32   enum RuntimeFeatureStatus {
33     Stable,
34     Experimental
35   };
36
37
38   struct RuntimeFeature {
39     std::string name;
40     std::string description;
41     std::string command_line_switch;
42     RuntimeFeatureStatus status;
43     bool enabled;
44     RuntimeFeature() = default;
45   };
46
47  private:
48   friend struct DefaultSingletonTraits<XWalkRuntimeFeatures>;
49   XWalkRuntimeFeatures();
50   ~XWalkRuntimeFeatures();
51   void AddFeature(const char* name, const char* command_line_switch,
52                   const char* description, RuntimeFeatureStatus status);
53   bool isFeatureEnabled(const char* name) const;
54   typedef std::vector<RuntimeFeature> RuntimeFeaturesList;
55   RuntimeFeaturesList runtime_features_;
56   const CommandLine* command_line_;
57   bool initialized_;
58   bool experimental_features_enabled_;
59 };
60
61 }  // namespace xwalk
62
63 #endif  // XWALK_RUNTIME_COMMON_XWALK_RUNTIME_FEATURES_H_