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/sync/test/integration/sync_extension_helper.h" | 5 #include "chrome/browser/sync/test/integration/sync_extension_helper.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/extensions/pending_extension_info.h" | 13 #include "chrome/browser/extensions/pending_extension_info.h" |
14 #include "chrome/browser/extensions/pending_extension_manager.h" | 14 #include "chrome/browser/extensions/pending_extension_manager.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 16 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
17 #include "chrome/browser/sync/test/integration/sync_test.h" | 17 #include "chrome/browser/sync/test/integration/sync_test.h" |
18 #include "components/crx_file/id_util.h" | 18 #include "components/crx_file/id_util.h" |
19 #include "extensions/browser/extension_prefs.h" | |
19 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
21 #include "extensions/browser/install_flag.h" | 22 #include "extensions/browser/install_flag.h" |
22 #include "extensions/browser/uninstall_reason.h" | 23 #include "extensions/browser/uninstall_reason.h" |
23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
24 #include "extensions/common/extension_set.h" | 25 #include "extensions/common/extension_set.h" |
25 #include "extensions/common/manifest_constants.h" | 26 #include "extensions/common/manifest_constants.h" |
26 #include "sync/api/string_ordinal.h" | 27 #include "sync/api/string_ordinal.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 using extensions::Extension; | 30 using extensions::Extension; |
31 using extensions::ExtensionPrefs; | |
30 using extensions::ExtensionRegistry; | 32 using extensions::ExtensionRegistry; |
31 using extensions::Manifest; | 33 using extensions::Manifest; |
32 | 34 |
33 SyncExtensionHelper::ExtensionState::ExtensionState() | 35 SyncExtensionHelper::ExtensionState::ExtensionState() |
34 : enabled_state(ENABLED), incognito_enabled(false) {} | 36 : enabled_state(ENABLED), disable_reasons(0), incognito_enabled(false) {} |
35 | 37 |
36 SyncExtensionHelper::ExtensionState::~ExtensionState() {} | 38 SyncExtensionHelper::ExtensionState::~ExtensionState() {} |
37 | 39 |
38 bool SyncExtensionHelper::ExtensionState::Equals( | 40 bool SyncExtensionHelper::ExtensionState::Equals( |
39 const SyncExtensionHelper::ExtensionState &other) const { | 41 const SyncExtensionHelper::ExtensionState &other) const { |
40 return ((enabled_state == other.enabled_state) && | 42 return ((enabled_state == other.enabled_state) && |
43 (disable_reasons == other.disable_reasons) && | |
41 (incognito_enabled == other.incognito_enabled)); | 44 (incognito_enabled == other.incognito_enabled)); |
42 } | 45 } |
43 | 46 |
44 // static | 47 // static |
45 SyncExtensionHelper* SyncExtensionHelper::GetInstance() { | 48 SyncExtensionHelper* SyncExtensionHelper::GetInstance() { |
46 SyncExtensionHelper* instance = Singleton<SyncExtensionHelper>::get(); | 49 SyncExtensionHelper* instance = Singleton<SyncExtensionHelper>::get(); |
47 instance->SetupIfNecessary(sync_datatype_helper::test()); | 50 instance->SetupIfNecessary(sync_datatype_helper::test()); |
48 return instance; | 51 return instance; |
49 } | 52 } |
50 | 53 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 const std::string& profile_debug_name = profile->GetDebugName(); | 201 const std::string& profile_debug_name = profile->GetDebugName(); |
199 | 202 |
200 ExtensionStateMap extension_state_map; | 203 ExtensionStateMap extension_state_map; |
201 | 204 |
202 scoped_ptr<const extensions::ExtensionSet> extensions( | 205 scoped_ptr<const extensions::ExtensionSet> extensions( |
203 extensions::ExtensionRegistry::Get(profile) | 206 extensions::ExtensionRegistry::Get(profile) |
204 ->GenerateInstalledExtensionsSet()); | 207 ->GenerateInstalledExtensionsSet()); |
205 | 208 |
206 ExtensionService* extension_service = | 209 ExtensionService* extension_service = |
207 extensions::ExtensionSystem::Get(profile)->extension_service(); | 210 extensions::ExtensionSystem::Get(profile)->extension_service(); |
208 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 211 for (const scoped_refptr<const Extension>& extension : *extensions) { |
209 it != extensions->end(); ++it) { | 212 const std::string& id = extension->id(); |
210 const std::string& id = (*it)->id(); | |
211 extension_state_map[id].enabled_state = | 213 extension_state_map[id].enabled_state = |
not at google - send to devlin
2015/05/12 18:04:17
Consider saving a reference to extension_state_map
Marc Treib
2015/05/19 12:12:03
Done. (Should it be a pointer instead of a referen
not at google - send to devlin
2015/05/19 14:32:10
I use non-const references for references into STL
Marc Treib
2015/05/19 15:30:56
Yup, I only found that as well.
Alright, thanks fo
| |
212 extension_service->IsExtensionEnabled(id) ? | 214 extension_service->IsExtensionEnabled(id) ? |
213 ExtensionState::ENABLED : | 215 ExtensionState::ENABLED : |
214 ExtensionState::DISABLED; | 216 ExtensionState::DISABLED; |
217 extension_state_map[id].disable_reasons = | |
218 ExtensionPrefs::Get(profile)->GetDisableReasons(id); | |
215 extension_state_map[id].incognito_enabled = | 219 extension_state_map[id].incognito_enabled = |
216 extensions::util::IsIncognitoEnabled(id, profile); | 220 extensions::util::IsIncognitoEnabled(id, profile); |
217 | 221 |
218 DVLOG(2) << "Extension " << (*it)->id() << " in profile " | 222 DVLOG(2) << "Extension " << id << " in profile " << profile_debug_name |
219 << profile_debug_name << " is " | 223 << " is " << (extension_service->IsExtensionEnabled(id) ? |
220 << (extension_service->IsExtensionEnabled(id) ? | 224 "enabled" : "disabled"); |
221 "enabled" : "disabled"); | |
222 } | 225 } |
223 | 226 |
224 const extensions::PendingExtensionManager* pending_extension_manager = | 227 const extensions::PendingExtensionManager* pending_extension_manager = |
225 extension_service->pending_extension_manager(); | 228 extension_service->pending_extension_manager(); |
226 | 229 |
227 std::list<std::string> pending_crx_ids; | 230 std::list<std::string> pending_crx_ids; |
228 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids); | 231 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids); |
229 | 232 |
230 std::list<std::string>::const_iterator id; | 233 std::list<std::string>::const_iterator id; |
231 for (id = pending_crx_ids.begin(); id != pending_crx_ids.end(); ++id) { | 234 for (const std::string& id : pending_crx_ids) { |
232 extension_state_map[*id].enabled_state = ExtensionState::PENDING; | 235 extension_state_map[id].enabled_state = ExtensionState::PENDING; |
233 extension_state_map[*id].incognito_enabled = | 236 extension_state_map[id].disable_reasons = |
234 extensions::util::IsIncognitoEnabled(*id, profile); | 237 ExtensionPrefs::Get(profile)->GetDisableReasons(id); |
235 DVLOG(2) << "Extension " << *id << " in profile " | 238 extension_state_map[id].incognito_enabled = |
239 extensions::util::IsIncognitoEnabled(id, profile); | |
240 DVLOG(2) << "Extension " << id << " in profile " | |
236 << profile_debug_name << " is pending"; | 241 << profile_debug_name << " is pending"; |
237 } | 242 } |
238 | 243 |
239 return extension_state_map; | 244 return extension_state_map; |
240 } | 245 } |
241 | 246 |
242 bool SyncExtensionHelper::ExtensionStatesMatch( | 247 bool SyncExtensionHelper::ExtensionStatesMatch( |
243 Profile* profile1, Profile* profile2) { | 248 Profile* profile1, Profile* profile2) { |
244 const ExtensionStateMap& state_map1 = GetExtensionStates(profile1); | 249 const ExtensionStateMap& state_map1 = GetExtensionStates(profile1); |
245 const ExtensionStateMap& state_map2 = GetExtensionStates(profile2); | 250 const ExtensionStateMap& state_map2 = GetExtensionStates(profile2); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 EXPECT_EQ(expected_id, extension->id()); | 394 EXPECT_EQ(expected_id, extension->id()); |
390 return NULL; | 395 return NULL; |
391 } | 396 } |
392 DVLOG(2) << "created extension with name = " | 397 DVLOG(2) << "created extension with name = " |
393 << name << ", id = " << expected_id; | 398 << name << ", id = " << expected_id; |
394 (it->second)[name] = extension; | 399 (it->second)[name] = extension; |
395 id_to_name_[expected_id] = name; | 400 id_to_name_[expected_id] = name; |
396 id_to_type_[expected_id] = type; | 401 id_to_type_[expected_id] = type; |
397 return extension; | 402 return extension; |
398 } | 403 } |
OLD | NEW |