Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/ui/app_list/app_list_syncable_service.h

Issue 118463002: Sync removal of Default apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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; 23 class ExtensionService;
tapted 2013/12/19 01:20:57 nit: this foward-dec probably isn't needed any lon
stevenjb 2013/12/19 01:48:44 Done.
25 class Profile; 24 class Profile;
26 25
27 namespace sync_pb { 26 namespace sync_pb {
28 class AppListSpecifics; 27 class AppListSpecifics;
29 } 28 }
30 29
31 namespace app_list { 30 namespace app_list {
32 31
33 class AppListModel; 32 class AppListModel;
34 class AppListItemModel; 33 class AppListItemModel;
35 34
36 // Keyed Service that owns, stores, and syncs an AppListModel for an 35 // Keyed Service that owns, stores, and syncs an AppListModel for a profile.
37 // ExtensionSystem and corresponding profile.
38 class AppListSyncableService : public syncer::SyncableService, 36 class AppListSyncableService : public syncer::SyncableService,
39 public BrowserContextKeyedService, 37 public BrowserContextKeyedService,
40 public content::NotificationObserver { 38 public content::NotificationObserver {
41 public: 39 public:
42 struct SyncItem { 40 struct SyncItem {
43 SyncItem(const std::string& id, 41 SyncItem(const std::string& id,
44 sync_pb::AppListSpecifics::AppListItemType type); 42 sync_pb::AppListSpecifics::AppListItemType type);
45 ~SyncItem(); 43 ~SyncItem();
46 const std::string item_id; 44 const std::string item_id;
47 sync_pb::AppListSpecifics::AppListItemType item_type; 45 sync_pb::AppListSpecifics::AppListItemType item_type;
48 std::string item_name; 46 std::string item_name;
49 std::string parent_id; 47 std::string parent_id;
50 syncer::StringOrdinal page_ordinal; 48 syncer::StringOrdinal page_ordinal;
51 syncer::StringOrdinal item_ordinal; 49 syncer::StringOrdinal item_ordinal;
52 50
53 std::string ToString() const; 51 std::string ToString() const;
54 }; 52 };
55 53
56 // Create an empty model. Then, if |extension_service| is non-NULL and ready, 54 // Populates the model when the extension service is ready.
57 // populate it. Otherwise populate the model once extensions become ready. 55 explicit AppListSyncableService(Profile* profile);
58 AppListSyncableService(Profile* profile, ExtensionService* extension_service);
59 56
60 virtual ~AppListSyncableService(); 57 virtual ~AppListSyncableService();
61 58
62 // Adds |item| to |sync_items_| and |model_|. Does noting if a sync item 59 // Adds |item| to |sync_items_| and |model_|. Does nothing if a sync item
63 // already exists. 60 // already exists.
64 void AddExtensionAppItem(ExtensionAppItem* item); 61 void AddItem(AppListItemModel* item);
65 62
66 // Updates existing entry in |sync_items_| from |item|. 63 // Updates existing entry in |sync_items_| from |item|.
67 void UpdateExtensionAppItem(ExtensionAppItem* item); 64 void UpdateItem(AppListItemModel* item);
68 65
69 // Removes sync item matching |id|. 66 // Removes sync item matching |id|.
70 void RemoveItem(const std::string& id); 67 void RemoveItem(const std::string& id);
71 68
72 // Returns the existing sync item matching |id| or NULL. 69 // Returns the existing sync item matching |id| or NULL.
73 const SyncItem* GetSyncItem(const std::string& id) const; 70 const SyncItem* GetSyncItem(const std::string& id) const;
74 71
75 Profile* profile() { return profile_; } 72 Profile* profile() { return profile_; }
76 AppListModel* model() { return model_.get(); } 73 AppListModel* model() { return model_.get(); }
77 size_t GetNumSyncItemsForTest() { return sync_items_.size(); } 74 size_t GetNumSyncItemsForTest() { return sync_items_.size(); }
(...skipping 15 matching lines...) Expand all
93 typedef std::map<std::string, SyncItem*> SyncItemMap; 90 typedef std::map<std::string, SyncItem*> SyncItemMap;
94 91
95 // content::NotificationObserver 92 // content::NotificationObserver
96 virtual void Observe(int type, 93 virtual void Observe(int type,
97 const content::NotificationSource& source, 94 const content::NotificationSource& source,
98 const content::NotificationDetails& details) OVERRIDE; 95 const content::NotificationDetails& details) OVERRIDE;
99 96
100 // Builds the model once ExtensionService is ready. 97 // Builds the model once ExtensionService is ready.
101 void BuildModel(); 98 void BuildModel();
102 99
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_|. 100 // Returns true if sync has restarted, otherwise runs |flare_|.
107 bool SyncStarted(); 101 bool SyncStarted();
108 102
109 // Creates a SyncItem entry and adds |item| to the model. 103 // Creates or updates a SyncItem from |specifics|. Returns true if a new item
110 SyncItem* AddItem(sync_pb::AppListSpecifics::AppListItemType type, 104 // was created.
111 AppListItemModel* item); 105 bool ProcessSyncItem(const sync_pb::AppListSpecifics& specifics);
106
107 // Handles a newly created sync item (e.g. creates a new Appitem and adds it
108 // to the model or uninstalls a deleted default item.
109 void ProcessNewSyncItem(SyncItem* sync_item);
110
111 // Handles updating an existing sync item (e.g. updates item positions).
112 void ProcessExistingSyncItem(SyncItem* sync_item);
112 113
113 // Sends ADD or CHANGED for sync item. 114 // Sends ADD or CHANGED for sync item.
114 void SendSyncChange(SyncItem* sync_item, 115 void SendSyncChange(SyncItem* sync_item,
115 syncer::SyncChange::SyncChangeType sync_change_type); 116 syncer::SyncChange::SyncChangeType sync_change_type);
116 117
117 // Returns an existing SyncItem corresponding to |item_id| or NULL. 118 // Returns an existing SyncItem corresponding to |item_id| or NULL.
118 SyncItem* FindSyncItem(const std::string& item_id); 119 SyncItem* FindSyncItem(const std::string& item_id);
119 120
120 // Returns a SyncItem corresponding to |item_id|. Sets |new_item| if an item 121 // Creates a new sync item for |item_id|.
121 // was created. 122 SyncItem* CreateSyncItem(
122 SyncItem* FindOrCreateSyncItem(
123 const std::string& item_id, 123 const std::string& item_id,
124 sync_pb::AppListSpecifics::AppListItemType type, 124 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 125
131 // Deletes a SyncItem matching |specifics|. 126 // Deletes a SyncItem matching |specifics|.
132 void DeleteSyncItem(const sync_pb::AppListSpecifics& specifics); 127 void DeleteSyncItem(const sync_pb::AppListSpecifics& specifics);
133 128
134 Profile* profile_; 129 Profile* profile_;
135 content::NotificationRegistrar registrar_; 130 content::NotificationRegistrar registrar_;
136 scoped_ptr<AppListModel> model_; 131 scoped_ptr<AppListModel> model_;
137 scoped_ptr<ExtensionAppModelBuilder> apps_builder_; 132 scoped_ptr<ExtensionAppModelBuilder> apps_builder_;
138 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 133 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
139 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_; 134 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler_;
140 SyncItemMap sync_items_; 135 SyncItemMap sync_items_;
141 syncer::SyncableService::StartSyncFlare flare_; 136 syncer::SyncableService::StartSyncFlare flare_;
142 137
143 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService); 138 DISALLOW_COPY_AND_ASSIGN(AppListSyncableService);
144 }; 139 };
145 140
146 } // namespace app_list 141 } // namespace app_list
147 142
148 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_ 143 #endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_SYNCABLE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698