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

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

Issue 7453014: [Sync] Refactor sync datatype error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and fix final unit test <3 c++ Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/sync/glue/session_model_associator.h" 5 #include "chrome/browser/sync/glue/session_model_associator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/tracked.h" 12 #include "base/tracked.h"
13 #include "chrome/browser/extensions/extension_tab_helper.h" 13 #include "chrome/browser/extensions/extension_tab_helper.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sessions/restore_tab_helper.h" 15 #include "chrome/browser/sessions/restore_tab_helper.h"
16 #include "chrome/browser/sessions/session_service_factory.h" 16 #include "chrome/browser/sessions/session_service_factory.h"
17 #include "chrome/browser/sync/api/sync_error.h"
17 #include "chrome/browser/sync/glue/synced_window_delegate.h" 18 #include "chrome/browser/sync/glue/synced_window_delegate.h"
18 #include "chrome/browser/sync/profile_sync_service.h" 19 #include "chrome/browser/sync/profile_sync_service.h"
19 #include "chrome/browser/sync/syncable/syncable.h" 20 #include "chrome/browser/sync/syncable/syncable.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/extensions/extension.h" 23 #include "chrome/common/extensions/extension.h"
23 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
24 #include "content/browser/tab_contents/navigation_controller.h" 25 #include "content/browser/tab_contents/navigation_controller.h"
25 #include "content/browser/tab_contents/navigation_entry.h" 26 #include "content/browser/tab_contents/navigation_entry.h"
26 #include "content/common/notification_details.h" 27 #include "content/common/notification_details.h"
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 sync_pb::TabNavigation_PageTransition_TYPED); 401 sync_pb::TabNavigation_PageTransition_TYPED);
401 } 402 }
402 } 403 }
403 404
404 void SessionModelAssociator::Disassociate(int64 sync_id) { 405 void SessionModelAssociator::Disassociate(int64 sync_id) {
405 DCHECK(CalledOnValidThread()); 406 DCHECK(CalledOnValidThread());
406 NOTIMPLEMENTED(); 407 NOTIMPLEMENTED();
407 // TODO(zea): we will need this once we support deleting foreign sessions. 408 // TODO(zea): we will need this once we support deleting foreign sessions.
408 } 409 }
409 410
410 bool SessionModelAssociator::AssociateModels() { 411 bool SessionModelAssociator::AssociateModels(SyncError* error) {
411 DCHECK(CalledOnValidThread()); 412 DCHECK(CalledOnValidThread());
412 413
413 // Ensure that we disassociated properly, otherwise memory might leak. 414 // Ensure that we disassociated properly, otherwise memory might leak.
414 DCHECK(synced_session_tracker_.empty()); 415 DCHECK(synced_session_tracker_.empty());
415 DCHECK_EQ(0U, tab_pool_.capacity()); 416 DCHECK_EQ(0U, tab_pool_.capacity());
416 417
417 local_session_syncid_ = sync_api::kInvalidId; 418 local_session_syncid_ = sync_api::kInvalidId;
418 419
419 // Read any available foreign sessions and load any session data we may have. 420 // Read any available foreign sessions and load any session data we may have.
420 // If we don't have any local session data in the db, create a header node. 421 // If we don't have any local session data in the db, create a header node.
421 { 422 {
422 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 423 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
423 424
424 sync_api::ReadNode root(&trans); 425 sync_api::ReadNode root(&trans);
425 if (!root.InitByTagLookup(kSessionsTag)) { 426 if (!root.InitByTagLookup(kSessionsTag)) {
426 LOG(ERROR) << kNoSessionsFolderError; 427 error->Reset(FROM_HERE, kNoSessionsFolderError, model_type());
427 return false; 428 return false;
428 } 429 }
429 430
430 // Make sure we have a machine tag. 431 // Make sure we have a machine tag.
431 if (current_machine_tag_.empty()) 432 if (current_machine_tag_.empty())
432 InitializeCurrentMachineTag(&trans); 433 InitializeCurrentMachineTag(&trans);
433 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_); 434 synced_session_tracker_.SetLocalSessionTag(current_machine_tag_);
434 UpdateAssociationsFromSyncModel(root, &trans); 435 UpdateAssociationsFromSyncModel(root, &trans);
435 436
436 if (local_session_syncid_ == sync_api::kInvalidId) { 437 if (local_session_syncid_ == sync_api::kInvalidId) {
437 // The sync db didn't have a header node for us, we need to create one. 438 // The sync db didn't have a header node for us, we need to create one.
438 sync_api::WriteNode write_node(&trans); 439 sync_api::WriteNode write_node(&trans);
439 if (!write_node.InitUniqueByCreation(syncable::SESSIONS, root, 440 if (!write_node.InitUniqueByCreation(syncable::SESSIONS, root,
440 current_machine_tag_)) { 441 current_machine_tag_)) {
441 LOG(ERROR) << "Failed to create sessions header sync node."; 442 error->Reset(FROM_HERE,
443 "Failed to create sessions header sync node.",
444 model_type());
442 return false; 445 return false;
443 } 446 }
444 write_node.SetTitle(UTF8ToWide(current_machine_tag_)); 447 write_node.SetTitle(UTF8ToWide(current_machine_tag_));
445 local_session_syncid_ = write_node.GetId(); 448 local_session_syncid_ = write_node.GetId();
446 } 449 }
447 } 450 }
448 451
449 // Check if anything has changed on the client side. 452 // Check if anything has changed on the client side.
450 UpdateSyncModelDataFromClient(); 453 UpdateSyncModelDataFromClient();
451 454
452 VLOG(1) << "Session models associated."; 455 VLOG(1) << "Session models associated.";
453 456
454 return true; 457 return true;
455 } 458 }
456 459
457 bool SessionModelAssociator::DisassociateModels() { 460 bool SessionModelAssociator::DisassociateModels(SyncError* error) {
458 DCHECK(CalledOnValidThread()); 461 DCHECK(CalledOnValidThread());
459 synced_session_tracker_.clear(); 462 synced_session_tracker_.clear();
460 tab_map_.clear(); 463 tab_map_.clear();
461 tab_pool_.clear(); 464 tab_pool_.clear();
462 local_session_syncid_ = sync_api::kInvalidId; 465 local_session_syncid_ = sync_api::kInvalidId;
463 466
464 // There is no local model stored with which to disassociate, just notify 467 // There is no local model stored with which to disassociate, just notify
465 // foreign session handlers. 468 // foreign session handlers.
466 NotificationService::current()->Notify( 469 NotificationService::current()->Notify(
467 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED, 470 chrome::NOTIFICATION_FOREIGN_SESSION_DISABLED,
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 bool SessionModelAssociator::CryptoReadyIfNecessary() { 1057 bool SessionModelAssociator::CryptoReadyIfNecessary() {
1055 // We only access the cryptographer while holding a transaction. 1058 // We only access the cryptographer while holding a transaction.
1056 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 1059 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
1057 syncable::ModelTypeSet encrypted_types; 1060 syncable::ModelTypeSet encrypted_types;
1058 encrypted_types = sync_api::GetEncryptedTypes(&trans); 1061 encrypted_types = sync_api::GetEncryptedTypes(&trans);
1059 return encrypted_types.count(syncable::SESSIONS) == 0 || 1062 return encrypted_types.count(syncable::SESSIONS) == 0 ||
1060 sync_service_->IsCryptographerReady(&trans); 1063 sync_service_->IsCryptographerReady(&trans);
1061 } 1064 }
1062 1065
1063 } // namespace browser_sync 1066 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_model_associator.h ('k') | chrome/browser/sync/glue/syncable_service_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698