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 <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "extensions/common/manifest.h" | 14 #include "extensions/common/manifest.h" |
15 #include "extensions/common/value_builder.h" | 15 #include "extensions/common/value_builder.h" |
16 | 16 |
17 namespace extensions { | 17 namespace extensions { |
18 class Extension; | 18 class Extension; |
19 | 19 |
20 // An easier way to create extensions than Extension::Create. The | 20 // An easier way to create extensions than Extension::Create. The |
21 // constructor sets up some defaults which are customized using the | 21 // constructor sets up some defaults which are customized using the |
22 // methods. The only method that must be called is SetManifest(). | 22 // methods. The only method that must be called is SetManifest(). |
23 class ExtensionBuilder { | 23 class ExtensionBuilder { |
24 public: | 24 public: |
25 ExtensionBuilder(); | 25 ExtensionBuilder(); |
26 ~ExtensionBuilder(); | 26 ~ExtensionBuilder(); |
27 | 27 |
28 // Move constructor and operator=. | 28 // Move constructor and operator=. |
29 ExtensionBuilder(ExtensionBuilder&& other); | 29 ExtensionBuilder(ExtensionBuilder&& other); |
30 ExtensionBuilder& operator=(ExtensionBuilder&& other); | 30 ExtensionBuilder& operator=(ExtensionBuilder&& other); |
31 | 31 |
32 // Can only be called once, after which it's invalid to use the builder. | 32 // Can only be called once, after which it's invalid to use the builder. |
33 // CHECKs that the extension was created successfully. | 33 // CHECKs that the extension was created successfully. |
34 scoped_refptr<Extension> Build(); | 34 scoped_refptr<Extension> Build(); |
35 | 35 |
36 // Defaults to FilePath(). | 36 // Defaults to FilePath(). |
37 ExtensionBuilder& SetPath(const base::FilePath& path); | 37 ExtensionBuilder& SetPath(const base::FilePath& path); |
38 | 38 |
39 // Defaults to Manifest::UNPACKED. | 39 // Defaults to Manifest::UNPACKED. |
40 ExtensionBuilder& SetLocation(Manifest::Location location); | 40 ExtensionBuilder& SetLocation(Manifest::Location location); |
41 | 41 |
42 ExtensionBuilder& SetManifest(scoped_ptr<base::DictionaryValue> manifest); | 42 ExtensionBuilder& SetManifest( |
| 43 std::unique_ptr<base::DictionaryValue> manifest); |
43 | 44 |
44 // Merge another manifest into the current manifest, with new keys taking | 45 // Merge another manifest into the current manifest, with new keys taking |
45 // precedence. | 46 // precedence. |
46 ExtensionBuilder& MergeManifest(scoped_ptr<base::DictionaryValue> manifest); | 47 ExtensionBuilder& MergeManifest( |
| 48 std::unique_ptr<base::DictionaryValue> manifest); |
47 | 49 |
48 ExtensionBuilder& AddFlags(int init_from_value_flags); | 50 ExtensionBuilder& AddFlags(int init_from_value_flags); |
49 | 51 |
50 // Defaults to the default extension ID created in Extension::Create. | 52 // Defaults to the default extension ID created in Extension::Create. |
51 ExtensionBuilder& SetID(const std::string& id); | 53 ExtensionBuilder& SetID(const std::string& id); |
52 | 54 |
53 private: | 55 private: |
54 base::FilePath path_; | 56 base::FilePath path_; |
55 Manifest::Location location_; | 57 Manifest::Location location_; |
56 scoped_ptr<base::DictionaryValue> manifest_; | 58 std::unique_ptr<base::DictionaryValue> manifest_; |
57 int flags_; | 59 int flags_; |
58 std::string id_; | 60 std::string id_; |
59 | 61 |
60 DISALLOW_COPY_AND_ASSIGN(ExtensionBuilder); | 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 |