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) { | |
stevenjb
2014/09/26 16:22:16
one line per arg
Matt Giuca
2014/09/30 02:49:47
I think this is fine, as long as they are all on o
calamity
2014/09/30 05:40:08
Yeah, this is ClangFormat's doing.
stevenjb
2014/09/30 18:16:23
Hm, we should probably update the style guide then
| |
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.folder_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 void OnAppListItemAdded(AppListItem* item) override { | |
238 UpdatePrefsFromAppListItem(item); | |
239 } | |
240 | |
241 void OnAppListItemWillBeDeleted(AppListItem* item) override { | |
242 app_list_prefs_->DeleteAppListInfo(item->id()); | |
243 } | |
244 | |
245 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 }; | |
stevenjb
2014/09/26 16:22:16
This appears to be entirely independent of AppList
Matt Giuca
2014/09/30 02:49:47
It's simple and could be considered an implementat
calamity
2014/09/30 05:40:08
I also think of it as a utility class that allows
stevenjb
2014/09/30 18:16:23
The reason I don't especially like it here is that
calamity
2014/10/01 08:46:14
Done.
FYI, I think our conflict resolution plan i
stevenjb
2014/10/01 16:29:33
There are a couple of things that concern me off t
| |
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 |