OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_COMMON_EXTENSION_BUILDER_H_ | 5 #ifndef EXTENSIONS_COMMON_EXTENSION_BUILDER_H_ |
6 #define EXTENSIONS_COMMON_EXTENSION_BUILDER_H_ | 6 #define EXTENSIONS_COMMON_EXTENSION_BUILDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "extensions/common/manifest.h" | 13 #include "extensions/common/manifest.h" |
14 #include "extensions/common/value_builder.h" | 14 #include "extensions/common/value_builder.h" |
15 | 15 |
16 namespace extensions { | 16 namespace extensions { |
17 class Extension; | 17 class Extension; |
18 | 18 |
19 // An easier way to create extensions than Extension::Create. The | 19 // An easier way to create extensions than Extension::Create. The |
20 // constructor sets up some defaults which are customized using the | 20 // constructor sets up some defaults which are customized using the |
21 // methods. The only method that must be called is SetManifest(). | 21 // methods. The only method that must be called is SetManifest(). |
22 class ExtensionBuilder { | 22 class ExtensionBuilder { |
23 public: | 23 public: |
24 ExtensionBuilder(); | 24 ExtensionBuilder(); |
25 ~ExtensionBuilder(); | 25 ~ExtensionBuilder(); |
26 | 26 |
| 27 // Move constructor and operator=. |
| 28 ExtensionBuilder(ExtensionBuilder&& other); |
| 29 ExtensionBuilder& operator=(ExtensionBuilder&& other); |
| 30 |
27 // Can only be called once, after which it's invalid to use the builder. | 31 // Can only be called once, after which it's invalid to use the builder. |
28 // CHECKs that the extension was created successfully. | 32 // CHECKs that the extension was created successfully. |
29 scoped_refptr<Extension> Build(); | 33 scoped_refptr<Extension> Build(); |
30 | 34 |
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; } | |
34 | |
35 // Defaults to FilePath(). | 35 // Defaults to FilePath(). |
36 ExtensionBuilder& SetPath(const base::FilePath& path); | 36 ExtensionBuilder& SetPath(const base::FilePath& path); |
37 | 37 |
38 // Defaults to Manifest::UNPACKED. | 38 // Defaults to Manifest::UNPACKED. |
39 ExtensionBuilder& SetLocation(Manifest::Location location); | 39 ExtensionBuilder& SetLocation(Manifest::Location location); |
40 | 40 |
41 ExtensionBuilder& SetManifest(scoped_ptr<base::DictionaryValue> manifest); | 41 ExtensionBuilder& SetManifest(scoped_ptr<base::DictionaryValue> manifest); |
42 ExtensionBuilder& SetManifest(DictionaryBuilder& manifest_builder) { | 42 ExtensionBuilder& SetManifest(DictionaryBuilder& manifest_builder) { |
43 return SetManifest(manifest_builder.Build()); | 43 return SetManifest(manifest_builder.Build()); |
44 } | 44 } |
45 | 45 |
46 // Adds the keys from the DictionaryBuilder to the manifest, with new keys | 46 // Adds the keys from the DictionaryBuilder to the manifest, with new keys |
47 // taking precedence. | 47 // taking precedence. |
48 ExtensionBuilder& MergeManifest(DictionaryBuilder& builder); | 48 ExtensionBuilder& MergeManifest(DictionaryBuilder& builder); |
49 | 49 |
50 ExtensionBuilder& AddFlags(int init_from_value_flags); | 50 ExtensionBuilder& AddFlags(int init_from_value_flags); |
51 | 51 |
52 // Defaults to the default extension ID created in Extension::Create. | 52 // Defaults to the default extension ID created in Extension::Create. |
53 ExtensionBuilder& SetID(const std::string& id); | 53 ExtensionBuilder& SetID(const std::string& id); |
54 | 54 |
55 private: | 55 private: |
56 base::FilePath path_; | 56 base::FilePath path_; |
57 Manifest::Location location_; | 57 Manifest::Location location_; |
58 scoped_ptr<base::DictionaryValue> manifest_; | 58 scoped_ptr<base::DictionaryValue> manifest_; |
59 int flags_; | 59 int flags_; |
60 std::string id_; | 60 std::string id_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ExtensionBuilder); |
61 }; | 63 }; |
62 | 64 |
63 } // namespace extensions | 65 } // namespace extensions |
64 | 66 |
65 #endif // EXTENSIONS_COMMON_EXTENSION_BUILDER_H_ | 67 #endif // EXTENSIONS_COMMON_EXTENSION_BUILDER_H_ |
OLD | NEW |