| 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 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 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/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "chrome/browser/sessions/session_id.h" | 20 #include "chrome/browser/sessions/session_id.h" |
| 21 #include "chrome/browser/sessions/session_service.h" | 21 #include "chrome/browser/sessions/session_service.h" |
| 22 #include "chrome/browser/sessions/session_types.h" | 22 #include "chrome/browser/sessions/session_types.h" |
| 23 #include "chrome/browser/sync/glue/favicon_cache.h" | 23 #include "chrome/browser/sync/glue/favicon_cache.h" |
| 24 #include "chrome/browser/sync/glue/model_associator.h" | 24 #include "chrome/browser/sync/glue/model_associator.h" |
| 25 #include "chrome/browser/sync/glue/synced_session_tracker.h" | 25 #include "chrome/browser/sync/glue/synced_session_tracker.h" |
| 26 #include "chrome/browser/sync/glue/tab_node_pool.h" | 26 #include "chrome/browser/sync/glue/tab_node_pool.h" |
| 27 #include "chrome/browser/sync/open_tabs_ui_delegate.h" |
| 27 #include "sync/internal_api/public/base/model_type.h" | 28 #include "sync/internal_api/public/base/model_type.h" |
| 28 | 29 |
| 29 class PrefServiceSyncable; | 30 class PrefServiceSyncable; |
| 30 class Profile; | 31 class Profile; |
| 31 class ProfileSyncService; | 32 class ProfileSyncService; |
| 32 | 33 |
| 33 namespace syncer { | 34 namespace syncer { |
| 34 class ReadNode; | 35 class ReadNode; |
| 35 class WriteTransaction; | 36 class WriteTransaction; |
| 36 } // namespace syncer | 37 } // namespace syncer |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 | 48 |
| 48 class DataTypeErrorHandler; | 49 class DataTypeErrorHandler; |
| 49 class DeviceInfo; | 50 class DeviceInfo; |
| 50 class SyncedTabDelegate; | 51 class SyncedTabDelegate; |
| 51 class SyncedWindowDelegate; | 52 class SyncedWindowDelegate; |
| 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 AssociatorInterface, | 57 : public AssociatorInterface, |
| 58 public OpenTabsUIDelegate, |
| 57 public base::SupportsWeakPtr<SessionModelAssociator>, | 59 public base::SupportsWeakPtr<SessionModelAssociator>, |
| 58 public base::NonThreadSafe { | 60 public base::NonThreadSafe { |
| 59 public: | 61 public: |
| 60 // Does not take ownership of sync_service. | 62 // Does not take ownership of sync_service. |
| 61 SessionModelAssociator(ProfileSyncService* sync_service, | 63 SessionModelAssociator(ProfileSyncService* sync_service, |
| 62 DataTypeErrorHandler* error_handler); | 64 DataTypeErrorHandler* error_handler); |
| 63 SessionModelAssociator(ProfileSyncService* sync_service, | 65 SessionModelAssociator(ProfileSyncService* sync_service, |
| 64 bool setup_for_test); | 66 bool setup_for_test); |
| 65 virtual ~SessionModelAssociator(); | 67 virtual ~SessionModelAssociator(); |
| 66 | 68 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Attempts to asynchronously refresh the sessions sync data. If new data is | 142 // Attempts to asynchronously refresh the sessions sync data. If new data is |
| 141 // received, the FOREIGN_SESSIONS_UPDATED notification is sent. No | 143 // received, the FOREIGN_SESSIONS_UPDATED notification is sent. No |
| 142 // notification will be sent otherwise. This method is not guaranteed to | 144 // notification will be sent otherwise. This method is not guaranteed to |
| 143 // trigger a sync cycle. | 145 // trigger a sync cycle. |
| 144 void AttemptSessionsDataRefresh() const; | 146 void AttemptSessionsDataRefresh() const; |
| 145 | 147 |
| 146 // Sets |*local_session| to point to the associator's representation of the | 148 // Sets |*local_session| to point to the associator's representation of the |
| 147 // local machine. Used primarily for testing. | 149 // local machine. Used primarily for testing. |
| 148 bool GetLocalSession(const SyncedSession* * local_session); | 150 bool GetLocalSession(const SyncedSession* * local_session); |
| 149 | 151 |
| 150 // Builds a list of all foreign sessions. Caller does NOT own SyncedSession | |
| 151 // objects. | |
| 152 // Returns true if foreign sessions were found, false otherwise. | |
| 153 bool GetAllForeignSessions(std::vector<const SyncedSession*>* sessions); | |
| 154 | |
| 155 // Loads all windows for foreign session with session tag |tag|. Caller does | |
| 156 // NOT own SyncedSession objects. | |
| 157 // Returns true if the foreign session was found, false otherwise. | |
| 158 bool GetForeignSession(const std::string& tag, | |
| 159 std::vector<const SessionWindow*>* windows); | |
| 160 | |
| 161 // Looks up the foreign tab identified by |tab_id| and belonging to foreign | |
| 162 // session |tag|. Caller does NOT own the SessionTab object. | |
| 163 // Returns true if the foreign session and tab were found, false otherwise. | |
| 164 bool GetForeignTab(const std::string& tag, | |
| 165 const SessionID::id_type tab_id, | |
| 166 const SessionTab** tab); | |
| 167 | |
| 168 // Triggers garbage collection of stale sessions (as defined by | 152 // Triggers garbage collection of stale sessions (as defined by |
| 169 // |stale_session_threshold_days_|). This is called automatically every | 153 // |stale_session_threshold_days_|). This is called automatically every |
| 170 // time we start up (via AssociateModels). | 154 // time we start up (via AssociateModels). |
| 171 void DeleteStaleSessions(); | 155 void DeleteStaleSessions(); |
| 172 | 156 |
| 173 // Set the threshold of inactivity (in days) at which we consider sessions | 157 // Set the threshold of inactivity (in days) at which we consider sessions |
| 174 // stale. | 158 // stale. |
| 175 void SetStaleSessionThreshold(size_t stale_session_threshold_days); | 159 void SetStaleSessionThreshold(size_t stale_session_threshold_days); |
| 176 | 160 |
| 177 // Delete a foreign session and all its sync data. | |
| 178 void DeleteForeignSession(const std::string& tag); | |
| 179 | |
| 180 // Control which local tabs we're interested in syncing. | 161 // Control which local tabs we're interested in syncing. |
| 181 // Ensures the profile matches sync's profile and that the tab has valid | 162 // Ensures the profile matches sync's profile and that the tab has valid |
| 182 // entries. | 163 // entries. |
| 183 bool ShouldSyncTab(const SyncedTabDelegate& tab) const; | 164 bool ShouldSyncTab(const SyncedTabDelegate& tab) const; |
| 184 | 165 |
| 185 // Compare |urls| against |local_tab_map_|'s urls to see if any tabs with | 166 // Compare |urls| against |local_tab_map_|'s urls to see if any tabs with |
| 186 // outstanding favicon loads can be fulfilled. | 167 // outstanding favicon loads can be fulfilled. |
| 187 void FaviconsUpdated(const std::set<GURL>& urls); | 168 void FaviconsUpdated(const std::set<GURL>& urls); |
| 188 | 169 |
| 189 // Returns the syncable model type. | 170 // Returns the syncable model type. |
| 190 static syncer::ModelType model_type() { return syncer::SESSIONS; } | 171 static syncer::ModelType model_type() { return syncer::SESSIONS; } |
| 191 | 172 |
| 192 // Testing only. Will cause the associator to call MessageLoop::Quit() | 173 // Testing only. Will cause the associator to call MessageLoop::Quit() |
| 193 // when a local change is made, or when timeout occurs, whichever is | 174 // when a local change is made, or when timeout occurs, whichever is |
| 194 // first. | 175 // first. |
| 195 void BlockUntilLocalChangeForTest(base::TimeDelta timeout); | 176 void BlockUntilLocalChangeForTest(base::TimeDelta timeout); |
| 196 | 177 |
| 197 // If a valid favicon for the page at |url| is found, fills |favicon_png| with | 178 // OpenTabsUIDelegate implementation. |
| 198 // the png-encoded image and returns true. Else, returns false. | 179 virtual bool GetSyncedFaviconForPageURL( |
| 199 bool GetSyncedFaviconForPageURL( | |
| 200 const std::string& pageurl, | 180 const std::string& pageurl, |
| 201 scoped_refptr<base::RefCountedMemory>* favicon_png) const; | 181 scoped_refptr<base::RefCountedMemory>* favicon_png) const OVERRIDE; |
| 182 virtual bool GetAllForeignSessions( |
| 183 std::vector<const SyncedSession*>* sessions) OVERRIDE; |
| 184 virtual bool GetForeignSession( |
| 185 const std::string& tag, |
| 186 std::vector<const SessionWindow*>* windows) OVERRIDE; |
| 187 virtual bool GetForeignTab(const std::string& tag, |
| 188 const SessionID::id_type tab_id, |
| 189 const SessionTab** tab) OVERRIDE; |
| 190 virtual void DeleteForeignSession(const std::string& tag) OVERRIDE; |
| 202 | 191 |
| 203 void SetCurrentMachineTagForTesting(const std::string& machine_tag) { | 192 void SetCurrentMachineTagForTesting(const std::string& machine_tag) { |
| 204 current_machine_tag_ = machine_tag; | 193 current_machine_tag_ = machine_tag; |
| 205 } | 194 } |
| 206 | 195 |
| 207 // Gets the device info for a given session tag. | 196 // Gets the device info for a given session tag. |
| 208 scoped_ptr<browser_sync::DeviceInfo> GetDeviceInfoForSessionTag( | 197 scoped_ptr<browser_sync::DeviceInfo> GetDeviceInfoForSessionTag( |
| 209 const std::string& session_tag); | 198 const std::string& session_tag); |
| 210 | 199 |
| 211 FaviconCache* GetFaviconCache(); | 200 FaviconCache* GetFaviconCache(); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 FaviconCache favicon_cache_; | 371 FaviconCache favicon_cache_; |
| 383 | 372 |
| 384 base::WeakPtrFactory<SessionModelAssociator> test_weak_factory_; | 373 base::WeakPtrFactory<SessionModelAssociator> test_weak_factory_; |
| 385 | 374 |
| 386 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); | 375 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); |
| 387 }; | 376 }; |
| 388 | 377 |
| 389 } // namespace browser_sync | 378 } // namespace browser_sync |
| 390 | 379 |
| 391 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 380 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
| OLD | NEW |