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 <set> | 10 #include <set> |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/sync/glue/model_associator.h" | 29 #include "chrome/browser/sync/glue/model_associator.h" |
30 #include "chrome/browser/sync/glue/synced_session_tracker.h" | 30 #include "chrome/browser/sync/glue/synced_session_tracker.h" |
31 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 31 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
32 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 32 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
33 #include "sync/syncable/model_type.h" | 33 #include "sync/syncable/model_type.h" |
34 | 34 |
35 class Prefservice; | 35 class Prefservice; |
36 class Profile; | 36 class Profile; |
37 class ProfileSyncService; | 37 class ProfileSyncService; |
38 | 38 |
| 39 namespace content { |
| 40 class NavigationEntry; |
| 41 } // namespace content |
| 42 |
39 namespace sync_api { | 43 namespace sync_api { |
40 class BaseTransaction; | 44 class BaseTransaction; |
41 class ReadNode; | 45 class ReadNode; |
42 class WriteTransaction; | 46 class WriteTransaction; |
43 } // namespace sync_api | 47 } // namespace sync_api |
44 | 48 |
45 namespace sync_pb { | 49 namespace sync_pb { |
46 class SessionHeader; | 50 class SessionHeader; |
47 class SessionSpecifics; | 51 class SessionSpecifics; |
48 class SessionTab; | 52 class SessionTab; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 289 |
286 // The currently visible url of the tab (used for syncing favicons). | 290 // The currently visible url of the tab (used for syncing favicons). |
287 GURL url_; | 291 GURL url_; |
288 | 292 |
289 // Handle for loading favicons. | 293 // Handle for loading favicons. |
290 FaviconService::Handle favicon_load_handle_; | 294 FaviconService::Handle favicon_load_handle_; |
291 }; | 295 }; |
292 | 296 |
293 // A pool for managing free/used tab sync nodes. Performs lazy creation | 297 // A pool for managing free/used tab sync nodes. Performs lazy creation |
294 // of sync nodes when necessary. | 298 // of sync nodes when necessary. |
| 299 // TODO(zea): pull this into its own file. |
295 class TabNodePool { | 300 class TabNodePool { |
296 public: | 301 public: |
297 explicit TabNodePool(ProfileSyncService* sync_service); | 302 explicit TabNodePool(ProfileSyncService* sync_service); |
298 ~TabNodePool(); | 303 ~TabNodePool(); |
299 | 304 |
300 // Add a previously allocated tab sync node to our pool. Increases the size | 305 // Add a previously allocated tab sync node to our pool. Increases the size |
301 // of tab_syncid_pool_ by one and marks the new tab node as free. | 306 // of tab_syncid_pool_ by one and marks the new tab node as free. |
302 // Note: this should only be called when we discover tab sync nodes from | 307 // Note: this should only be called when we discover tab sync nodes from |
303 // previous sessions, not for freeing tab nodes we created through | 308 // previous sessions, not for freeing tab nodes we created through |
304 // GetFreeTabNode (use FreeTabNode below for that). | 309 // GetFreeTabNode (use FreeTabNode below for that). |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 // load if the url has changed. | 409 // load if the url has changed. |
405 // Returns true on success, false if we need to reassociate due to corruption. | 410 // Returns true on success, false if we need to reassociate due to corruption. |
406 bool WriteTabContentsToSyncModel(TabLink* tab_link, | 411 bool WriteTabContentsToSyncModel(TabLink* tab_link, |
407 SyncError* error); | 412 SyncError* error); |
408 | 413 |
409 // Decrements the favicon usage counters for the favicon used by |page_url|. | 414 // Decrements the favicon usage counters for the favicon used by |page_url|. |
410 // Deletes the favicon and associated pages from the favicon usage maps | 415 // Deletes the favicon and associated pages from the favicon usage maps |
411 // if no page is found to be referring to the favicon anymore. | 416 // if no page is found to be referring to the favicon anymore. |
412 void DecrementAndCleanFaviconForURL(const std::string& page_url); | 417 void DecrementAndCleanFaviconForURL(const std::string& page_url); |
413 | 418 |
| 419 // Helper method to build sync's tab specifics from a newly modified |
| 420 // tab, window, and the locally stored previous tab data. After completing, |
| 421 // |prev_tab| will be updated to reflect the current data, |sync_tab| will |
| 422 // be filled with the tab data (preserving old timestamps as necessary), and |
| 423 // |new_url| will be the tab's current url. |
| 424 void AssociateTabContents(const SyncedWindowDelegate& window, |
| 425 const SyncedTabDelegate& new_tab, |
| 426 SyncedSessionTab* prev_tab, |
| 427 sync_pb::SessionTab* sync_tab, |
| 428 GURL* new_url); |
| 429 |
414 // Load the favicon for the tab specified by |tab_link|. Will cancel any | 430 // Load the favicon for the tab specified by |tab_link|. Will cancel any |
415 // outstanding request for this tab. OnFaviconDataAvailable(..) will be called | 431 // outstanding request for this tab. OnFaviconDataAvailable(..) will be called |
416 // when the load completes. | 432 // when the load completes. |
417 void LoadFaviconForTab(TabLink* tab_link); | 433 void LoadFaviconForTab(TabLink* tab_link); |
418 | 434 |
419 // Callback method to store a tab's favicon into its sync node once it becomes | 435 // Callback method to store a tab's favicon into its sync node once it becomes |
420 // available. Does nothing if no favicon data was available. | 436 // available. Does nothing if no favicon data was available. |
421 void OnFaviconDataAvailable(FaviconService::Handle handle, | 437 void OnFaviconDataAvailable(FaviconService::Handle handle, |
422 history::FaviconData favicon); | 438 history::FaviconData favicon); |
423 | 439 |
424 // Used to populate a session header from the session specifics header | 440 // Used to populate a session header from the session specifics header |
425 // provided. | 441 // provided. |
426 static void PopulateSessionHeaderFromSpecifics( | 442 static void PopulateSessionHeaderFromSpecifics( |
427 const sync_pb::SessionHeader& header_specifics, | 443 const sync_pb::SessionHeader& header_specifics, |
428 const base::Time& mtime, | 444 const base::Time& mtime, |
429 SyncedSession* session_header); | 445 SyncedSession* session_header); |
430 | 446 |
431 // Used to populate a session window from the session specifics window | 447 // Used to populate a session window from the session specifics window |
432 // provided. Tracks any foreign session data created through |tracker|. | 448 // provided. Tracks any foreign session data created through |tracker|. |
433 static void PopulateSessionWindowFromSpecifics( | 449 static void PopulateSessionWindowFromSpecifics( |
434 const std::string& foreign_session_tag, | 450 const std::string& foreign_session_tag, |
435 const sync_pb::SessionWindow& window, | 451 const sync_pb::SessionWindow& window, |
436 const base::Time& mtime, | 452 const base::Time& mtime, |
437 SessionWindow* session_window, | 453 SessionWindow* session_window, |
438 SyncedSessionTracker* tracker); | 454 SyncedSessionTracker* tracker); |
439 | 455 |
440 // Used to populate a session tab from the session specifics tab provided. | 456 // Used to populate a session tab from the session specifics tab provided. |
441 static void PopulateSessionTabFromSpecifics(const sync_pb::SessionTab& tab, | 457 static void PopulateSessionTabFromSpecifics(const sync_pb::SessionTab& tab, |
442 const base::Time& mtime, | 458 const base::Time& mtime, |
443 SessionTab* session_tab); | 459 SyncedSessionTab* session_tab); |
444 | 460 |
445 // Helper method to load the favicon data from the tab specifics. If the | 461 // Helper method to load the favicon data from the tab specifics. If the |
446 // favicon is valid, stores the favicon data and increments the usage counter | 462 // favicon is valid, stores the favicon data and increments the usage counter |
447 // in |synced_favicons_| and updates |synced_favicon_pages_| appropriately. | 463 // in |synced_favicons_| and updates |synced_favicon_pages_| appropriately. |
448 void LoadForeignTabFavicon(const sync_pb::SessionTab& tab); | 464 void LoadForeignTabFavicon(const sync_pb::SessionTab& tab); |
449 | 465 |
450 // Used to populate a session tab from the session specifics tab provided. | 466 // Append a new navigation from sync specifics onto |tab| navigation vectors. |
451 static void AppendSessionTabNavigation( | 467 static void AppendSessionTabNavigation( |
452 const sync_pb::TabNavigation& navigation, | 468 const sync_pb::TabNavigation& navigation, |
453 std::vector<TabNavigation>* navigations); | 469 SyncedSessionTab* tab); |
454 | 470 |
455 // Populates the navigation portion of the session specifics. | 471 // Populates the navigation portion of the session specifics. |
456 static void PopulateSessionSpecificsNavigation( | 472 static void PopulateSessionSpecificsNavigation( |
457 const TabNavigation* navigation, | 473 const content::NavigationEntry& navigation, |
458 sync_pb::TabNavigation* tab_navigation); | 474 sync_pb::TabNavigation* tab_navigation); |
459 | 475 |
460 // Returns true if this tab belongs to this profile and belongs to a window, | 476 // Returns true if this tab belongs to this profile and belongs to a window, |
461 // false otherwise. | 477 // false otherwise. |
462 bool IsValidTab(const SyncedTabDelegate& tab) const; | 478 bool IsValidTab(const SyncedTabDelegate& tab) const; |
463 | 479 |
464 // Having a valid entry is defined as the url being valid and and having a | 480 // Having a valid entry is defined as the url being valid and and having a |
465 // syncable scheme (non chrome:// and file:// url's). In other words, we don't | 481 // syncable scheme (non chrome:// and file:// url's). In other words, we don't |
466 // want to sync a tab that is nothing but chrome:// and file:// navigations or | 482 // want to sync a tab that is nothing but chrome:// and file:// navigations or |
467 // invalid url's. | 483 // invalid url's. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 std::map<std::string, linked_ptr<SyncedFaviconInfo> > synced_favicons_; | 559 std::map<std::string, linked_ptr<SyncedFaviconInfo> > synced_favicons_; |
544 // Map of page URL -> favicon url. | 560 // Map of page URL -> favicon url. |
545 std::map<std::string, std::string> synced_favicon_pages_; | 561 std::map<std::string, std::string> synced_favicon_pages_; |
546 | 562 |
547 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); | 563 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); |
548 }; | 564 }; |
549 | 565 |
550 } // namespace browser_sync | 566 } // namespace browser_sync |
551 | 567 |
552 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ | 568 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ |
OLD | NEW |