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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/apps/drive/drive_app_provider.h" | 8 #include "chrome/browser/apps/drive/drive_app_provider.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/app_list/app_list_prefs.h" |
12 #include "chrome/browser/ui/app_list/app_list_service.h" | 13 #include "chrome/browser/ui/app_list/app_list_service.h" |
13 #include "chrome/browser/ui/app_list/extension_app_item.h" | 14 #include "chrome/browser/ui/app_list/extension_app_item.h" |
14 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" | 15 #include "chrome/browser/ui/app_list/extension_app_model_builder.h" |
15 #include "chrome/browser/ui/host_desktop.h" | 16 #include "chrome/browser/ui/host_desktop.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
19 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
20 #include "extensions/browser/extension_prefs.h" | 21 #include "extensions/browser/extension_prefs.h" |
21 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 VLOG(2) << owner_ << " OnAppListItemUpdated: " << item->ToDebugString(); | 197 VLOG(2) << owner_ << " OnAppListItemUpdated: " << item->ToDebugString(); |
197 owner_->UpdateSyncItem(item); | 198 owner_->UpdateSyncItem(item); |
198 } | 199 } |
199 | 200 |
200 AppListSyncableService* owner_; | 201 AppListSyncableService* owner_; |
201 AppListItem* adding_item_; // Unowned pointer to item being added. | 202 AppListItem* adding_item_; // Unowned pointer to item being added. |
202 | 203 |
203 DISALLOW_COPY_AND_ASSIGN(ModelObserver); | 204 DISALLOW_COPY_AND_ASSIGN(ModelObserver); |
204 }; | 205 }; |
205 | 206 |
| 207 // AppListSyncableService::PrefUpdater |
| 208 |
| 209 class AppListSyncableService::PrefUpdater : public AppListModelObserver { |
| 210 public: |
| 211 explicit PrefUpdater(AppListPrefs* app_list_prefs, AppListModel* model) |
| 212 : app_list_prefs_(app_list_prefs), model_(model) { |
| 213 model_->AddObserver(this); |
| 214 } |
| 215 |
| 216 virtual ~PrefUpdater() { model_->RemoveObserver(this); } |
| 217 |
| 218 private: |
| 219 void UpdatePrefsFromAppListItem(AppListItem* item) { |
| 220 // Write synced data to local pref. |
| 221 AppListPrefs::AppListInfo info; |
| 222 if (item->GetItemType() == AppListFolderItem::kItemType) |
| 223 info.item_type = AppListPrefs::AppListInfo::FOLDER_ITEM; |
| 224 else if (item->GetItemType() == ExtensionAppItem::kItemType) |
| 225 info.item_type = AppListPrefs::AppListInfo::APP_ITEM; |
| 226 else |
| 227 NOTREACHED(); |
| 228 |
| 229 info.parent_id = item->folder_id(); |
| 230 info.position = item->position(); |
| 231 info.name = item->name(); |
| 232 |
| 233 app_list_prefs_->SetAppListInfo(item->id(), info); |
| 234 } |
| 235 |
| 236 // Overridden from AppListModelObserver: |
| 237 virtual void OnAppListItemAdded(AppListItem* item) OVERRIDE { |
| 238 UpdatePrefsFromAppListItem(item); |
| 239 } |
| 240 |
| 241 virtual void OnAppListItemWillBeDeleted(AppListItem* item) OVERRIDE { |
| 242 app_list_prefs_->DeleteAppListInfo(item->id()); |
| 243 } |
| 244 |
| 245 virtual void OnAppListItemUpdated(AppListItem* item) OVERRIDE { |
| 246 UpdatePrefsFromAppListItem(item); |
| 247 } |
| 248 |
| 249 AppListPrefs* app_list_prefs_; |
| 250 AppListModel* model_; |
| 251 |
| 252 DISALLOW_COPY_AND_ASSIGN(PrefUpdater); |
| 253 }; |
| 254 |
206 // AppListSyncableService | 255 // AppListSyncableService |
207 | 256 |
208 AppListSyncableService::AppListSyncableService( | 257 AppListSyncableService::AppListSyncableService( |
209 Profile* profile, | 258 Profile* profile, |
210 extensions::ExtensionSystem* extension_system) | 259 extensions::ExtensionSystem* extension_system) |
211 : profile_(profile), | 260 : profile_(profile), |
212 extension_system_(extension_system), | 261 extension_system_(extension_system), |
213 model_(new AppListModel), | 262 model_(new AppListModel), |
214 initial_sync_data_processed_(false), | 263 initial_sync_data_processed_(false), |
215 first_app_list_sync_(true) { | 264 first_app_list_sync_(true) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 DCHECK(profile_); | 306 DCHECK(profile_); |
258 if (app_list::switches::IsAppListSyncEnabled()) { | 307 if (app_list::switches::IsAppListSyncEnabled()) { |
259 VLOG(1) << this << ": AppListSyncableService: InitializeWithService."; | 308 VLOG(1) << this << ": AppListSyncableService: InitializeWithService."; |
260 SyncStarted(); | 309 SyncStarted(); |
261 apps_builder_->InitializeWithService(this); | 310 apps_builder_->InitializeWithService(this); |
262 } else { | 311 } else { |
263 VLOG(1) << this << ": AppListSyncableService: InitializeWithProfile."; | 312 VLOG(1) << this << ": AppListSyncableService: InitializeWithProfile."; |
264 apps_builder_->InitializeWithProfile(profile_, model_.get()); | 313 apps_builder_->InitializeWithProfile(profile_, model_.get()); |
265 } | 314 } |
266 | 315 |
| 316 pref_updater_.reset( |
| 317 new PrefUpdater(AppListPrefs::Get(profile_), model_.get())); |
| 318 |
267 if (app_list::switches::IsDriveAppsInAppListEnabled()) | 319 if (app_list::switches::IsDriveAppsInAppListEnabled()) |
268 drive_app_provider_.reset(new DriveAppProvider(profile_)); | 320 drive_app_provider_.reset(new DriveAppProvider(profile_)); |
269 } | 321 } |
270 | 322 |
271 void AppListSyncableService::ResetDriveAppProviderForTest() { | 323 void AppListSyncableService::ResetDriveAppProviderForTest() { |
272 drive_app_provider_.reset(); | 324 drive_app_provider_.reset(); |
273 } | 325 } |
274 | 326 |
275 void AppListSyncableService::Shutdown() { | 327 void AppListSyncableService::Shutdown() { |
276 // DriveAppProvider touches other KeyedServices in its dtor and needs be | 328 // DriveAppProvider touches other KeyedServices in its dtor and needs be |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 } else { | 977 } else { |
926 res += " { " + item_name + " }"; | 978 res += " { " + item_name + " }"; |
927 res += " [" + item_ordinal.ToDebugString() + "]"; | 979 res += " [" + item_ordinal.ToDebugString() + "]"; |
928 if (!parent_id.empty()) | 980 if (!parent_id.empty()) |
929 res += " <" + parent_id.substr(0, 8) + ">"; | 981 res += " <" + parent_id.substr(0, 8) + ">"; |
930 } | 982 } |
931 return res; | 983 return res; |
932 } | 984 } |
933 | 985 |
934 } // namespace app_list | 986 } // namespace app_list |
OLD | NEW |