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

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

Issue 10990012: [Sync] Refactor handling of session tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Few more fixes Created 8 years, 2 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) 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>
(...skipping 11 matching lines...) Expand all
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "chrome/browser/favicon/favicon_service.h" 23 #include "chrome/browser/favicon/favicon_service.h"
24 #include "chrome/browser/sessions/session_id.h" 24 #include "chrome/browser/sessions/session_id.h"
25 #include "chrome/browser/sessions/session_service.h" 25 #include "chrome/browser/sessions/session_service.h"
26 #include "chrome/browser/sessions/session_types.h" 26 #include "chrome/browser/sessions/session_types.h"
27 #include "chrome/browser/sync/glue/data_type_error_handler.h" 27 #include "chrome/browser/sync/glue/data_type_error_handler.h"
28 #include "chrome/browser/sync/glue/model_associator.h" 28 #include "chrome/browser/sync/glue/model_associator.h"
29 #include "chrome/browser/sync/glue/synced_session_tracker.h" 29 #include "chrome/browser/sync/glue/synced_session_tracker.h"
30 #include "chrome/browser/sync/glue/synced_tab_delegate.h" 30 #include "chrome/browser/sync/glue/synced_tab_delegate.h"
31 #include "chrome/browser/sync/glue/synced_window_delegate.h" 31 #include "chrome/browser/sync/glue/synced_window_delegate.h"
32 #include "googleurl/src/gurl.h"
32 #include "sync/internal_api/public/base/model_type.h" 33 #include "sync/internal_api/public/base/model_type.h"
33 34
34 class Prefservice; 35 class Prefservice;
35 class Profile; 36 class Profile;
36 class ProfileSyncService; 37 class ProfileSyncService;
37 38
38 namespace content { 39 namespace content {
39 class NavigationEntry; 40 class NavigationEntry;
40 } // namespace content 41 } // namespace content
41 42
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Returns true on success, false if association failed. 397 // Returns true on success, false if association failed.
397 bool UpdateSyncModelDataFromClient(syncer::SyncError* error); 398 bool UpdateSyncModelDataFromClient(syncer::SyncError* error);
398 399
399 // Pulls the current sync model from the sync database and returns true upon 400 // Pulls the current sync model from the sync database and returns true upon
400 // update of the client model. Will associate any foreign sessions as well as 401 // update of the client model. Will associate any foreign sessions as well as
401 // keep track of any local tab nodes, adding them to our free tab node pool. 402 // keep track of any local tab nodes, adding them to our free tab node pool.
402 bool UpdateAssociationsFromSyncModel(const syncer::ReadNode& root, 403 bool UpdateAssociationsFromSyncModel(const syncer::ReadNode& root,
403 syncer::WriteTransaction* trans, 404 syncer::WriteTransaction* trans,
404 syncer::SyncError* error); 405 syncer::SyncError* error);
405 406
407 // Return the virtual URL of the current tab, even if it's pending.
408 static GURL GetCurrentVirtualURL(const SyncedTabDelegate& tab_delegate);
409
406 // Fills a tab sync node with data from a WebContents object. Updates 410 // Fills a tab sync node with data from a WebContents object. Updates
407 // |tab_link| with the current url if it's valid and triggers a favicon 411 // |tab_link| with the current url if it's valid and triggers a favicon
408 // load if the url has changed. 412 // load if the url has changed.
409 // Returns true on success, false if we need to reassociate due to corruption. 413 // Returns true on success, false if we need to reassociate due to corruption.
410 bool WriteTabContentsToSyncModel(TabLink* tab_link, 414 bool WriteTabContentsToSyncModel(TabLink* tab_link,
411 syncer::SyncError* error); 415 syncer::SyncError* error);
412 416
413 // Decrements the favicon usage counters for the favicon used by |page_url|. 417 // Decrements the favicon usage counters for the favicon used by |page_url|.
414 // Deletes the favicon and associated pages from the favicon usage maps 418 // Deletes the favicon and associated pages from the favicon usage maps
415 // if no page is found to be referring to the favicon anymore. 419 // if no page is found to be referring to the favicon anymore.
416 void DecrementAndCleanFaviconForURL(const std::string& page_url); 420 void DecrementAndCleanFaviconForURL(const std::string& page_url);
417 421
418 // Helper method to build sync's tab specifics from a newly modified 422 // Helper method to update the given session tab from the given
419 // tab, window, and the locally stored previous tab data. After completing, 423 // delegate (preserving old timestamps as necessary).
420 // |prev_tab| will be updated to reflect the current data, |sync_tab| will 424 //
421 // be filled with the tab data (preserving old timestamps as necessary), and 425 // TODO(akalin): Remove |default_navigation_timestamp| once we have
422 // |new_url| will be the tab's current url. 426 // a timestamp in NavigationEntry.
423 void AssociateTabContents(const SyncedWindowDelegate& window, 427 static void UpdateSessionTabFromDelegate(
424 const SyncedTabDelegate& new_tab, 428 const SyncedTabDelegate& tab_delegate,
425 SessionTab* prev_tab, 429 base::Time mtime,
426 sync_pb::SessionTab* sync_tab, 430 base::Time default_navigation_timestamp,
427 GURL* new_url); 431 SessionTab* session_tab);
428 432
429 // Load the favicon for the tab specified by |tab_link|. Will cancel any 433 // Load the favicon for the tab specified by |tab_link|. Will cancel any
430 // outstanding request for this tab. OnFaviconDataAvailable(..) will be called 434 // outstanding request for this tab. OnFaviconDataAvailable(..) will be called
431 // when the load completes. 435 // when the load completes.
432 void LoadFaviconForTab(TabLink* tab_link); 436 void LoadFaviconForTab(TabLink* tab_link);
433 437
434 // Callback method to store a tab's favicon into its sync node once it becomes 438 // Callback method to store a tab's favicon into its sync node once it becomes
435 // available. Does nothing if no favicon data was available. 439 // available. Does nothing if no favicon data was available.
436 void OnFaviconDataAvailable( 440 void OnFaviconDataAvailable(
437 FaviconService::Handle handle, 441 FaviconService::Handle handle,
438 const history::FaviconBitmapResult& bitmap_result); 442 const history::FaviconBitmapResult& bitmap_result);
439 443
440 // Used to populate a session header from the session specifics header 444 // Used to populate a session header from the session specifics header
441 // provided. 445 // provided.
442 static void PopulateSessionHeaderFromSpecifics( 446 static void PopulateSessionHeaderFromSpecifics(
443 const sync_pb::SessionHeader& header_specifics, 447 const sync_pb::SessionHeader& header_specifics,
444 const base::Time& mtime, 448 base::Time mtime,
445 SyncedSession* session_header); 449 SyncedSession* session_header);
446 450
447 // Used to populate a session window from the session specifics window 451 // Used to populate a session window from the session specifics window
448 // provided. Tracks any foreign session data created through |tracker|. 452 // provided. Tracks any foreign session data created through |tracker|.
449 static void PopulateSessionWindowFromSpecifics( 453 static void PopulateSessionWindowFromSpecifics(
450 const std::string& foreign_session_tag, 454 const std::string& foreign_session_tag,
451 const sync_pb::SessionWindow& window, 455 const sync_pb::SessionWindow& window,
452 const base::Time& mtime, 456 base::Time mtime,
453 SessionWindow* session_window, 457 SessionWindow* session_window,
454 SyncedSessionTracker* tracker); 458 SyncedSessionTracker* tracker);
455 459
456 // Used to populate a session tab from the session specifics tab provided.
457 static void PopulateSessionTabFromSpecifics(const sync_pb::SessionTab& tab,
458 const base::Time& mtime,
459 SessionTab* session_tab);
460
461 // Helper method to load the favicon data from the tab specifics. If the 460 // Helper method to load the favicon data from the tab specifics. If the
462 // favicon is valid, stores the favicon data and increments the usage counter 461 // favicon is valid, stores the favicon data and increments the usage counter
463 // in |synced_favicons_| and updates |synced_favicon_pages_| appropriately. 462 // in |synced_favicons_| and updates |synced_favicon_pages_| appropriately.
464 void LoadForeignTabFavicon(const sync_pb::SessionTab& tab); 463 void LoadForeignTabFavicon(const sync_pb::SessionTab& tab);
465 464
466 // Returns true if this tab belongs to this profile and belongs to a window, 465 // Returns true if this tab belongs to this profile and belongs to a window,
467 // false otherwise. 466 // false otherwise.
468 bool IsValidTab(const SyncedTabDelegate& tab) const; 467 bool IsValidTab(const SyncedTabDelegate& tab) const;
469 468
470 // Having a valid entry is defined as the url being valid and and having a 469 // Having a valid entry is defined as the url being valid and and having a
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 std::map<std::string, linked_ptr<SyncedFaviconInfo> > synced_favicons_; 548 std::map<std::string, linked_ptr<SyncedFaviconInfo> > synced_favicons_;
550 // Map of page URL -> favicon url. 549 // Map of page URL -> favicon url.
551 std::map<std::string, std::string> synced_favicon_pages_; 550 std::map<std::string, std::string> synced_favicon_pages_;
552 551
553 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator); 552 DISALLOW_COPY_AND_ASSIGN(SessionModelAssociator);
554 }; 553 };
555 554
556 } // namespace browser_sync 555 } // namespace browser_sync
557 556
558 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_ 557 #endif // CHROME_BROWSER_SYNC_GLUE_SESSION_MODEL_ASSOCIATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698