| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/app_list_syncable_service.h" | 5 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
| 32 #include "extensions/browser/uninstall_reason.h" | 32 #include "extensions/browser/uninstall_reason.h" |
| 33 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
| 34 #include "extensions/common/one_shot_event.h" | 34 #include "extensions/common/one_shot_event.h" |
| 35 #include "ui/app_list/app_list_folder_item.h" | 35 #include "ui/app_list/app_list_folder_item.h" |
| 36 #include "ui/app_list/app_list_item.h" | 36 #include "ui/app_list/app_list_item.h" |
| 37 #include "ui/app_list/app_list_model.h" | 37 #include "ui/app_list/app_list_model.h" |
| 38 #include "ui/app_list/app_list_model_observer.h" | 38 #include "ui/app_list/app_list_model_observer.h" |
| 39 #include "ui/app_list/app_list_switches.h" | 39 #include "ui/app_list/app_list_switches.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 | |
| 42 #if defined(OS_CHROMEOS) | |
| 43 #include "chrome/browser/chromeos/arc/arc_util.h" | 41 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 44 #include "chrome/browser/chromeos/file_manager/app_id.h" | 42 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 45 #include "chrome/browser/chromeos/genius_app/app_id.h" | 43 #include "chrome/browser/chromeos/genius_app/app_id.h" |
| 46 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" | 44 #include "chrome/browser/ui/app_list/arc/arc_app_item.h" |
| 47 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 45 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 48 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" | 46 #include "chrome/browser/ui/app_list/arc/arc_app_model_builder.h" |
| 49 #endif | |
| 50 | 47 |
| 51 using syncer::SyncChange; | 48 using syncer::SyncChange; |
| 52 | 49 |
| 53 namespace app_list { | 50 namespace app_list { |
| 54 | 51 |
| 55 namespace { | 52 namespace { |
| 56 | 53 |
| 57 const char kNameKey[] = "name"; | 54 const char kNameKey[] = "name"; |
| 58 const char kParentIdKey[] = "parent_id"; | 55 const char kParentIdKey[] = "parent_id"; |
| 59 const char kPositionKey[] = "position"; | 56 const char kPositionKey[] = "position"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 item->item_id, | 120 item->item_id, |
| 124 specifics); | 121 specifics); |
| 125 } | 122 } |
| 126 | 123 |
| 127 bool AppIsDefault(ExtensionService* service, const std::string& id) { | 124 bool AppIsDefault(ExtensionService* service, const std::string& id) { |
| 128 return service && extensions::ExtensionPrefs::Get(service->profile()) | 125 return service && extensions::ExtensionPrefs::Get(service->profile()) |
| 129 ->WasInstalledByDefault(id); | 126 ->WasInstalledByDefault(id); |
| 130 } | 127 } |
| 131 | 128 |
| 132 bool IsUnRemovableDefaultApp(const std::string& id) { | 129 bool IsUnRemovableDefaultApp(const std::string& id) { |
| 133 if (id == extension_misc::kChromeAppId || | 130 return id == extension_misc::kChromeAppId || |
| 134 id == extensions::kWebStoreAppId) | 131 id == extensions::kWebStoreAppId || |
| 135 return true; | 132 id == file_manager::kFileManagerAppId || |
| 136 #if defined(OS_CHROMEOS) | 133 id == genius_app::kGeniusAppId; |
| 137 if (id == file_manager::kFileManagerAppId || id == genius_app::kGeniusAppId) | |
| 138 return true; | |
| 139 #endif | |
| 140 return false; | |
| 141 } | 134 } |
| 142 | 135 |
| 143 void UninstallExtension(ExtensionService* service, const std::string& id) { | 136 void UninstallExtension(ExtensionService* service, const std::string& id) { |
| 144 if (service) { | 137 if (service) { |
| 145 ExtensionService::UninstallExtensionHelper( | 138 ExtensionService::UninstallExtensionHelper( |
| 146 service, id, extensions::UNINSTALL_REASON_SYNC); | 139 service, id, extensions::UNINSTALL_REASON_SYNC); |
| 147 } | 140 } |
| 148 } | 141 } |
| 149 | 142 |
| 150 bool GetAppListItemType(AppListItem* item, | 143 bool GetAppListItemType(AppListItem* item, |
| 151 sync_pb::AppListSpecifics::AppListItemType* type) { | 144 sync_pb::AppListSpecifics::AppListItemType* type) { |
| 152 const char* item_type = item->GetItemType(); | 145 const char* item_type = item->GetItemType(); |
| 153 if (item_type == ExtensionAppItem::kItemType) { | 146 if (item_type == ExtensionAppItem::kItemType) { |
| 154 *type = sync_pb::AppListSpecifics::TYPE_APP; | 147 *type = sync_pb::AppListSpecifics::TYPE_APP; |
| 155 #if defined(OS_CHROMEOS) | |
| 156 } else if (item_type == ArcAppItem::kItemType) { | 148 } else if (item_type == ArcAppItem::kItemType) { |
| 157 *type = sync_pb::AppListSpecifics::TYPE_APP; | 149 *type = sync_pb::AppListSpecifics::TYPE_APP; |
| 158 #endif | |
| 159 } else if (item_type == AppListFolderItem::kItemType) { | 150 } else if (item_type == AppListFolderItem::kItemType) { |
| 160 *type = sync_pb::AppListSpecifics::TYPE_FOLDER; | 151 *type = sync_pb::AppListSpecifics::TYPE_FOLDER; |
| 161 } else { | 152 } else { |
| 162 LOG(ERROR) << "Unrecognized model type: " << item_type; | 153 LOG(ERROR) << "Unrecognized model type: " << item_type; |
| 163 return false; | 154 return false; |
| 164 } | 155 } |
| 165 return true; | 156 return true; |
| 166 } | 157 } |
| 167 | 158 |
| 168 bool IsDriveAppSyncId(const std::string& sync_id) { | 159 bool IsDriveAppSyncId(const std::string& sync_id) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 240 |
| 250 void OnAppListItemWillBeDeleted(AppListItem* item) override { | 241 void OnAppListItemWillBeDeleted(AppListItem* item) override { |
| 251 DCHECK(!adding_item_); | 242 DCHECK(!adding_item_); |
| 252 VLOG(2) << owner_ << " OnAppListItemDeleted: " << item->ToDebugString(); | 243 VLOG(2) << owner_ << " OnAppListItemDeleted: " << item->ToDebugString(); |
| 253 // Don't sync folder removal in case the folder still exists on another | 244 // Don't sync folder removal in case the folder still exists on another |
| 254 // device (e.g. with device specific items in it). Empty folders will be | 245 // device (e.g. with device specific items in it). Empty folders will be |
| 255 // deleted when the last item is removed (in PruneEmptySyncFolders()). | 246 // deleted when the last item is removed (in PruneEmptySyncFolders()). |
| 256 if (item->GetItemType() == AppListFolderItem::kItemType) | 247 if (item->GetItemType() == AppListFolderItem::kItemType) |
| 257 return; | 248 return; |
| 258 | 249 |
| 259 #if defined(OS_CHROMEOS) | |
| 260 if (item->GetItemType() == ArcAppItem::kItemType) { | 250 if (item->GetItemType() == ArcAppItem::kItemType) { |
| 261 // Don't sync remove changes coming as result of disabling ARC. | 251 // Don't sync remove changes coming as result of disabling ARC. |
| 262 if (!arc::IsArcPlayStoreEnabledForProfile(owner_->profile())) | 252 if (!arc::IsArcPlayStoreEnabledForProfile(owner_->profile())) |
| 263 return; | 253 return; |
| 264 } | 254 } |
| 265 #endif | |
| 266 | 255 |
| 267 owner_->RemoveSyncItem(item->id()); | 256 owner_->RemoveSyncItem(item->id()); |
| 268 } | 257 } |
| 269 | 258 |
| 270 void OnAppListItemUpdated(AppListItem* item) override { | 259 void OnAppListItemUpdated(AppListItem* item) override { |
| 271 if (adding_item_) { | 260 if (adding_item_) { |
| 272 // Adding an item may trigger update notifications which should be | 261 // Adding an item may trigger update notifications which should be |
| 273 // ignored. | 262 // ignored. |
| 274 DCHECK_EQ(adding_item_, item); | 263 DCHECK_EQ(adding_item_, item); |
| 275 return; | 264 return; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 void AppListSyncableService::BuildModel() { | 375 void AppListSyncableService::BuildModel() { |
| 387 InitFromLocalStorage(); | 376 InitFromLocalStorage(); |
| 388 | 377 |
| 389 // TODO(calamity): make this a DCHECK after a dev channel release. | 378 // TODO(calamity): make this a DCHECK after a dev channel release. |
| 390 CHECK(IsExtensionServiceReady()); | 379 CHECK(IsExtensionServiceReady()); |
| 391 AppListControllerDelegate* controller = NULL; | 380 AppListControllerDelegate* controller = NULL; |
| 392 AppListService* service = AppListService::Get(); | 381 AppListService* service = AppListService::Get(); |
| 393 if (service) | 382 if (service) |
| 394 controller = service->GetControllerDelegate(); | 383 controller = service->GetControllerDelegate(); |
| 395 apps_builder_.reset(new ExtensionAppModelBuilder(controller)); | 384 apps_builder_.reset(new ExtensionAppModelBuilder(controller)); |
| 396 #if defined(OS_CHROMEOS) | |
| 397 if (arc::IsArcAllowedForProfile(profile_)) | 385 if (arc::IsArcAllowedForProfile(profile_)) |
| 398 arc_apps_builder_.reset(new ArcAppModelBuilder(controller)); | 386 arc_apps_builder_.reset(new ArcAppModelBuilder(controller)); |
| 399 #endif | |
| 400 DCHECK(profile_); | 387 DCHECK(profile_); |
| 401 if (app_list::switches::IsAppListSyncEnabled()) { | 388 if (app_list::switches::IsAppListSyncEnabled()) { |
| 402 VLOG(1) << this << ": AppListSyncableService: InitializeWithService."; | 389 VLOG(1) << this << ": AppListSyncableService: InitializeWithService."; |
| 403 SyncStarted(); | 390 SyncStarted(); |
| 404 apps_builder_->InitializeWithService(this, model_.get()); | 391 apps_builder_->InitializeWithService(this, model_.get()); |
| 405 #if defined(OS_CHROMEOS) | |
| 406 if (arc_apps_builder_.get()) | 392 if (arc_apps_builder_.get()) |
| 407 arc_apps_builder_->InitializeWithService(this, model_.get()); | 393 arc_apps_builder_->InitializeWithService(this, model_.get()); |
| 408 #endif | |
| 409 } else { | 394 } else { |
| 410 VLOG(1) << this << ": AppListSyncableService: InitializeWithProfile."; | 395 VLOG(1) << this << ": AppListSyncableService: InitializeWithProfile."; |
| 411 apps_builder_->InitializeWithProfile(profile_, model_.get()); | 396 apps_builder_->InitializeWithProfile(profile_, model_.get()); |
| 412 #if defined(OS_CHROMEOS) | |
| 413 if (arc_apps_builder_.get()) | 397 if (arc_apps_builder_.get()) |
| 414 arc_apps_builder_->InitializeWithProfile(profile_, model_.get()); | 398 arc_apps_builder_->InitializeWithProfile(profile_, model_.get()); |
| 415 #endif | |
| 416 } | 399 } |
| 417 | 400 |
| 418 if (app_list::switches::IsDriveAppsInAppListEnabled()) | 401 if (app_list::switches::IsDriveAppsInAppListEnabled()) |
| 419 drive_app_provider_.reset(new DriveAppProvider(profile_, this)); | 402 drive_app_provider_.reset(new DriveAppProvider(profile_, this)); |
| 420 | 403 |
| 421 HandleUpdateFinished(); | 404 HandleUpdateFinished(); |
| 422 } | 405 } |
| 423 | 406 |
| 424 void AppListSyncableService::AddObserverAndStart(Observer* observer) { | 407 void AppListSyncableService::AddObserverAndStart(Observer* observer) { |
| 425 observer_list_.AddObserver(observer); | 408 observer_list_.AddObserver(observer); |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 } | 1205 } |
| 1223 | 1206 |
| 1224 const syncer::StringOrdinal oem_ordinal = | 1207 const syncer::StringOrdinal oem_ordinal = |
| 1225 web_store_app_item->position().CreateAfter(); | 1208 web_store_app_item->position().CreateAfter(); |
| 1226 VLOG(1) << "Placing OEM Folder at: " << item_list->item_count() | 1209 VLOG(1) << "Placing OEM Folder at: " << item_list->item_count() |
| 1227 << " position: " << oem_ordinal.ToDebugString(); | 1210 << " position: " << oem_ordinal.ToDebugString(); |
| 1228 return oem_ordinal; | 1211 return oem_ordinal; |
| 1229 } | 1212 } |
| 1230 | 1213 |
| 1231 bool AppListSyncableService::AppIsOem(const std::string& id) { | 1214 bool AppListSyncableService::AppIsOem(const std::string& id) { |
| 1232 #if defined(OS_CHROMEOS) | |
| 1233 const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile_); | 1215 const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile_); |
| 1234 if (arc_prefs && arc_prefs->IsOem(id)) | 1216 if (arc_prefs && arc_prefs->IsOem(id)) |
| 1235 return true; | 1217 return true; |
| 1236 #endif | |
| 1237 | 1218 |
| 1238 if (!extension_system_->extension_service()) | 1219 if (!extension_system_->extension_service()) |
| 1239 return false; | 1220 return false; |
| 1240 const extensions::Extension* extension = | 1221 const extensions::Extension* extension = |
| 1241 extension_system_->extension_service()->GetExtensionById(id, true); | 1222 extension_system_->extension_service()->GetExtensionById(id, true); |
| 1242 return extension && extension->was_installed_by_oem(); | 1223 return extension && extension->was_installed_by_oem(); |
| 1243 } | 1224 } |
| 1244 | 1225 |
| 1245 std::string AppListSyncableService::SyncItem::ToString() const { | 1226 std::string AppListSyncableService::SyncItem::ToString() const { |
| 1246 std::string res = item_id.substr(0, 8); | 1227 std::string res = item_id.substr(0, 8); |
| 1247 if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { | 1228 if (item_type == sync_pb::AppListSpecifics::TYPE_REMOVE_DEFAULT_APP) { |
| 1248 res += " { RemoveDefault }"; | 1229 res += " { RemoveDefault }"; |
| 1249 } else { | 1230 } else { |
| 1250 res += " { " + item_name + " }"; | 1231 res += " { " + item_name + " }"; |
| 1251 res += " [" + item_ordinal.ToDebugString() + "]"; | 1232 res += " [" + item_ordinal.ToDebugString() + "]"; |
| 1252 if (!parent_id.empty()) | 1233 if (!parent_id.empty()) |
| 1253 res += " <" + parent_id.substr(0, 8) + ">"; | 1234 res += " <" + parent_id.substr(0, 8) + ">"; |
| 1254 res += " [" + item_pin_ordinal.ToDebugString() + "]"; | 1235 res += " [" + item_pin_ordinal.ToDebugString() + "]"; |
| 1255 } | 1236 } |
| 1256 return res; | 1237 return res; |
| 1257 } | 1238 } |
| 1258 | 1239 |
| 1259 } // namespace app_list | 1240 } // namespace app_list |
| OLD | NEW |