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

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

Issue 6905044: Refactor preference syncing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the previous fix Created 9 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class SessionSpecifics; 42 class SessionSpecifics;
43 } // namespace sync_pb 43 } // namespace sync_pb
44 44
45 namespace browser_sync { 45 namespace browser_sync {
46 46
47 static const char kSessionsTag[] = "google_chrome_sessions"; 47 static const char kSessionsTag[] = "google_chrome_sessions";
48 48
49 // Contains all logic for associating the Chrome sessions model and 49 // Contains all logic for associating the Chrome sessions model and
50 // the sync sessions model. 50 // the sync sessions model.
51 class SessionModelAssociator 51 class SessionModelAssociator
52 : public PerDataTypeAssociatorInterface<TabContents, size_t>, 52 : public NewAssociatorInterface,
53 public base::NonThreadSafe { 53 public base::NonThreadSafe {
54 public: 54 public:
55 // Does not take ownership of sync_service. 55 // Does not take ownership of sync_service.
56 explicit SessionModelAssociator(ProfileSyncService* sync_service); 56 explicit SessionModelAssociator(ProfileSyncService* sync_service);
57 SessionModelAssociator(ProfileSyncService* sync_service, 57 SessionModelAssociator(ProfileSyncService* sync_service,
58 bool setup_for_test); 58 bool setup_for_test);
59 virtual ~SessionModelAssociator();
60 59
61 // The has_nodes out parameter is set to true if the sync model has 60 // The has_nodes out parameter is set to true if the sync model has
62 // nodes other than the permanent tagged nodes. The method may 61 // nodes other than the permanent tagged nodes. The method may
63 // return false if an error occurred. 62 // return false if an error occurred.
64 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); 63 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes);
65 64
66 // AssociatorInterface and PerDataTypeAssociator Interface implementation. 65 // AssociatorInterface and PerDataTypeAssociator Interface implementation.
67 virtual void AbortAssociation() { 66 virtual void AbortAssociation() {
68 // No implementation needed, this associator runs on the main thread. 67 // No implementation needed, this associator runs on the main thread.
69 } 68 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 163
165 // Control which local tabs we're interested in syncing. 164 // Control which local tabs we're interested in syncing.
166 // Ensures the profile matches sync's profile and that the tab has at least 165 // Ensures the profile matches sync's profile and that the tab has at least
167 // one navigation entry and is not an empty tab. 166 // one navigation entry and is not an empty tab.
168 bool IsValidTab(const TabContents& tab); 167 bool IsValidTab(const TabContents& tab);
169 168
170 // Control which foreign tabs we're interested in displaying. 169 // Control which foreign tabs we're interested in displaying.
171 // Checks that the tab has navigations and is not a new tab. 170 // Checks that the tab has navigations and is not a new tab.
172 // Note: a new tab page with back/forward history is valid. 171 // Note: a new tab page with back/forward history is valid.
173 static bool IsValidSessionTab(const SessionTab& tab); 172 static bool IsValidSessionTab(const SessionTab& tab);
174
175 // Returns the syncable model type.
176 static syncable::ModelType model_type() { return syncable::SESSIONS; }
177
178 private: 173 private:
179 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode); 174 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, WriteSessionToNode);
180 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, 175 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest,
181 WriteFilledSessionToNode); 176 WriteFilledSessionToNode);
182 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, 177 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest,
183 WriteForeignSessionToNode); 178 WriteForeignSessionToNode);
184 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolEmpty); 179 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolEmpty);
185 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty); 180 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty);
186 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionWindow); 181 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionWindow);
187 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionTab); 182 FRIEND_TEST_ALL_PREFIXES(SessionModelAssociatorTest, PopulateSessionTab);
188 183
184 virtual ~SessionModelAssociator();
185
189 // Keep all the links to local tab data in one place. 186 // Keep all the links to local tab data in one place.
190 class TabLinks { 187 class TabLinks {
191 public: 188 public:
192 // To support usage as second value in maps we need default and copy 189 // To support usage as second value in maps we need default and copy
193 // constructors. 190 // constructors.
194 TabLinks() 191 TabLinks()
195 : sync_id_(0), 192 : sync_id_(0),
196 session_tab_(NULL), 193 session_tab_(NULL),
197 tab_(NULL) {} 194 tab_(NULL) {}
198 195
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 405
409 // To avoid certain checks not applicable to tests. 406 // To avoid certain checks not applicable to tests.
410 bool setup_for_test_; 407 bool setup_for_test_;
411 408
412 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); 409 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator);
413 }; 410 };
414 411
415 } // namespace browser_sync 412 } // namespace browser_sync
416 413
417 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ 414 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698