OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/sync_sessions/session_data_type_controller.h" | 5 #include "components/sync_sessions/session_data_type_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "components/prefs/pref_service.h" | 9 #include "components/prefs/pref_service.h" |
10 #include "components/sync/driver/sync_client.h" | 10 #include "components/sync/driver/sync_client.h" |
11 #include "components/sync_sessions/sync_sessions_client.h" | 11 #include "components/sync_sessions/sync_sessions_client.h" |
12 #include "components/sync_sessions/synced_window_delegate.h" | 12 #include "components/sync_sessions/synced_window_delegate.h" |
13 #include "components/sync_sessions/synced_window_delegates_getter.h" | 13 #include "components/sync_sessions/synced_window_delegates_getter.h" |
14 | 14 |
15 namespace browser_sync { | 15 namespace sync_sessions { |
16 | 16 |
17 SessionDataTypeController::SessionDataTypeController( | 17 SessionDataTypeController::SessionDataTypeController( |
18 const base::Closure& dump_stack, | 18 const base::Closure& dump_stack, |
19 sync_driver::SyncClient* sync_client, | 19 sync_driver::SyncClient* sync_client, |
20 sync_driver::LocalDeviceInfoProvider* local_device, | 20 sync_driver::LocalDeviceInfoProvider* local_device, |
21 const char* history_disabled_pref_name) | 21 const char* history_disabled_pref_name) |
22 : UIDataTypeController(syncer::SESSIONS, dump_stack, sync_client), | 22 : UIDataTypeController(syncer::SESSIONS, dump_stack, sync_client), |
23 sync_client_(sync_client), | 23 sync_client_(sync_client), |
24 local_device_(local_device), | 24 local_device_(local_device), |
25 history_disabled_pref_name_(history_disabled_pref_name), | 25 history_disabled_pref_name_(history_disabled_pref_name), |
26 waiting_on_session_restore_(false), | 26 waiting_on_session_restore_(false), |
27 waiting_on_local_device_info_(false) { | 27 waiting_on_local_device_info_(false) { |
28 DCHECK(local_device_); | 28 DCHECK(local_device_); |
29 pref_registrar_.Init(sync_client_->GetPrefService()); | 29 pref_registrar_.Init(sync_client_->GetPrefService()); |
30 pref_registrar_.Add( | 30 pref_registrar_.Add( |
31 history_disabled_pref_name_, | 31 history_disabled_pref_name_, |
32 base::Bind(&SessionDataTypeController::OnSavingBrowserHistoryPrefChanged, | 32 base::Bind(&SessionDataTypeController::OnSavingBrowserHistoryPrefChanged, |
33 base::AsWeakPtr(this))); | 33 base::AsWeakPtr(this))); |
34 } | 34 } |
35 | 35 |
36 SessionDataTypeController::~SessionDataTypeController() {} | 36 SessionDataTypeController::~SessionDataTypeController() {} |
37 | 37 |
38 bool SessionDataTypeController::StartModels() { | 38 bool SessionDataTypeController::StartModels() { |
39 DCHECK(CalledOnValidThread()); | 39 DCHECK(CalledOnValidThread()); |
40 browser_sync::SyncedWindowDelegatesGetter* synced_window_getter = | 40 SyncedWindowDelegatesGetter* synced_window_getter = |
41 sync_client_->GetSyncSessionsClient()->GetSyncedWindowDelegatesGetter(); | 41 sync_client_->GetSyncSessionsClient()->GetSyncedWindowDelegatesGetter(); |
42 std::set<const browser_sync::SyncedWindowDelegate*> window = | 42 std::set<const SyncedWindowDelegate*> window = |
43 synced_window_getter->GetSyncedWindowDelegates(); | 43 synced_window_getter->GetSyncedWindowDelegates(); |
44 for (std::set<const browser_sync::SyncedWindowDelegate*>::const_iterator i = | 44 for (std::set<const SyncedWindowDelegate*>::const_iterator i = window.begin(); |
45 window.begin(); | |
46 i != window.end(); ++i) { | 45 i != window.end(); ++i) { |
47 if ((*i)->IsSessionRestoreInProgress()) { | 46 if ((*i)->IsSessionRestoreInProgress()) { |
48 waiting_on_session_restore_ = true; | 47 waiting_on_session_restore_ = true; |
49 break; | 48 break; |
50 } | 49 } |
51 } | 50 } |
52 | 51 |
53 if (!local_device_->GetLocalDeviceInfo()) { | 52 if (!local_device_->GetLocalDeviceInfo()) { |
54 subscription_ = local_device_->RegisterOnInitializedCallback( | 53 subscription_ = local_device_->RegisterOnInitializedCallback( |
55 base::Bind(&SessionDataTypeController::OnLocalDeviceInfoInitialized, | 54 base::Bind(&SessionDataTypeController::OnLocalDeviceInfoInitialized, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (state() != NOT_RUNNING && state() != STOPPING) { | 103 if (state() != NOT_RUNNING && state() != STOPPING) { |
105 syncer::SyncError error( | 104 syncer::SyncError error( |
106 FROM_HERE, syncer::SyncError::DATATYPE_POLICY_ERROR, | 105 FROM_HERE, syncer::SyncError::DATATYPE_POLICY_ERROR, |
107 "History and tab saving is now disabled by policy.", | 106 "History and tab saving is now disabled by policy.", |
108 syncer::SESSIONS); | 107 syncer::SESSIONS); |
109 CreateErrorHandler()->OnUnrecoverableError(error); | 108 CreateErrorHandler()->OnUnrecoverableError(error); |
110 } | 109 } |
111 } | 110 } |
112 } | 111 } |
113 | 112 |
114 } // namespace browser_sync | 113 } // namespace sync_sessions |
OLD | NEW |