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 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ |
6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/browser/sync/glue/sync_start_util.h" | 11 #include "chrome/browser/sync/glue/sync_start_util.h" |
12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
15 #include "sync/api/string_ordinal.h" | 15 #include "sync/api/string_ordinal.h" |
16 #include "sync/api/sync_change.h" | 16 #include "sync/api/sync_change.h" |
17 #include "sync/api/sync_change_processor.h" | 17 #include "sync/api/sync_change_processor.h" |
18 #include "sync/api/sync_error_factory.h" | 18 #include "sync/api/sync_error_factory.h" |
19 #include "sync/api/syncable_service.h" | 19 #include "sync/api/syncable_service.h" |
20 #include "sync/protocol/app_list_specifics.pb.h" | 20 #include "sync/protocol/app_list_specifics.pb.h" |
21 | 21 |
22 class ExtensionAppItem; | |
23 class ExtensionAppModelBuilder; | 22 class ExtensionAppModelBuilder; |
24 class ExtensionService; | |
25 class Profile; | 23 class Profile; |
26 | 24 |
| 25 namespace extensions { |
| 26 class ExtensionSystem; |
| 27 } |
| 28 |
27 namespace sync_pb { | 29 namespace sync_pb { |
28 class AppListSpecifics; | 30 class AppListSpecifics; |
29 } | 31 } |
30 | 32 |
31 namespace app_list { | 33 namespace app_list { |
32 | 34 |
33 class AppListModel; | 35 class AppListModel; |
34 class AppListItem; | 36 class AppListItem; |
35 | 37 |
36 // Keyed Service that owns, stores, and syncs an AppListModel for an | 38 // Keyed Service that owns, stores, and syncs an AppListModel for a profile. |
37 // ExtensionSystem and corresponding profile. | |
38 class AppListSyncableService : public syncer::SyncableService, | 39 class AppListSyncableService : public syncer::SyncableService, |
39 public BrowserContextKeyedService, | 40 public BrowserContextKeyedService, |
40 public content::NotificationObserver { | 41 public content::NotificationObserver { |
41 public: | 42 public: |
42 struct SyncItem { | 43 struct SyncItem { |
43 SyncItem(const std::string& id, | 44 SyncItem(const std::string& id, |
44 sync_pb::AppListSpecifics::AppListItemType type); | 45 sync_pb::AppListSpecifics::AppListItemType type); |
45 ~SyncItem(); | 46 ~SyncItem(); |
46 const std::string item_id; | 47 const std::string item_id; |
47 sync_pb::AppListSpecifics::AppListItemType item_type; | 48 sync_pb::AppListSpecifics::AppListItemType item_type; |
48 std::string item_name; | 49 std::string item_name; |
49 std::string parent_id; | 50 std::string parent_id; |
50 syncer::StringOrdinal page_ordinal; | 51 syncer::StringOrdinal page_ordinal; |
51 syncer::StringOrdinal item_ordinal; | 52 syncer::StringOrdinal item_ordinal; |
52 | 53 |
53 std::string ToString() const; | 54 std::string ToString() const; |
54 }; | 55 }; |
55 | 56 |
56 // Create an empty model. Then, if |extension_service| is non-NULL and ready, | 57 // Populates the model when |extension_system| is ready. |
57 // populate it. Otherwise populate the model once extensions become ready. | 58 AppListSyncableService(Profile* profile, |
58 AppListSyncableService(Profile* profile, ExtensionService* extension_service); | 59 extensions::ExtensionSystem* extension_system); |
59 | 60 |
60 virtual ~AppListSyncableService(); | 61 virtual ~AppListSyncableService(); |
61 | 62 |
62 // Adds |item| to |sync_items_| and |model_|. Does noting if a sync item | 63 // Adds |item| to |sync_items_| and |model_|. Does nothing if a sync item |
63 // already exists. | 64 // already exists. |
64 void AddExtensionAppItem(ExtensionAppItem* item); | 65 void AddItem(AppListItem* item); |
65 | 66 |
66 // Updates existing entry in |sync_items_| from |item|. | 67 // Updates existing entry in |sync_items_| from |item|. |
67 void UpdateExtensionAppItem(ExtensionAppItem* item); | 68 void UpdateItem(AppListItem* item); |
68 | 69 |
69 // Removes sync item matching |id|. | 70 // Removes sync item matching |id|. |
70 void RemoveItem(const std::string& id); | 71 void RemoveItem(const std::string& id); |
71 | 72 |
72 // Returns the existing sync item matching |id| or NULL. | 73 // Returns the existing sync item matching |id| or NULL. |
73 const SyncItem* GetSyncItem(const std::string& id) const; | 74 const SyncItem* GetSyncItem(const std::string& id) const; |
74 | 75 |
75 Profile* profile() { return profile_; } | 76 Profile* profile() { return profile_; } |
76 AppListModel* model() { return model_.get(); } | 77 AppListModel* model() { return model_.get(); } |
77 size_t GetNumSyncItemsForTest() { return sync_items_.size(); } | 78 size_t GetNumSyncItemsForTest() { return sync_items_.size(); } |
(...skipping 15 matching lines...) Expand all Loading... |
93 typedef std::map<std::string, SyncItem*> SyncItemMap; | 94 typedef std::map<std::string, SyncItem*> SyncItemMap; |
94 | 95 |
95 // content::NotificationObserver | 96 // content::NotificationObserver |
96 virtual void Observe(int type, | 97 virtual void Observe(int type, |
97 const content::NotificationSource& source, | 98 const content::NotificationSource& source, |
98 const content::NotificationDetails& details) OVERRIDE; | 99 const content::NotificationDetails& details) OVERRIDE; |
99 | 100 |
100 // Builds the model once ExtensionService is ready. | 101 // Builds the model once ExtensionService is ready. |
101 void BuildModel(); | 102 void BuildModel(); |
102 | 103 |
103 // Creates a new Appitem from |sync_item| and adds it to the model. | |
104 void CreateAppItemFromSyncItem(SyncItem* sync_item); | |
105 | |
106 // Returns true if sync has restarted, otherwise runs |flare_|. | 104 // Returns true if sync has restarted, otherwise runs |flare_|. |
107 bool SyncStarted(); | 105 bool SyncStarted(); |
108 | 106 |
109 // Creates a SyncItem entry and adds |item| to the model. | 107 // Creates or updates a SyncItem from |specifics|. Returns true if a new item |
110 SyncItem* AddItem(sync_pb::AppListSpecifics::AppListItemType type, | 108 // was created. |
111 AppListItem* item); | 109 bool ProcessSyncItem(const sync_pb::AppListSpecifics& specifics); |
| 110 |
| 111 // Handles a newly created sync item (e.g. creates a new Appitem and adds it |
| 112 // to the model or uninstalls a deleted default item. |
| 113 void ProcessNewSyncItem(SyncItem* sync_item); |
| 114 |
| 115 // Handles updating an existing sync item (e.g. updates item positions). |
| 116 void ProcessExistingSyncItem(SyncItem* sync_item); |
112 | 117 |
113 // Sends ADD or CHANGED for sync item. | 118 // Sends ADD or CHANGED for sync item. |
114 void SendSyncChange(SyncItem* sync_item, | 119 void SendSyncChange(SyncItem* sync_item, |
115 syncer::SyncChange::SyncChangeType sync_change_type); | 120 syncer::SyncChange::SyncChangeType sync_change_type); |
116 | 121 |
117 // Returns an existing SyncItem corresponding to |item_id| or NULL. | 122 // Returns an existing SyncItem corresponding to |item_id| or NULL. |
118 SyncItem* FindSyncItem(const std::string& item_id); | 123 SyncItem* FindSyncItem(const std::string& item_id); |
119 | 124 |
120 // Returns a SyncItem corresponding to |item_id|. Sets |new_item| if an item | 125 // Creates a new sync item for |item_id|. |
121 // was created. | 126 SyncItem* CreateSyncItem( |
122 SyncItem* FindOrCreateSyncItem( | |
123 const std::string& item_id, | 127 const std::string& item_id, |
124 sync_pb::AppListSpecifics::AppListItemType type, | 128 sync_pb::AppListSpecifics::AppListItemType item_type); |
125 bool* new_item); | |
126 | |
127 // Creates or updates a SyncItem from |specifics|. Returns true if an item | |
128 // was created. | |
129 bool CreateOrUpdateSyncItem(const sync_pb::AppListSpecifics& specifics); | |
130 | 129 |
131 // Deletes a SyncItem matching |specifics|. | 130 // Deletes a SyncItem matching |specifics|. |
132 void DeleteSyncItem(const sync_pb::AppListSpecifics& specifics); | 131 void DeleteSyncItem(const sync_pb::AppListSpecifics& specifics); |
133 | 132 |
134 Profile* profile_; | 133 Profile* profile_; |
| 134 extensions::ExtensionSystem* extension_system_; |
135 content::NotificationRegistrar registrar_; | 135 content::NotificationRegistrar registrar_; |
136 scoped_ptr<AppListModel> model_; | 136 scoped_ptr<AppListModel> model_; |
137 scoped_ptr<ExtensionAppModelBuilder> apps_builder_; | 137 scoped_ptr<ExtensionAppModelBuilder> apps_builder_; |
138 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 138 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
139 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_; | 139 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_; |
140 SyncItemMap sync_items_; | 140 SyncItemMap sync_items_; |
141 syncer::SyncableService::StartSyncFlare flare_; | 141 syncer::SyncableService::StartSyncFlare flare_; |
142 | 142 |
143 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); | 143 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); |
144 }; | 144 }; |
145 | 145 |
146 } // namespace app_list | 146 } // namespace app_list |
147 | 147 |
148 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ | 148 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ |
OLD | NEW |