OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/test_extension_system.h" | 5 #include "chrome/browser/extensions/test_extension_system.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/extensions/blacklist.h" | 9 #include "chrome/browser/extensions/blacklist.h" |
10 #include "chrome/browser/extensions/declarative_user_script_master.h" | 10 #include "chrome/browser/extensions/declarative_user_script_master.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 using content::BrowserThread; | 35 using content::BrowserThread; |
36 | 36 |
37 namespace extensions { | 37 namespace extensions { |
38 | 38 |
39 TestExtensionSystem::TestExtensionSystem(Profile* profile) | 39 TestExtensionSystem::TestExtensionSystem(Profile* profile) |
40 : profile_(profile), | 40 : profile_(profile), |
41 value_store_(NULL), | 41 value_store_(NULL), |
42 info_map_(new InfoMap()), | 42 info_map_(new InfoMap()), |
43 error_console_(new ErrorConsole(profile)), | 43 error_console_(new ErrorConsole(profile)), |
44 quota_service_(new QuotaService()) {} | 44 quota_service_(new QuotaService()), |
45 extension_service_(NULL), | |
46 extension_service_owned_(true) {} | |
45 | 47 |
46 TestExtensionSystem::~TestExtensionSystem() { | 48 TestExtensionSystem::~TestExtensionSystem() { |
49 if (extension_service_owned_) | |
Yoyo Zhou
2014/09/05 16:21:33
&& extension_service_?
Lei Zhang
2014/09/05 19:35:08
Nope. http://www.parashift.com/c++-faq/delete-hand
| |
50 delete extension_service_; | |
47 } | 51 } |
48 | 52 |
49 void TestExtensionSystem::Shutdown() { | 53 void TestExtensionSystem::Shutdown() { |
50 process_manager_.reset(); | 54 process_manager_.reset(); |
51 } | 55 } |
52 | 56 |
53 void TestExtensionSystem::CreateProcessManager() { | 57 void TestExtensionSystem::CreateProcessManager() { |
54 process_manager_.reset(ProcessManager::Create(profile_)); | 58 process_manager_.reset(ProcessManager::Create(profile_)); |
55 } | 59 } |
56 | 60 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 value_store_ = value_store.get(); | 100 value_store_ = value_store.get(); |
97 state_store_.reset( | 101 state_store_.reset( |
98 new StateStore(profile_, value_store.PassAs<ValueStore>())); | 102 new StateStore(profile_, value_store.PassAs<ValueStore>())); |
99 blacklist_.reset(new Blacklist(ExtensionPrefs::Get(profile_))); | 103 blacklist_.reset(new Blacklist(ExtensionPrefs::Get(profile_))); |
100 standard_management_policy_provider_.reset( | 104 standard_management_policy_provider_.reset( |
101 new StandardManagementPolicyProvider(ExtensionPrefs::Get(profile_))); | 105 new StandardManagementPolicyProvider(ExtensionPrefs::Get(profile_))); |
102 management_policy_.reset(new ManagementPolicy()); | 106 management_policy_.reset(new ManagementPolicy()); |
103 management_policy_->RegisterProvider( | 107 management_policy_->RegisterProvider( |
104 standard_management_policy_provider_.get()); | 108 standard_management_policy_provider_.get()); |
105 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); | 109 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); |
106 extension_service_.reset(new ExtensionService(profile_, | 110 if (extension_service_owned_) |
107 command_line, | 111 delete extension_service_; |
108 install_directory, | 112 extension_service_ = new ExtensionService(profile_, |
109 ExtensionPrefs::Get(profile_), | 113 command_line, |
110 blacklist_.get(), | 114 install_directory, |
111 autoupdate_enabled, | 115 ExtensionPrefs::Get(profile_), |
112 true, | 116 blacklist_.get(), |
113 &ready_)); | 117 autoupdate_enabled, |
118 true, | |
119 &ready_); | |
120 extension_service_owned_ = true; | |
114 extension_service_->ClearProvidersForTesting(); | 121 extension_service_->ClearProvidersForTesting(); |
115 return extension_service_.get(); | 122 return extension_service_; |
116 } | 123 } |
117 | 124 |
118 ExtensionService* TestExtensionSystem::extension_service() { | 125 ExtensionService* TestExtensionSystem::extension_service() { |
119 return extension_service_.get(); | 126 return extension_service_; |
120 } | 127 } |
121 | 128 |
122 RuntimeData* TestExtensionSystem::runtime_data() { | 129 RuntimeData* TestExtensionSystem::runtime_data() { |
123 return runtime_data_.get(); | 130 return runtime_data_.get(); |
124 } | 131 } |
125 | 132 |
126 ManagementPolicy* TestExtensionSystem::management_policy() { | 133 ManagementPolicy* TestExtensionSystem::management_policy() { |
127 return management_policy_.get(); | 134 return management_policy_.get(); |
128 } | 135 } |
129 | 136 |
130 void TestExtensionSystem::SetExtensionService(ExtensionService* service) { | 137 void TestExtensionSystem::SetExtensionService(ExtensionService* service, |
131 extension_service_.reset(service); | 138 bool owned) { |
139 if (extension_service_owned_) | |
140 delete extension_service_; | |
141 extension_service_ = service; | |
142 extension_service_owned_ = owned; | |
132 } | 143 } |
133 | 144 |
134 SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() { | 145 SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() { |
135 return NULL; | 146 return NULL; |
136 } | 147 } |
137 | 148 |
138 ProcessManager* TestExtensionSystem::process_manager() { | 149 ProcessManager* TestExtensionSystem::process_manager() { |
139 return process_manager_.get(); | 150 return process_manager_.get(); |
140 } | 151 } |
141 | 152 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 } | 225 } |
215 return master; | 226 return master; |
216 } | 227 } |
217 | 228 |
218 // static | 229 // static |
219 KeyedService* TestExtensionSystem::Build(content::BrowserContext* profile) { | 230 KeyedService* TestExtensionSystem::Build(content::BrowserContext* profile) { |
220 return new TestExtensionSystem(static_cast<Profile*>(profile)); | 231 return new TestExtensionSystem(static_cast<Profile*>(profile)); |
221 } | 232 } |
222 | 233 |
223 } // namespace extensions | 234 } // namespace extensions |
OLD | NEW |