OLD | NEW |
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 <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/format_macros.h" | |
15 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
16 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
17 #include "base/scoped_vector.h" | 16 #include "base/scoped_vector.h" |
18 #include "base/string_util.h" | 17 #include "base/string_util.h" |
19 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
20 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
21 #include "chrome/browser/browser_window.h" | 20 #include "chrome/browser/browser_window.h" |
22 #include "chrome/browser/sessions/session_id.h" | 21 #include "chrome/browser/sessions/session_id.h" |
23 #include "chrome/browser/sessions/session_service.h" | 22 #include "chrome/browser/sessions/session_service.h" |
24 #include "chrome/browser/sessions/session_types.h" | 23 #include "chrome/browser/sessions/session_types.h" |
(...skipping 22 matching lines...) Expand all Loading... |
47 static const char kSessionsTag[] = "google_chrome_sessions"; | 46 static const char kSessionsTag[] = "google_chrome_sessions"; |
48 | 47 |
49 // Contains all logic for associating the Chrome sessions model and | 48 // Contains all logic for associating the Chrome sessions model and |
50 // the sync sessions model. | 49 // the sync sessions model. |
51 class SessionModelAssociator | 50 class SessionModelAssociator |
52 : public PerDataTypeAssociatorInterface<TabContents, size_t>, | 51 : public PerDataTypeAssociatorInterface<TabContents, size_t>, |
53 public base::NonThreadSafe { | 52 public base::NonThreadSafe { |
54 public: | 53 public: |
55 // Does not take ownership of sync_service. | 54 // Does not take ownership of sync_service. |
56 explicit SessionModelAssociator(ProfileSyncService* sync_service); | 55 explicit SessionModelAssociator(ProfileSyncService* sync_service); |
57 SessionModelAssociator(ProfileSyncService* sync_service, | |
58 bool setup_for_test); | |
59 virtual ~SessionModelAssociator(); | 56 virtual ~SessionModelAssociator(); |
60 | 57 |
61 // The has_nodes out parameter is set to true if the sync model has | 58 // 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 | 59 // nodes other than the permanent tagged nodes. The method may |
63 // return false if an error occurred. | 60 // return false if an error occurred. |
64 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); | 61 virtual bool SyncModelHasUserCreatedNodes(bool* has_nodes); |
65 | 62 |
66 // AssociatorInterface and PerDataTypeAssociator Interface implementation. | 63 // AssociatorInterface and PerDataTypeAssociator Interface implementation. |
67 virtual void AbortAssociation() { | 64 virtual void AbortAssociation() { |
68 // No implementation needed, this associator runs on the main thread. | 65 // No implementation needed, this associator runs on the main thread. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // SessionTab*'s. | 294 // SessionTab*'s. |
298 void DeleteForeignSessions(); | 295 void DeleteForeignSessions(); |
299 | 296 |
300 // Determine if a window is of a type we're interested in syncing. | 297 // Determine if a window is of a type we're interested in syncing. |
301 static bool ShouldSyncWindowType(const Browser::Type& type); | 298 static bool ShouldSyncWindowType(const Browser::Type& type); |
302 | 299 |
303 // Build a sync tag from tab_node_id. | 300 // Build a sync tag from tab_node_id. |
304 static inline std::string TabIdToTag( | 301 static inline std::string TabIdToTag( |
305 const std::string machine_tag, | 302 const std::string machine_tag, |
306 size_t tab_node_id) { | 303 size_t tab_node_id) { |
307 return StringPrintf("%s %"PRIuS"", | 304 return StringPrintf("%s %lu", |
308 machine_tag.c_str(), tab_node_id); | 305 machine_tag.c_str(), static_cast<unsigned long>(tab_node_id)); |
309 } | 306 } |
310 | 307 |
311 // Initializes the tag corresponding to this machine. | 308 // Initializes the tag corresponding to this machine. |
312 void InitializeCurrentMachineTag(sync_api::WriteTransaction* trans); | 309 void InitializeCurrentMachineTag(sync_api::WriteTransaction* trans); |
313 | 310 |
314 // Updates the server data based upon the current client session. If no node | 311 // Updates the server data based upon the current client session. If no node |
315 // corresponding to this machine exists in the sync model, one is created. | 312 // corresponding to this machine exists in the sync model, one is created. |
316 void UpdateSyncModelDataFromClient(); | 313 void UpdateSyncModelDataFromClient(); |
317 | 314 |
318 // Pulls the current sync model from the sync database and returns true upon | 315 // Pulls the current sync model from the sync database and returns true upon |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 TabLinksMap tab_map_; | 392 TabLinksMap tab_map_; |
396 | 393 |
397 ForeignSessionTracker foreign_session_tracker_; | 394 ForeignSessionTracker foreign_session_tracker_; |
398 | 395 |
399 // Weak pointer. | 396 // Weak pointer. |
400 ProfileSyncService* sync_service_; | 397 ProfileSyncService* sync_service_; |
401 | 398 |
402 // Consumer used to obtain the current session. | 399 // Consumer used to obtain the current session. |
403 CancelableRequestConsumer consumer_; | 400 CancelableRequestConsumer consumer_; |
404 | 401 |
405 // To avoid certain checks not applicable to tests. | |
406 bool setup_for_test_; | |
407 | |
408 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); | 402 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); |
409 }; | 403 }; |
410 | 404 |
411 } // namespace browser_sync | 405 } // namespace browser_sync |
412 | 406 |
413 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 407 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
OLD | NEW |