| 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(); | 213 ExtensionState& extension_state = extension_state_map[id]; |
| 211 extension_state_map[id].enabled_state = | 214 extension_state.enabled_state = |
| 212 extension_service->IsExtensionEnabled(id) ? | 215 extension_service->IsExtensionEnabled(id) ? |
| 213 ExtensionState::ENABLED : | 216 ExtensionState::ENABLED : |
| 214 ExtensionState::DISABLED; | 217 ExtensionState::DISABLED; |
| 215 extension_state_map[id].incognito_enabled = | 218 extension_state.disable_reasons = |
| 219 ExtensionPrefs::Get(profile)->GetDisableReasons(id); |
| 220 extension_state.incognito_enabled = |
| 216 extensions::util::IsIncognitoEnabled(id, profile); | 221 extensions::util::IsIncognitoEnabled(id, profile); |
| 217 | 222 |
| 218 DVLOG(2) << "Extension " << (*it)->id() << " in profile " | 223 DVLOG(2) << "Extension " << id << " in profile " << profile_debug_name |
| 219 << profile_debug_name << " is " | 224 << " is " << (extension_service->IsExtensionEnabled(id) ? |
| 220 << (extension_service->IsExtensionEnabled(id) ? | 225 "enabled" : "disabled"); |
| 221 "enabled" : "disabled"); | |
| 222 } | 226 } |
| 223 | 227 |
| 224 const extensions::PendingExtensionManager* pending_extension_manager = | 228 const extensions::PendingExtensionManager* pending_extension_manager = |
| 225 extension_service->pending_extension_manager(); | 229 extension_service->pending_extension_manager(); |
| 226 | 230 |
| 227 std::list<std::string> pending_crx_ids; | 231 std::list<std::string> pending_crx_ids; |
| 228 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids); | 232 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids); |
| 229 | 233 |
| 230 std::list<std::string>::const_iterator id; | 234 std::list<std::string>::const_iterator id; |
| 231 for (id = pending_crx_ids.begin(); id != pending_crx_ids.end(); ++id) { | 235 for (const std::string& id : pending_crx_ids) { |
| 232 extension_state_map[*id].enabled_state = ExtensionState::PENDING; | 236 ExtensionState& extension_state = extension_state_map[id]; |
| 233 extension_state_map[*id].incognito_enabled = | 237 extension_state.enabled_state = ExtensionState::PENDING; |
| 234 extensions::util::IsIncognitoEnabled(*id, profile); | 238 extension_state.disable_reasons = |
| 235 DVLOG(2) << "Extension " << *id << " in profile " | 239 ExtensionPrefs::Get(profile)->GetDisableReasons(id); |
| 240 extension_state.incognito_enabled = |
| 241 extensions::util::IsIncognitoEnabled(id, profile); |
| 242 DVLOG(2) << "Extension " << id << " in profile " |
| 236 << profile_debug_name << " is pending"; | 243 << profile_debug_name << " is pending"; |
| 237 } | 244 } |
| 238 | 245 |
| 239 return extension_state_map; | 246 return extension_state_map; |
| 240 } | 247 } |
| 241 | 248 |
| 242 bool SyncExtensionHelper::ExtensionStatesMatch( | 249 bool SyncExtensionHelper::ExtensionStatesMatch( |
| 243 Profile* profile1, Profile* profile2) { | 250 Profile* profile1, Profile* profile2) { |
| 244 const ExtensionStateMap& state_map1 = GetExtensionStates(profile1); | 251 const ExtensionStateMap& state_map1 = GetExtensionStates(profile1); |
| 245 const ExtensionStateMap& state_map2 = GetExtensionStates(profile2); | 252 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()); | 396 EXPECT_EQ(expected_id, extension->id()); |
| 390 return NULL; | 397 return NULL; |
| 391 } | 398 } |
| 392 DVLOG(2) << "created extension with name = " | 399 DVLOG(2) << "created extension with name = " |
| 393 << name << ", id = " << expected_id; | 400 << name << ", id = " << expected_id; |
| 394 (it->second)[name] = extension; | 401 (it->second)[name] = extension; |
| 395 id_to_name_[expected_id] = name; | 402 id_to_name_[expected_id] = name; |
| 396 id_to_type_[expected_id] = type; | 403 id_to_type_[expected_id] = type; |
| 397 return extension; | 404 return extension; |
| 398 } | 405 } |
| OLD | NEW |