Roll src/third_party/WebKit b3f094a:f697bbd (svn 194310:194313)
[chromium-blink-merge.git] / extensions / common / extension_builder.h
blob4b40178b9b71b790ce00bcae139e97d4850f1ec2
1 // Copyright 2013 The Chromium 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.
5 #ifndef EXTENSIONS_COMMON_EXTENSION_BUILDER_H_
6 #define EXTENSIONS_COMMON_EXTENSION_BUILDER_H_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "extensions/common/manifest.h"
14 #include "extensions/common/value_builder.h"
16 namespace extensions {
17 class Extension;
19 // An easier way to create extensions than Extension::Create. The
20 // constructor sets up some defaults which are customized using the
21 // methods. The only method that must be called is SetManifest().
22 class ExtensionBuilder {
23 public:
24 ExtensionBuilder();
25 ~ExtensionBuilder();
27 // Can only be called once, after which it's invalid to use the builder.
28 // CHECKs that the extension was created successfully.
29 scoped_refptr<Extension> Build();
31 // Workaround to allow you to pass rvalue ExtensionBuilders by reference to
32 // other functions, e.g. UseBuilder(ExtensionBuilder().Pass())
33 ExtensionBuilder& Pass() { return *this; }
35 // Defaults to FilePath().
36 ExtensionBuilder& SetPath(const base::FilePath& path);
38 // Defaults to Manifest::UNPACKED.
39 ExtensionBuilder& SetLocation(Manifest::Location location);
41 ExtensionBuilder& SetManifest(scoped_ptr<base::DictionaryValue> manifest);
42 ExtensionBuilder& SetManifest(DictionaryBuilder& manifest_builder) {
43 return SetManifest(manifest_builder.Build());
46 // Adds the keys from the DictionaryBuilder to the manifest, with new keys
47 // taking precedence.
48 ExtensionBuilder& MergeManifest(DictionaryBuilder& builder);
50 ExtensionBuilder& AddFlags(int init_from_value_flags);
52 // Defaults to the default extension ID created in Extension::Create.
53 ExtensionBuilder& SetID(const std::string& id);
55 private:
56 base::FilePath path_;
57 Manifest::Location location_;
58 scoped_ptr<base::DictionaryValue> manifest_;
59 int flags_;
60 std::string id_;
63 } // namespace extensions
65 #endif // EXTENSIONS_COMMON_EXTENSION_BUILDER_H_