| 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_app_helper.h" | 5 #include "chrome/browser/sync/test/integration/sync_app_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/launch_util.h" | 8 #include "chrome/browser/extensions/launch_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/sync/test/integration/extensions_helper.h" | 10 #include "chrome/browser/sync/test/integration/extensions_helper.h" |
| 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 12 #include "chrome/browser/sync/test/integration/sync_extension_helper.h" | 12 #include "chrome/browser/sync/test/integration/sync_extension_helper.h" |
| 13 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 14 #include "chrome/common/extensions/sync_helper.h" | 14 #include "chrome/common/extensions/sync_helper.h" |
| 15 #include "extensions/browser/app_sorting.h" | 15 #include "extensions/browser/app_sorting.h" |
| 16 #include "extensions/browser/extension_prefs.h" |
| 16 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
| 17 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
| 18 #include "extensions/common/extension_set.h" | 19 #include "extensions/common/extension_set.h" |
| 19 #include "extensions/common/id_util.h" | 20 #include "extensions/common/id_util.h" |
| 20 | 21 |
| 22 using extensions::ExtensionPrefs; |
| 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 struct AppState { | 26 struct AppState { |
| 24 AppState(); | 27 AppState(); |
| 25 ~AppState(); | 28 ~AppState(); |
| 26 bool IsValid() const; | 29 bool IsValid() const; |
| 27 bool Equals(const AppState& other) const; | 30 bool Equals(const AppState& other) const; |
| 28 | 31 |
| 29 syncer::StringOrdinal app_launch_ordinal; | 32 syncer::StringOrdinal app_launch_ordinal; |
| 30 syncer::StringOrdinal page_ordinal; | 33 syncer::StringOrdinal page_ordinal; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 return page_ordinal.IsValid() && app_launch_ordinal.IsValid(); | 44 return page_ordinal.IsValid() && app_launch_ordinal.IsValid(); |
| 42 } | 45 } |
| 43 | 46 |
| 44 bool AppState::Equals(const AppState& other) const { | 47 bool AppState::Equals(const AppState& other) const { |
| 45 return app_launch_ordinal.Equals(other.app_launch_ordinal) && | 48 return app_launch_ordinal.Equals(other.app_launch_ordinal) && |
| 46 page_ordinal.Equals(other.page_ordinal) && | 49 page_ordinal.Equals(other.page_ordinal) && |
| 47 launch_type == other.launch_type; | 50 launch_type == other.launch_type; |
| 48 } | 51 } |
| 49 | 52 |
| 50 // Load all the app specific values for |id| into |app_state|. | 53 // Load all the app specific values for |id| into |app_state|. |
| 51 void LoadApp(ExtensionService* extension_service, | 54 void LoadApp(content::BrowserContext* context, |
| 52 const std::string& id, | 55 const std::string& id, |
| 53 AppState* app_state) { | 56 AppState* app_state) { |
| 54 app_state->app_launch_ordinal = extension_service->extension_prefs()-> | 57 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); |
| 55 app_sorting()->GetAppLaunchOrdinal(id); | 58 app_state->app_launch_ordinal = prefs->app_sorting()->GetAppLaunchOrdinal(id); |
| 56 app_state->page_ordinal = extension_service->extension_prefs()-> | 59 app_state->page_ordinal = prefs->app_sorting()->GetPageOrdinal(id); |
| 57 app_sorting()->GetPageOrdinal(id); | 60 app_state->launch_type = extensions::GetLaunchTypePrefValue(prefs, id); |
| 58 app_state->launch_type = | |
| 59 extensions::GetLaunchTypePrefValue(extension_service->extension_prefs(), | |
| 60 id); | |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Returns a map from |profile|'s installed extensions to their state. | 63 // Returns a map from |profile|'s installed extensions to their state. |
| 64 AppStateMap GetAppStates(Profile* profile) { | 64 AppStateMap GetAppStates(Profile* profile) { |
| 65 AppStateMap app_state_map; | 65 AppStateMap app_state_map; |
| 66 | 66 |
| 67 ExtensionService* extension_service = profile->GetExtensionService(); | 67 ExtensionService* extension_service = profile->GetExtensionService(); |
| 68 | 68 |
| 69 scoped_ptr<const extensions::ExtensionSet> extensions( | 69 scoped_ptr<const extensions::ExtensionSet> extensions( |
| 70 extension_service->GenerateInstalledExtensionsSet()); | 70 extension_service->GenerateInstalledExtensionsSet()); |
| 71 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 71 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
| 72 it != extensions->end(); ++it) { | 72 it != extensions->end(); ++it) { |
| 73 if (extensions::sync_helper::IsSyncableApp(it->get())) { | 73 if (extensions::sync_helper::IsSyncableApp(it->get())) { |
| 74 const std::string& id = (*it)->id(); | 74 const std::string& id = (*it)->id(); |
| 75 LoadApp(extension_service, id, &(app_state_map[id])); | 75 LoadApp(profile, id, &(app_state_map[id])); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 const extensions::PendingExtensionManager* pending_extension_manager = | 79 const extensions::PendingExtensionManager* pending_extension_manager = |
| 80 extension_service->pending_extension_manager(); | 80 extension_service->pending_extension_manager(); |
| 81 | 81 |
| 82 std::list<std::string> pending_crx_ids; | 82 std::list<std::string> pending_crx_ids; |
| 83 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids); | 83 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_crx_ids); |
| 84 | 84 |
| 85 for (std::list<std::string>::const_iterator id = pending_crx_ids.begin(); | 85 for (std::list<std::string>::const_iterator id = pending_crx_ids.begin(); |
| 86 id != pending_crx_ids.end(); ++id) { | 86 id != pending_crx_ids.end(); ++id) { |
| 87 LoadApp(extension_service, *id, &(app_state_map[*id])); | 87 LoadApp(profile, *id, &(app_state_map[*id])); |
| 88 } | 88 } |
| 89 | 89 |
| 90 return app_state_map; | 90 return app_state_map; |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace | 93 } // namespace |
| 94 | 94 |
| 95 SyncAppHelper* SyncAppHelper::GetInstance() { | 95 SyncAppHelper* SyncAppHelper::GetInstance() { |
| 96 SyncAppHelper* instance = Singleton<SyncAppHelper>::get(); | 96 SyncAppHelper* instance = Singleton<SyncAppHelper>::get(); |
| 97 instance->SetupIfNecessary(sync_datatype_helper::test()); | 97 instance->SetupIfNecessary(sync_datatype_helper::test()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 ++it1; | 148 ++it1; |
| 149 ++it2; | 149 ++it2; |
| 150 } | 150 } |
| 151 | 151 |
| 152 return true; | 152 return true; |
| 153 } | 153 } |
| 154 | 154 |
| 155 syncer::StringOrdinal SyncAppHelper::GetPageOrdinalForApp( | 155 syncer::StringOrdinal SyncAppHelper::GetPageOrdinalForApp( |
| 156 Profile* profile, | 156 Profile* profile, |
| 157 const std::string& name) { | 157 const std::string& name) { |
| 158 return profile->GetExtensionService()->extension_prefs()-> | 158 return ExtensionPrefs::Get(profile)->app_sorting()->GetPageOrdinal( |
| 159 app_sorting()->GetPageOrdinal(extensions::id_util::GenerateId(name)); | 159 extensions::id_util::GenerateId(name)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void SyncAppHelper::SetPageOrdinalForApp( | 162 void SyncAppHelper::SetPageOrdinalForApp( |
| 163 Profile* profile, | 163 Profile* profile, |
| 164 const std::string& name, | 164 const std::string& name, |
| 165 const syncer::StringOrdinal& page_ordinal) { | 165 const syncer::StringOrdinal& page_ordinal) { |
| 166 profile->GetExtensionService()->extension_prefs()->app_sorting()-> | 166 ExtensionPrefs::Get(profile)->app_sorting()->SetPageOrdinal( |
| 167 SetPageOrdinal(extensions::id_util::GenerateId(name), page_ordinal); | 167 extensions::id_util::GenerateId(name), page_ordinal); |
| 168 } | 168 } |
| 169 | 169 |
| 170 syncer::StringOrdinal SyncAppHelper::GetAppLaunchOrdinalForApp( | 170 syncer::StringOrdinal SyncAppHelper::GetAppLaunchOrdinalForApp( |
| 171 Profile* profile, | 171 Profile* profile, |
| 172 const std::string& name) { | 172 const std::string& name) { |
| 173 return profile->GetExtensionService()->extension_prefs()-> | 173 return ExtensionPrefs::Get(profile)->app_sorting()->GetAppLaunchOrdinal( |
| 174 app_sorting()->GetAppLaunchOrdinal(extensions::id_util::GenerateId(name)); | 174 extensions::id_util::GenerateId(name)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void SyncAppHelper::SetAppLaunchOrdinalForApp( | 177 void SyncAppHelper::SetAppLaunchOrdinalForApp( |
| 178 Profile* profile, | 178 Profile* profile, |
| 179 const std::string& name, | 179 const std::string& name, |
| 180 const syncer::StringOrdinal& app_launch_ordinal) { | 180 const syncer::StringOrdinal& app_launch_ordinal) { |
| 181 profile->GetExtensionService()->extension_prefs()->app_sorting()-> | 181 ExtensionPrefs::Get(profile)->app_sorting()->SetAppLaunchOrdinal( |
| 182 SetAppLaunchOrdinal(extensions::id_util::GenerateId(name), | 182 extensions::id_util::GenerateId(name), app_launch_ordinal); |
| 183 app_launch_ordinal); | |
| 184 } | 183 } |
| 185 | 184 |
| 186 void SyncAppHelper::FixNTPOrdinalCollisions(Profile* profile) { | 185 void SyncAppHelper::FixNTPOrdinalCollisions(Profile* profile) { |
| 187 profile->GetExtensionService()->extension_prefs()->app_sorting()-> | 186 ExtensionPrefs::Get(profile)->app_sorting()->FixNTPOrdinalCollisions(); |
| 188 FixNTPOrdinalCollisions(); | |
| 189 } | 187 } |
| 190 | 188 |
| 191 SyncAppHelper::SyncAppHelper() : setup_completed_(false) {} | 189 SyncAppHelper::SyncAppHelper() : setup_completed_(false) {} |
| 192 | 190 |
| 193 SyncAppHelper::~SyncAppHelper() {} | 191 SyncAppHelper::~SyncAppHelper() {} |
| OLD | NEW |