| 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/manifest_handlers/app_launch_info.h" |
| 14 #include "chrome/common/extensions/sync_helper.h" | 15 #include "chrome/common/extensions/sync_helper.h" |
| 15 #include "extensions/browser/app_sorting.h" | 16 #include "extensions/browser/app_sorting.h" |
| 16 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
| 17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_set.h" | 21 #include "extensions/common/extension_set.h" |
| 21 #include "extensions/common/id_util.h" | 22 #include "extensions/common/id_util.h" |
| 22 | 23 |
| 23 using extensions::ExtensionPrefs; | 24 using extensions::ExtensionPrefs; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 struct AppState { | 28 struct AppState { |
| 28 AppState(); | 29 AppState(); |
| 29 ~AppState(); | 30 ~AppState(); |
| 30 bool IsValid() const; | 31 bool IsValid() const; |
| 31 bool Equals(const AppState& other) const; | 32 bool Equals(const AppState& other) const; |
| 32 | 33 |
| 33 syncer::StringOrdinal app_launch_ordinal; | 34 syncer::StringOrdinal app_launch_ordinal; |
| 34 syncer::StringOrdinal page_ordinal; | 35 syncer::StringOrdinal page_ordinal; |
| 35 extensions::LaunchType launch_type; | 36 extensions::LaunchType launch_type; |
| 37 GURL launch_web_url; |
| 38 std::string description; |
| 39 std::string name; |
| 40 bool from_bookmark; |
| 36 }; | 41 }; |
| 37 | 42 |
| 38 typedef std::map<std::string, AppState> AppStateMap; | 43 typedef std::map<std::string, AppState> AppStateMap; |
| 39 | 44 |
| 40 AppState::AppState() : launch_type(extensions::LAUNCH_TYPE_INVALID) {} | 45 AppState::AppState() : launch_type(extensions::LAUNCH_TYPE_INVALID) {} |
| 41 | 46 |
| 42 AppState::~AppState() {} | 47 AppState::~AppState() {} |
| 43 | 48 |
| 44 bool AppState::IsValid() const { | 49 bool AppState::IsValid() const { |
| 45 return page_ordinal.IsValid() && app_launch_ordinal.IsValid(); | 50 return page_ordinal.IsValid() && app_launch_ordinal.IsValid(); |
| 46 } | 51 } |
| 47 | 52 |
| 48 bool AppState::Equals(const AppState& other) const { | 53 bool AppState::Equals(const AppState& other) const { |
| 49 return app_launch_ordinal.Equals(other.app_launch_ordinal) && | 54 return app_launch_ordinal.Equals(other.app_launch_ordinal) && |
| 50 page_ordinal.Equals(other.page_ordinal) && | 55 page_ordinal.Equals(other.page_ordinal) && |
| 51 launch_type == other.launch_type; | 56 launch_type == other.launch_type && |
| 57 launch_web_url == other.launch_web_url && |
| 58 description == other.description && name == other.name && |
| 59 from_bookmark == other.from_bookmark; |
| 52 } | 60 } |
| 53 | 61 |
| 54 // Load all the app specific values for |id| into |app_state|. | 62 // Load all the app specific values for |id| into |app_state|. |
| 55 void LoadApp(content::BrowserContext* context, | 63 void LoadApp(content::BrowserContext* context, |
| 56 const std::string& id, | 64 const std::string& id, |
| 57 AppState* app_state) { | 65 AppState* app_state) { |
| 58 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); | 66 ExtensionPrefs* prefs = ExtensionPrefs::Get(context); |
| 59 app_state->app_launch_ordinal = prefs->app_sorting()->GetAppLaunchOrdinal(id); | 67 app_state->app_launch_ordinal = prefs->app_sorting()->GetAppLaunchOrdinal(id); |
| 60 app_state->page_ordinal = prefs->app_sorting()->GetPageOrdinal(id); | 68 app_state->page_ordinal = prefs->app_sorting()->GetPageOrdinal(id); |
| 61 app_state->launch_type = extensions::GetLaunchTypePrefValue(prefs, id); | 69 app_state->launch_type = extensions::GetLaunchTypePrefValue(prefs, id); |
| 70 ExtensionService* service = |
| 71 extensions::ExtensionSystem::Get(context)->extension_service(); |
| 72 const extensions::Extension* extension = service->GetInstalledExtension(id); |
| 73 app_state->launch_web_url = |
| 74 extensions::AppLaunchInfo::GetLaunchWebURL(extension); |
| 75 app_state->description = extension->description(); |
| 76 app_state->name = extension->name(); |
| 77 app_state->from_bookmark = extension->from_bookmark(); |
| 62 } | 78 } |
| 63 | 79 |
| 64 // Returns a map from |profile|'s installed extensions to their state. | 80 // Returns a map from |profile|'s installed extensions to their state. |
| 65 AppStateMap GetAppStates(Profile* profile) { | 81 AppStateMap GetAppStates(Profile* profile) { |
| 66 AppStateMap app_state_map; | 82 AppStateMap app_state_map; |
| 67 | 83 |
| 68 scoped_ptr<const extensions::ExtensionSet> extensions( | 84 scoped_ptr<const extensions::ExtensionSet> extensions( |
| 69 extensions::ExtensionRegistry::Get(profile) | 85 extensions::ExtensionRegistry::Get(profile) |
| 70 ->GenerateInstalledExtensionsSet()); | 86 ->GenerateInstalledExtensionsSet()); |
| 71 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 87 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 extensions::id_util::GenerateId(name), app_launch_ordinal); | 200 extensions::id_util::GenerateId(name), app_launch_ordinal); |
| 185 } | 201 } |
| 186 | 202 |
| 187 void SyncAppHelper::FixNTPOrdinalCollisions(Profile* profile) { | 203 void SyncAppHelper::FixNTPOrdinalCollisions(Profile* profile) { |
| 188 ExtensionPrefs::Get(profile)->app_sorting()->FixNTPOrdinalCollisions(); | 204 ExtensionPrefs::Get(profile)->app_sorting()->FixNTPOrdinalCollisions(); |
| 189 } | 205 } |
| 190 | 206 |
| 191 SyncAppHelper::SyncAppHelper() : setup_completed_(false) {} | 207 SyncAppHelper::SyncAppHelper() : setup_completed_(false) {} |
| 192 | 208 |
| 193 SyncAppHelper::~SyncAppHelper() {} | 209 SyncAppHelper::~SyncAppHelper() {} |
| OLD | NEW |