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 #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/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" |
14 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
18 #include "chrome/browser/sessions/session_service_factory.h" | 19 #include "chrome/browser/sessions/session_service_factory.h" |
19 #include "chrome/browser/sync/api/sync_error.h" | 20 #include "chrome/browser/sync/api/sync_error.h" |
20 #include "chrome/browser/sync/glue/synced_session.h" | 21 #include "chrome/browser/sync/glue/synced_session.h" |
21 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 22 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
22 #include "chrome/browser/sync/glue/synced_window_delegate.h" | 23 #include "chrome/browser/sync/glue/synced_window_delegate.h" |
23 #include "chrome/browser/sync/internal_api/read_node.h" | 24 #include "chrome/browser/sync/internal_api/read_node.h" |
24 #include "chrome/browser/sync/internal_api/read_transaction.h" | 25 #include "chrome/browser/sync/internal_api/read_transaction.h" |
25 #include "chrome/browser/sync/internal_api/write_node.h" | 26 #include "chrome/browser/sync/internal_api/write_node.h" |
26 #include "chrome/browser/sync/internal_api/write_transaction.h" | 27 #include "chrome/browser/sync/internal_api/write_transaction.h" |
27 #include "chrome/browser/sync/profile_sync_service.h" | 28 #include "chrome/browser/sync/profile_sync_service.h" |
28 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 29 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
29 #include "chrome/browser/sync/syncable/syncable.h" | 30 #include "chrome/browser/sync/syncable/syncable.h" |
30 #include "chrome/browser/sync/util/get_session_name_task.h" | 31 #include "chrome/browser/sync/util/get_session_name.h" |
31 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
33 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
35 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
36 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
37 #include "base/linux_util.h" | 38 #include "base/linux_util.h" |
38 #elif defined(OS_WIN) | 39 #elif defined(OS_WIN) |
39 #include <windows.h> | 40 #include <windows.h> |
40 #endif | 41 #endif |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 // Only use the default machine name if it hasn't already been set. | 570 // Only use the default machine name if it hasn't already been set. |
570 if (current_session_name_.empty()) | 571 if (current_session_name_.empty()) |
571 current_session_name_ = name; | 572 current_session_name_ = name; |
572 } | 573 } |
573 | 574 |
574 void SessionModelAssociator::InitializeCurrentSessionName() { | 575 void SessionModelAssociator::InitializeCurrentSessionName() { |
575 DCHECK(CalledOnValidThread()); | 576 DCHECK(CalledOnValidThread()); |
576 if (setup_for_test_) { | 577 if (setup_for_test_) { |
577 OnSessionNameInitialized("TestSessionName"); | 578 OnSessionNameInitialized("TestSessionName"); |
578 } else { | 579 } else { |
579 scoped_refptr<GetSessionNameTask> task = new GetSessionNameTask( | 580 browser_sync::GetSessionName( |
| 581 BrowserThread::GetBlockingPool(), |
580 base::Bind(&SessionModelAssociator::OnSessionNameInitialized, | 582 base::Bind(&SessionModelAssociator::OnSessionNameInitialized, |
581 AsWeakPtr())); | 583 AsWeakPtr())); |
582 BrowserThread::PostTask( | |
583 BrowserThread::FILE, | |
584 FROM_HERE, | |
585 base::Bind(&GetSessionNameTask::GetSessionNameAsync, task.get())); | |
586 } | 584 } |
587 } | 585 } |
588 | 586 |
589 bool SessionModelAssociator::UpdateAssociationsFromSyncModel( | 587 bool SessionModelAssociator::UpdateAssociationsFromSyncModel( |
590 const sync_api::ReadNode& root, | 588 const sync_api::ReadNode& root, |
591 const sync_api::BaseTransaction* trans) { | 589 const sync_api::BaseTransaction* trans) { |
592 DCHECK(CalledOnValidThread()); | 590 DCHECK(CalledOnValidThread()); |
593 DCHECK(tab_pool_.empty()); | 591 DCHECK(tab_pool_.empty()); |
594 | 592 |
595 // Iterate through the nodes and associate any foreign sessions. | 593 // Iterate through the nodes and associate any foreign sessions. |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 bool SessionModelAssociator::CryptoReadyIfNecessary() { | 1134 bool SessionModelAssociator::CryptoReadyIfNecessary() { |
1137 // We only access the cryptographer while holding a transaction. | 1135 // We only access the cryptographer while holding a transaction. |
1138 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 1136 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
1139 const syncable::ModelTypeSet encrypted_types = | 1137 const syncable::ModelTypeSet encrypted_types = |
1140 sync_api::GetEncryptedTypes(&trans); | 1138 sync_api::GetEncryptedTypes(&trans); |
1141 return !encrypted_types.Has(SESSIONS) || | 1139 return !encrypted_types.Has(SESSIONS) || |
1142 sync_service_->IsCryptographerReady(&trans); | 1140 sync_service_->IsCryptographerReady(&trans); |
1143 } | 1141 } |
1144 | 1142 |
1145 } // namespace browser_sync | 1143 } // namespace browser_sync |
OLD | NEW |