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 "base/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "extensions/common/manifest.h"
12 #include "extensions/common/value_builder.h"
14 namespace extensions
{
17 // An easier way to create extensions than Extension::Create. The
18 // constructor sets up some defaults which are customized using the
19 // methods. The only method that must be called is SetManifest().
20 class ExtensionBuilder
{
25 // Can only be called once, after which it's invalid to use the builder.
26 // CHECKs that the extension was created successfully.
27 scoped_refptr
<Extension
> Build();
29 // Workaround to allow you to pass rvalue ExtensionBuilders by reference to
30 // other functions, e.g. UseBuilder(ExtensionBuilder().Pass())
31 ExtensionBuilder
& Pass() { return *this; }
33 // Defaults to FilePath().
34 ExtensionBuilder
& SetPath(const base::FilePath
& path
);
36 // Defaults to Manifest::UNPACKED.
37 ExtensionBuilder
& SetLocation(Manifest::Location location
);
39 ExtensionBuilder
& SetManifest(scoped_ptr
<base::DictionaryValue
> manifest
);
40 ExtensionBuilder
& SetManifest(DictionaryBuilder
& manifest_builder
) {
41 return SetManifest(manifest_builder
.Build());
44 // Adds the keys from the DictionaryBuilder to the manifest, with new keys
46 ExtensionBuilder
& MergeManifest(DictionaryBuilder
& builder
);
48 ExtensionBuilder
& AddFlags(int init_from_value_flags
);
50 // Defaults to the default extension ID created in Extension::Create.
51 ExtensionBuilder
& SetID(const std::string
& id
);
55 Manifest::Location location_
;
56 scoped_ptr
<base::DictionaryValue
> manifest_
;
61 } // namespace extensions
63 #endif // EXTENSIONS_COMMON_EXTENSION_BUILDER_H_