OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/sessions/session_id.h" | 22 #include "chrome/browser/sessions/session_id.h" |
23 #include "chrome/browser/sessions/session_service.h" | 23 #include "chrome/browser/sessions/session_service.h" |
24 #include "chrome/browser/sessions/session_types.h" | 24 #include "chrome/browser/sessions/session_types.h" |
25 #include "chrome/browser/sync/glue/data_type_error_handler.h" | |
25 #include "chrome/browser/sync/glue/model_associator.h" | 26 #include "chrome/browser/sync/glue/model_associator.h" |
26 #include "chrome/browser/sync/glue/synced_session_tracker.h" | 27 #include "chrome/browser/sync/glue/synced_session_tracker.h" |
27 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 28 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
28 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 29 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
29 #include "sync/syncable/model_type.h" | 30 #include "sync/syncable/model_type.h" |
30 | 31 |
31 class Prefservice; | 32 class Prefservice; |
32 class Profile; | 33 class Profile; |
33 class ProfileSyncService; | 34 class ProfileSyncService; |
34 | 35 |
(...skipping 16 matching lines...) Expand all Loading... | |
51 static const char kSessionsTag[] = "google_chrome_sessions"; | 52 static const char kSessionsTag[] = "google_chrome_sessions"; |
52 | 53 |
53 // Contains all logic for associating the Chrome sessions model and | 54 // Contains all logic for associating the Chrome sessions model and |
54 // the sync sessions model. | 55 // the sync sessions model. |
55 class SessionModelAssociator | 56 class SessionModelAssociator |
56 : public PerDataTypeAssociatorInterface<SyncedTabDelegate, size_t>, | 57 : public PerDataTypeAssociatorInterface<SyncedTabDelegate, size_t>, |
57 public base::SupportsWeakPtr<SessionModelAssociator>, | 58 public base::SupportsWeakPtr<SessionModelAssociator>, |
58 public base::NonThreadSafe { | 59 public base::NonThreadSafe { |
59 public: | 60 public: |
60 // Does not take ownership of sync_service. | 61 // Does not take ownership of sync_service. |
61 explicit SessionModelAssociator(ProfileSyncService* sync_service); | 62 SessionModelAssociator(ProfileSyncService* sync_service, |
63 DataTypeErrorHandler* error_handler); | |
62 SessionModelAssociator(ProfileSyncService* sync_service, | 64 SessionModelAssociator(ProfileSyncService* sync_service, |
63 bool setup_for_test); | 65 bool setup_for_test); |
64 virtual ~SessionModelAssociator(); | 66 virtual ~SessionModelAssociator(); |
65 | 67 |
66 // The has_nodes out parameter is set to true if the sync model has | 68 // The has_nodes out parameter is set to true if the sync model has |
67 // nodes other than the permanent tagged nodes. The method may | 69 // nodes other than the permanent tagged nodes. The method may |
68 // return false if an error occurred. | 70 // return false if an error occurred. |
69 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) OVERRIDE; | 71 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes) OVERRIDE; |
70 | 72 |
71 // AssociatorInterface and PerDataTypeAssociator Interface implementation. | 73 // AssociatorInterface and PerDataTypeAssociator Interface implementation. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 // |error| gets set if any association error occurred. | 126 // |error| gets set if any association error occurred. |
125 // Returns: false if the local session's sync nodes were deleted and | 127 // Returns: false if the local session's sync nodes were deleted and |
126 // reassociation is necessary, true otherwise. | 128 // reassociation is necessary, true otherwise. |
127 bool AssociateTab(const SyncedTabDelegate& tab, | 129 bool AssociateTab(const SyncedTabDelegate& tab, |
128 SyncError* error); | 130 SyncError* error); |
129 | 131 |
130 // Load any foreign session info stored in sync db and update the sync db | 132 // Load any foreign session info stored in sync db and update the sync db |
131 // with local client data. Processes/reuses any sync nodes owned by this | 133 // with local client data. Processes/reuses any sync nodes owned by this |
132 // client and creates any further sync nodes needed to store local header and | 134 // client and creates any further sync nodes needed to store local header and |
133 // tab info. | 135 // tab info. |
134 // |error| gets set if any association error occurred. | 136 // |error| gets set if any association error occurred. |
Nicolas Zea
2012/04/05 22:08:58
remove comment (here and DisassociateModels)
lipalani1
2012/04/05 22:51:03
Done.
| |
135 virtual bool AssociateModels(SyncError* error) OVERRIDE; | 137 virtual SyncError AssociateModels() OVERRIDE; |
136 | 138 |
137 // Initializes the given sync node from the given chrome node id. | 139 // Initializes the given sync node from the given chrome node id. |
138 // Returns false if no sync node was found for the given chrome node id or | 140 // Returns false if no sync node was found for the given chrome node id or |
139 // if the initialization of sync node fails. | 141 // if the initialization of sync node fails. |
140 virtual bool InitSyncNodeFromChromeId(const std::string& id, | 142 virtual bool InitSyncNodeFromChromeId(const std::string& id, |
141 sync_api::BaseNode* sync_node); | 143 sync_api::BaseNode* sync_node); |
142 | 144 |
143 // Clear local sync data buffers. Does not delete sync nodes to avoid | 145 // Clear local sync data buffers. Does not delete sync nodes to avoid |
144 // tombstones. TODO(zea): way to eventually delete orphaned nodes. | 146 // tombstones. TODO(zea): way to eventually delete orphaned nodes. |
145 // |error| gets set if any disassociation error occurred. | 147 // |error| gets set if any disassociation error occurred. |
146 virtual bool DisassociateModels(SyncError* error) OVERRIDE; | 148 virtual SyncError DisassociateModels() OVERRIDE; |
147 | 149 |
148 // Returns the tag used to uniquely identify this machine's session in the | 150 // Returns the tag used to uniquely identify this machine's session in the |
149 // sync model. | 151 // sync model. |
150 const std::string& GetCurrentMachineTag() const { | 152 const std::string& GetCurrentMachineTag() const { |
151 DCHECK(!current_machine_tag_.empty()); | 153 DCHECK(!current_machine_tag_.empty()); |
152 return current_machine_tag_; | 154 return current_machine_tag_; |
153 } | 155 } |
154 | 156 |
155 // Load and associate window and tab data for a foreign session. | 157 // Load and associate window and tab data for a foreign session. |
156 void AssociateForeignSpecifics(const sync_pb::SessionSpecifics& specifics, | 158 void AssociateForeignSpecifics(const sync_pb::SessionSpecifics& specifics, |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 // is made. | 465 // is made. |
464 bool waiting_for_change_; | 466 bool waiting_for_change_; |
465 base::WeakPtrFactory<SessionModelAssociator> test_weak_factory_; | 467 base::WeakPtrFactory<SessionModelAssociator> test_weak_factory_; |
466 | 468 |
467 // Profile being synced. Weak pointer. | 469 // Profile being synced. Weak pointer. |
468 Profile* const profile_; | 470 Profile* const profile_; |
469 | 471 |
470 // Pref service. Used to persist the session sync guid. Weak pointer. | 472 // Pref service. Used to persist the session sync guid. Weak pointer. |
471 PrefService* const pref_service_; | 473 PrefService* const pref_service_; |
472 | 474 |
475 DataTypeErrorHandler* error_handler_; | |
476 | |
473 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); | 477 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); |
474 }; | 478 }; |
475 | 479 |
476 } // namespace browser_sync | 480 } // namespace browser_sync |
477 | 481 |
478 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 482 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
OLD | NEW |