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/bookmark_data_type_controller.h" | 5 #include "chrome/browser/sync/glue/bookmark_data_type_controller.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/history/history_service.h" | 10 #include "chrome/browser/history/history_service.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 profile, | 33 profile, |
34 sync_service), | 34 sync_service), |
35 bookmark_model_(NULL), | 35 bookmark_model_(NULL), |
36 installed_bookmark_observer_(false) { | 36 installed_bookmark_observer_(false) { |
37 } | 37 } |
38 | 38 |
39 syncer::ModelType BookmarkDataTypeController::type() const { | 39 syncer::ModelType BookmarkDataTypeController::type() const { |
40 return syncer::BOOKMARKS; | 40 return syncer::BOOKMARKS; |
41 } | 41 } |
42 | 42 |
43 void BookmarkDataTypeController::Observe( | |
44 int type, | |
45 const content::NotificationSource& source, | |
46 const content::NotificationDetails& details) { | |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
48 DCHECK_EQ(state_, MODEL_STARTING); | |
49 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_LOADED, type); | |
50 | |
51 if (!DependentsLoaded()) | |
52 return; | |
53 | |
54 bookmark_model_->RemoveObserver(this); | |
55 installed_bookmark_observer_ = false; | |
56 | |
57 registrar_.RemoveAll(); | |
58 OnModelLoaded(); | |
59 } | |
60 | |
61 BookmarkDataTypeController::~BookmarkDataTypeController() { | 43 BookmarkDataTypeController::~BookmarkDataTypeController() { |
62 if (installed_bookmark_observer_ && bookmark_model_) { | 44 if (installed_bookmark_observer_ && bookmark_model_) { |
63 DCHECK(profile_); | 45 DCHECK(profile_); |
64 bookmark_model_->RemoveObserver(this); | 46 bookmark_model_->RemoveObserver(this); |
65 } | 47 } |
66 } | 48 } |
67 | 49 |
68 bool BookmarkDataTypeController::StartModels() { | 50 bool BookmarkDataTypeController::StartModels() { |
69 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); | 51 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); |
70 if (!DependentsLoaded()) { | 52 if (!DependentsLoaded()) { |
71 bookmark_model_->AddObserver(this); | 53 bookmark_model_->AddObserver(this); |
72 installed_bookmark_observer_ = true; | 54 installed_bookmark_observer_ = true; |
73 | 55 HistoryService* history = HistoryServiceFactory::GetForProfile( |
74 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED, | 56 profile_, Profile::EXPLICIT_ACCESS); |
75 content::Source<Profile>(sync_service_->profile())); | 57 history->AddHistoryServiceObserver(this); |
sdefresne
2014/09/23 08:45:09
You never call "history->RemoveHistoryServiceObser
sdefresne
2014/10/20 13:15:42
Use ScopedObserver<>.
nshaik
2014/10/29 08:43:39
I used ScopedObserver and I m running into an issu
nshaik
2014/10/29 08:43:39
Done.
| |
76 return false; | 58 return false; |
77 } | 59 } |
78 return true; | 60 return true; |
79 } | 61 } |
80 | 62 |
81 // Cleanup for our extra registrar usage. | 63 // Cleanup for our extra registrar usage. |
82 void BookmarkDataTypeController::CleanUpState() { | 64 void BookmarkDataTypeController::CleanUpState() { |
83 registrar_.RemoveAll(); | |
84 if (bookmark_model_ && installed_bookmark_observer_) { | 65 if (bookmark_model_ && installed_bookmark_observer_) { |
85 bookmark_model_->RemoveObserver(this); | 66 bookmark_model_->RemoveObserver(this); |
86 installed_bookmark_observer_ = false; | 67 installed_bookmark_observer_ = false; |
87 } | 68 } |
88 } | 69 } |
89 | 70 |
90 void BookmarkDataTypeController::CreateSyncComponents() { | 71 void BookmarkDataTypeController::CreateSyncComponents() { |
91 ProfileSyncComponentsFactory::SyncComponents sync_components = | 72 ProfileSyncComponentsFactory::SyncComponents sync_components = |
92 profile_sync_factory_->CreateBookmarkSyncComponents(sync_service_, | 73 profile_sync_factory_->CreateBookmarkSyncComponents(sync_service_, |
93 this); | 74 this); |
94 set_model_associator(sync_components.model_associator); | 75 set_model_associator(sync_components.model_associator); |
95 set_change_processor(sync_components.change_processor); | 76 set_change_processor(sync_components.change_processor); |
96 } | 77 } |
97 | 78 |
98 void BookmarkDataTypeController::BookmarkModelChanged() { | 79 void BookmarkDataTypeController::BookmarkModelChanged() { |
99 } | 80 } |
100 | 81 |
101 void BookmarkDataTypeController::BookmarkModelLoaded(BookmarkModel* model, | 82 void BookmarkDataTypeController::BookmarkModelLoaded(BookmarkModel* model, |
102 bool ids_reassigned) { | 83 bool ids_reassigned) { |
103 DCHECK(model->loaded()); | 84 DCHECK(model->loaded()); |
104 model->RemoveObserver(this); | 85 model->RemoveObserver(this); |
105 installed_bookmark_observer_ = false; | 86 installed_bookmark_observer_ = false; |
106 | 87 |
107 if (!DependentsLoaded()) | 88 if (!DependentsLoaded()) |
108 return; | 89 return; |
109 | 90 |
110 registrar_.RemoveAll(); | |
111 OnModelLoaded(); | 91 OnModelLoaded(); |
112 } | 92 } |
113 | 93 |
114 void BookmarkDataTypeController::BookmarkModelBeingDeleted( | 94 void BookmarkDataTypeController::BookmarkModelBeingDeleted( |
115 BookmarkModel* model) { | 95 BookmarkModel* model) { |
116 installed_bookmark_observer_ = false; | 96 installed_bookmark_observer_ = false; |
117 } | 97 } |
118 | 98 |
119 // Check that both the bookmark model and the history service (for favicons) | 99 // Check that both the bookmark model and the history service (for favicons) |
120 // are loaded. | 100 // are loaded. |
121 bool BookmarkDataTypeController::DependentsLoaded() { | 101 bool BookmarkDataTypeController::DependentsLoaded() { |
122 if (!bookmark_model_ || !bookmark_model_->loaded()) | 102 if (!bookmark_model_ || !bookmark_model_->loaded()) |
123 return false; | 103 return false; |
124 | 104 |
125 HistoryService* history = HistoryServiceFactory::GetForProfile( | 105 HistoryService* history = HistoryServiceFactory::GetForProfile( |
126 profile_, Profile::EXPLICIT_ACCESS); | 106 profile_, Profile::EXPLICIT_ACCESS); |
127 if (!history || !history->BackendLoaded()) | 107 if (!history || !history->BackendLoaded()) |
128 return false; | 108 return false; |
129 | 109 |
130 // All necessary services are loaded. | 110 // All necessary services are loaded. |
131 return true; | 111 return true; |
132 } | 112 } |
133 | 113 |
114 void BookmarkDataTypeController::HistoryServiceLoaded(HistoryService* service) { | |
115 if (!DependentsLoaded()) | |
sdefresne
2014/09/23 08:45:09
You removed the following assertion, maybe you sho
nshaik
2014/10/29 08:43:39
Done.
| |
116 return; | |
117 | |
118 bookmark_model_->RemoveObserver(this); | |
119 installed_bookmark_observer_ = false; | |
120 | |
121 OnModelLoaded(); | |
122 } | |
123 | |
134 } // namespace browser_sync | 124 } // namespace browser_sync |
OLD | NEW |