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

Side by Side Diff: chrome/browser/sync/glue/session_model_associator.h

Issue 3825005: Fix syncing of sessions. Numerous changes have been made. Currently, the mode... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Rebased again Created 10 years, 2 months 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_
6 #define CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/scoped_vector.h"
15 #include "chrome/browser/sessions/session_service.h" 16 #include "chrome/browser/sessions/session_service.h"
16 #include "chrome/browser/sessions/session_types.h" 17 #include "chrome/browser/sessions/session_types.h"
17 #include "chrome/browser/sync/engine/syncapi.h" 18 #include "chrome/browser/sync/engine/syncapi.h"
18 #include "chrome/browser/sync/glue/model_associator.h" 19 #include "chrome/browser/sync/glue/model_associator.h"
19 #include "chrome/browser/sync/protocol/session_specifics.pb.h" 20 #include "chrome/browser/sync/protocol/session_specifics.pb.h"
20 #include "chrome/browser/sync/syncable/model_type.h" 21 #include "chrome/browser/sync/syncable/model_type.h"
21 #include "chrome/common/notification_registrar.h" 22 #include "chrome/common/notification_registrar.h"
22 23
23 class Profile; 24 class Profile;
24 class ProfileSyncService; 25 class ProfileSyncService;
25 26
26 namespace sync_api { 27 namespace sync_api {
27 class ReadNode; 28 class ReadNode;
28 class WriteNode; 29 class WriteNode;
29 class WriteTransaction; 30 class WriteTransaction;
30 } // namespace sync_api 31 } // namespace sync_api
31 32
32 namespace sync_pb { 33 namespace sync_pb {
33 class SessionSpecifics; 34 class SessionSpecifics;
34 } // namespace sync_pb 35 } // namespace sync_pb
35 36
36 namespace browser_sync { 37 namespace browser_sync {
37 38
38 static const char kSessionsTag[] = "google_chrome_sessions"; 39 static const char kSessionsTag[] = "google_chrome_sessions";
40
39 // Contains all logic for associating the Chrome sessions model and 41 // Contains all logic for associating the Chrome sessions model and
40 // the sync sessions model. 42 // the sync sessions model.
43 // In the case of sessions, our local model is nothing but a buffer (specifics_)
44 // that gets overwritten everytime there is an update. From it, we build a new
45 // foreign session windows list each time |GetSessionData| is called by the
46 // ForeignSessionHandler.
41 class SessionModelAssociator : public PerDataTypeAssociatorInterface< 47 class SessionModelAssociator : public PerDataTypeAssociatorInterface<
42 sync_pb::SessionSpecifics, std::string>, public NonThreadSafe { 48 sync_pb::SessionSpecifics, std::string>, public NonThreadSafe {
43 public: 49 public:
44 50
45 // Does not take ownership of sync_service. 51 // Does not take ownership of sync_service.
46 explicit SessionModelAssociator(ProfileSyncService* sync_service); 52 explicit SessionModelAssociator(ProfileSyncService* sync_service);
47 virtual ~SessionModelAssociator(); 53 virtual ~SessionModelAssociator();
48 54
49 55
50 // AssociatorInterface and PerDataTypeAssociator Interface implementation. 56 // AssociatorInterface and PerDataTypeAssociator Interface implementation.
51 virtual void AbortAssociation() { 57 virtual void AbortAssociation() {
52 return; 58 return;
53 // No implementation needed, this associator runs on the main 59 // No implementation needed, this associator runs on the main
54 // thread. 60 // thread.
55 } 61 }
56 62
57 // Used to re-associate a foreign session. 63 // Dummy method, we do everything all-at-once in UpdateFromSyncModel.
58 virtual void Associate(const sync_pb::SessionSpecifics* specifics, 64 virtual void Associate(const sync_pb::SessionSpecifics* specifics,
59 int64 sync_id); 65 int64 sync_id) {
66 }
60 67
61 // Updates the sync model with the local client data. 68 // Updates the sync model with the local client data. (calls
69 // UpdateFromSyncModel)
62 virtual bool AssociateModels(); 70 virtual bool AssociateModels();
63 71
64 // The has_nodes out parameter is set to true if the chrome model 72 // The has_nodes out parameter is set to true if the chrome model
65 // has user-created nodes. The method may return false if an error 73 // has user-created nodes. The method may return false if an error
66 // occurred. 74 // occurred.
67 virtual bool ChromeModelHasUserCreatedNodes(bool* has_nodes); 75 virtual bool ChromeModelHasUserCreatedNodes(bool* has_nodes);
68 76
69 // Will update the new tab page with current foreign sessions excluding the 77 // Dummy method, we do everything all-at-once in UpdateFromSyncModel.
70 // one being disassociated. 78 virtual void Disassociate(int64 sync_id) {
71 virtual void Disassociate(int64 sync_id); 79 }
72 80
73 // TODO(jerrica): Add functionality to stop rendering foreign sessions to the 81 // Clear specifics_ buffer and notify foreign session handlers.
74 // new tab page. 82 virtual bool DisassociateModels();
75 virtual bool DisassociateModels() {
76 // There is no local model stored with which to disassociate.
77 return true;
78 }
79 83
80 // Returns the chrome session specifics for the given sync id. 84 // Returns the chrome session specifics for the given sync id.
81 // Returns NULL if no specifics are found for the given sync id. 85 // Returns NULL if no specifics are found for the given sync id.
82 virtual const sync_pb::SessionSpecifics* GetChromeNodeFromSyncId( 86 virtual const sync_pb::SessionSpecifics* GetChromeNodeFromSyncId(
83 int64 sync_id); 87 int64 sync_id);
84 88
85 // Returns whether a node with the given permanent tag was found and update 89 // Returns whether a node with the given permanent tag was found and update
86 // |sync_id| with that node's id. 90 // |sync_id| with that node's id.
87 virtual bool GetSyncIdForTaggedNode(const std::string* tag, int64* sync_id); 91 virtual bool GetSyncIdForTaggedNode(const std::string* tag, int64* sync_id);
88 92
(...skipping 13 matching lines...) Expand all
102 106
103 // The has_nodes out parameter is set to true if the sync model has 107 // The has_nodes out parameter is set to true if the sync model has
104 // nodes other than the permanent tagged nodes. The method may 108 // nodes other than the permanent tagged nodes. The method may
105 // return false if an error occurred. 109 // return false if an error occurred.
106 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); 110 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes);
107 111
108 // Returns the tag used to uniquely identify this machine's session in the 112 // Returns the tag used to uniquely identify this machine's session in the
109 // sync model. 113 // sync model.
110 std::string GetCurrentMachineTag(); 114 std::string GetCurrentMachineTag();
111 115
112 // Pulls the current sync model from the server, and returns true upon update 116 // Updates the server data based upon the current client session. If no node
113 // of the client model. 117 // corresponding to this machine exists in the sync model, one is created.
114 bool GetSessionDataFromSyncModel(std::vector<ForeignSession*>* windows); 118 void UpdateSyncModelDataFromClient();
115 119
120 // Pulls the current sync model from the sync database and returns true upon
121 // update of the client model. Called by SessionChangeProcessor.
122 // Note that the specifics_ vector is reset and built from scratch each time.
123 bool UpdateFromSyncModel(const sync_api::BaseTransaction* trans);
124
125 // Helper for UpdateFromSyncModel. Appends sync data to a vector of specifics.
126 bool QuerySyncModel(const sync_api::BaseTransaction* trans,
127 std::vector<const sync_pb::SessionSpecifics*>& specifics);
128
129 // Builds sessions from buffered specifics data
130 bool GetSessionData(std::vector<ForeignSession*>* sessions);
116 131
117 // Helper method for converting session specifics to windows. 132 // Helper method for converting session specifics to windows.
118 void AppendForeignSessionFromSpecifics( 133 void AppendForeignSessionFromSpecifics(
119 const sync_pb::SessionSpecifics* specifics, 134 const sync_pb::SessionSpecifics* specifics,
120 std::vector<ForeignSession*>* session); 135 std::vector<ForeignSession*>* session);
121 136
122 // Fills the given empty vector with foreign session windows to restore. 137 // Fills the given empty vector with foreign session windows to restore.
123 // If the vector is returned empty, then the session data could not be 138 // If the vector is returned empty, then the session data could not be
124 // converted back into windows. 139 // converted back into windows.
125 void AppendForeignSessionWithID(int64 id, 140 void AppendForeignSessionWithID(int64 id,
126 std::vector<ForeignSession*>* session, 141 std::vector<ForeignSession*>* session,
127 sync_api::BaseTransaction* trans); 142 sync_api::BaseTransaction* trans);
128 143
129 // Returns the syncable model type. 144 // Returns the syncable model type.
130 static syncable::ModelType model_type() { return syncable::SESSIONS; } 145 static syncable::ModelType model_type() { return syncable::SESSIONS; }
131 146
132 // Updates the server data based upon the current client session. If no node
133 // corresponding to this machine exists in the sync model, one is created.
134 void UpdateSyncModelDataFromClient();
135
136 private: 147 private:
137 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode); 148 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode);
138 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, 149 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest,
139 WriteForeignSessionToNode); 150 WriteForeignSessionToNode);
140 151
141 // Returns the session service from |sync_service_|. 152 // Returns the session service from |sync_service_|.
142 SessionService* GetSessionService(); 153 SessionService* GetSessionService();
143 154
144 // Initializes the tag corresponding to this machine. 155 // Initializes the tag corresponding to this machine.
156 // Note: creates a syncable::BaseTransaction.
145 void InitializeCurrentMachineTag(); 157 void InitializeCurrentMachineTag();
146 158
147 // Populates the navigation portion of the session specifics. 159 // Populates the navigation portion of the session specifics.
148 void PopulateSessionSpecificsNavigation(const TabNavigation* navigation, 160 void PopulateSessionSpecificsNavigation(const TabNavigation* navigation,
149 sync_pb::TabNavigation* tab_navigation); 161 sync_pb::TabNavigation* tab_navigation);
150 162
151 // Populates the tab portion of the session specifics. 163 // Populates the tab portion of the session specifics.
152 void PopulateSessionSpecificsTab(const SessionTab* tab, 164 void PopulateSessionSpecificsTab(const SessionTab* tab,
153 sync_pb::SessionTab* session_tab); 165 sync_pb::SessionTab* session_tab);
154 166
(...skipping 20 matching lines...) Expand all
175 // Used to populate a session window from the session specifics window 187 // Used to populate a session window from the session specifics window
176 // provided. 188 // provided.
177 void PopulateSessionWindowFromSpecifics(SessionWindow* session_window, 189 void PopulateSessionWindowFromSpecifics(SessionWindow* session_window,
178 const sync_pb::SessionWindow* window); 190 const sync_pb::SessionWindow* window);
179 191
180 // Updates the current session on the server. Creates a node for this machine 192 // Updates the current session on the server. Creates a node for this machine
181 // if there is not one already. 193 // if there is not one already.
182 bool UpdateSyncModel(sync_pb::SessionSpecifics* session_data, 194 bool UpdateSyncModel(sync_pb::SessionSpecifics* session_data,
183 sync_api::WriteTransaction* trans, 195 sync_api::WriteTransaction* trans,
184 const sync_api::ReadNode* root); 196 const sync_api::ReadNode* root);
185
186 // Stores the machine tag. 197 // Stores the machine tag.
187 std::string current_machine_tag_; 198 std::string current_machine_tag_;
188 199
200 // Stores the current set of foreign session specifics.
201 // Used by ForeignSessionHandler through |GetSessionData|.
202 // Built by |QuerySyncModel| via |UpdateFromSyncModel|.
203 std::vector<const sync_pb::SessionSpecifics*> specifics_;
204
189 // Weak pointer. 205 // Weak pointer.
190 ProfileSyncService* sync_service_; 206 ProfileSyncService* sync_service_;
191 207
192 // Consumer used to obtain the current session. 208 // Consumer used to obtain the current session.
193 CancelableRequestConsumer consumer_; 209 CancelableRequestConsumer consumer_;
194 210
195 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); 211 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator);
196 }; 212 };
197 213
198 } // namespace browser_sync 214 } // namespace browser_sync
199 215
200 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ 216 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_
201
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_change_processor.cc ('k') | chrome/browser/sync/glue/session_model_associator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698