OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/profiles/profile_statistics.h" | 5 #include "chrome/browser/profiles/profile_statistics.h" |
6 | 6 |
| 7 #include <set> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
11 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
16 #include "chrome/browser/password_manager/password_store_factory.h" | 18 #include "chrome/browser/password_manager/password_store_factory.h" |
17 #include "chrome/browser/profiles/profile_attributes_entry.h" | 19 #include "chrome/browser/profiles/profile_attributes_entry.h" |
18 #include "chrome/browser/profiles/profile_attributes_storage.h" | 20 #include "chrome/browser/profiles/profile_attributes_storage.h" |
19 #include "chrome/browser/profiles/profile_info_cache.h" | 21 #include "chrome/browser/profiles/profile_info_cache.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "components/bookmarks/browser/bookmark_model.h" | 23 #include "components/bookmarks/browser/bookmark_model.h" |
| 24 #include "components/bookmarks/browser/bookmark_model_observer.h" |
22 #include "components/history/core/browser/history_service.h" | 25 #include "components/history/core/browser/history_service.h" |
23 #include "components/password_manager/core/browser/password_store.h" | 26 #include "components/password_manager/core/browser/password_store.h" |
24 #include "components/password_manager/core/browser/password_store_consumer.h" | 27 #include "components/password_manager/core/browser/password_store_consumer.h" |
25 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
26 | 29 |
27 using content::BrowserThread; | |
28 | |
29 namespace { | 30 namespace { |
30 | 31 |
31 struct ProfileStatValue { | 32 struct ProfileStatValue { |
32 int count; | 33 int count; |
33 bool success; // false means the statistics failed to load | 34 bool success; // false means the statistics failed to load |
34 }; | 35 }; |
35 | 36 |
36 int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) { | 37 int CountBookmarksFromNode(const bookmarks::BookmarkNode* node) { |
37 int count = 0; | 38 int count = 0; |
38 if (node->is_url()) { | 39 if (node->is_url()) { |
39 ++count; | 40 ++count; |
40 } else { | 41 } else { |
41 for (int i = 0; i < node->child_count(); ++i) | 42 for (int i = 0; i < node->child_count(); ++i) |
42 count += CountBookmarksFromNode(node->GetChild(i)); | 43 count += CountBookmarksFromNode(node->GetChild(i)); |
43 } | 44 } |
44 return count; | 45 return count; |
45 } | 46 } |
46 | 47 |
47 class ProfileStatisticsAggregator | 48 class ProfileStatisticsAggregator |
48 : public base::RefCountedThreadSafe<ProfileStatisticsAggregator> { | 49 : public base::RefCountedThreadSafe<ProfileStatisticsAggregator> { |
49 // This class collects statistical information about the profile and returns | 50 // This class is used internally by GetProfileStatistics and |
| 51 // StoreProfileStatisticsToCache. |
| 52 // |
| 53 // The class collects statistical information about the profile and returns |
50 // the information via a callback function. Currently bookmarks, history, | 54 // the information via a callback function. Currently bookmarks, history, |
51 // logins and preferences are counted. | 55 // logins and preferences are counted. |
52 // | 56 // |
53 // The class is RefCounted because this is needed for CancelableTaskTracker | 57 // The class is RefCounted because this is needed for CancelableTaskTracker |
54 // to function properly. Once all tasks are run (or cancelled) the instance is | 58 // to function properly. Once all tasks are run (or cancelled) the instance is |
55 // automatically destructed. | 59 // automatically destructed. |
56 // | |
57 // The class is used internally by GetProfileStatistics function. | |
58 | 60 |
59 public: | 61 public: |
60 explicit ProfileStatisticsAggregator(Profile* profile, | 62 ProfileStatisticsAggregator(Profile* profile, |
61 const profiles::ProfileStatisticsCallback& callback, | 63 const profiles::ProfileStatisticsCallback& callback, |
62 base::CancelableTaskTracker* tracker); | 64 base::CancelableTaskTracker* tracker); |
63 | 65 |
64 private: | 66 private: |
65 friend class base::RefCountedThreadSafe<ProfileStatisticsAggregator>; | 67 friend class base::RefCountedThreadSafe<ProfileStatisticsAggregator>; |
66 ~ProfileStatisticsAggregator() {} | 68 ~ProfileStatisticsAggregator() {} |
67 | 69 |
68 void Init(); | 70 void Init(); |
69 | 71 |
70 // Callback functions | 72 // Callback functions |
71 // Normal callback. Appends result to |profile_category_stats_|, and then call | 73 // Normal callback. Appends result to |profile_category_stats_|, and then call |
72 // the external callback. All other callbacks call this function. | 74 // the external callback. All other callbacks call this function. |
73 void StatisticsCallback(const char* category, ProfileStatValue result); | 75 void StatisticsCallback(const char* category, ProfileStatValue result); |
74 // Callback for reporting success. | 76 // Callback for reporting success. |
75 void StatisticsCallbackSuccess(const char* category, int count); | 77 void StatisticsCallbackSuccess(const char* category, int count); |
76 // Callback for reporting failure. | 78 // Callback for reporting failure. |
77 void StatisticsCallbackFailure(const char* category); | 79 void StatisticsCallbackFailure(const char* category); |
78 // Callback for history. | 80 // Callback for history. |
79 void StatisticsCallbackHistory(history::HistoryCountResult result); | 81 void StatisticsCallbackHistory(history::HistoryCountResult result); |
80 | 82 |
81 // Bookmark counting. | 83 // Bookmark counting. |
82 ProfileStatValue CountBookmarks() const; | 84 void WaitOrCountBookmarks(); |
| 85 void CountBookmarks(bookmarks::BookmarkModel* bookmark_model); |
83 | 86 |
84 // Preference counting. | 87 class BookmarkModelHelper |
85 ProfileStatValue CountPrefs() const; | 88 : public bookmarks::BookmarkModelObserver { |
| 89 public: |
| 90 explicit BookmarkModelHelper(ProfileStatisticsAggregator* parent) |
| 91 : parent_(parent) {} |
86 | 92 |
87 Profile* profile_; | 93 void BookmarkModelLoaded(bookmarks::BookmarkModel* model, |
88 profiles::ProfileCategoryStats profile_category_stats_; | 94 bool ids_reassigned) |
| 95 override { |
| 96 // Remove observer before release, otherwise it may become a dangling |
| 97 // reference. |
| 98 model->RemoveObserver(this); |
| 99 parent_->CountBookmarks(model); |
| 100 parent_->Release(); |
| 101 } |
89 | 102 |
90 // Callback function to be called when results arrive. Will be called | 103 void BookmarkNodeMoved(bookmarks::BookmarkModel* model, |
91 // multiple times (once for each statistics). | 104 const bookmarks::BookmarkNode* old_parent, |
92 const profiles::ProfileStatisticsCallback callback_; | 105 int old_index, |
| 106 const bookmarks::BookmarkNode* new_parent, |
| 107 int new_index) override {} |
93 | 108 |
94 base::CancelableTaskTracker* tracker_; | 109 void BookmarkNodeAdded(bookmarks::BookmarkModel* model, |
| 110 const bookmarks::BookmarkNode* parent, |
| 111 int index) override {} |
95 | 112 |
96 // Password counting. | 113 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model, |
| 114 const bookmarks::BookmarkNode* parent, |
| 115 int old_index, const bookmarks::BookmarkNode* node, |
| 116 const std::set<GURL>& no_longer_bookmarked) override {} |
| 117 |
| 118 void BookmarkNodeChanged(bookmarks::BookmarkModel* model, |
| 119 const bookmarks::BookmarkNode* node) override {} |
| 120 |
| 121 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, |
| 122 const bookmarks::BookmarkNode* node) override {} |
| 123 |
| 124 void BookmarkNodeChildrenReordered(bookmarks::BookmarkModel* model, |
| 125 const bookmarks::BookmarkNode* node) override {} |
| 126 |
| 127 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model, |
| 128 const std::set<GURL>& removed_urls) override {} |
| 129 |
| 130 private: |
| 131 ProfileStatisticsAggregator* parent_ = nullptr; |
| 132 }; |
| 133 |
| 134 // Password counting |
97 class PasswordStoreConsumerHelper | 135 class PasswordStoreConsumerHelper |
98 : public password_manager::PasswordStoreConsumer { | 136 : public password_manager::PasswordStoreConsumer { |
99 public: | 137 public: |
100 explicit PasswordStoreConsumerHelper(ProfileStatisticsAggregator* parent) | 138 explicit PasswordStoreConsumerHelper(ProfileStatisticsAggregator* parent) |
101 : parent_(parent) {} | 139 : parent_(parent) {} |
102 | 140 |
103 void OnGetPasswordStoreResults( | 141 void OnGetPasswordStoreResults( |
104 ScopedVector<autofill::PasswordForm> results) override { | 142 ScopedVector<autofill::PasswordForm> results) override { |
105 parent_->StatisticsCallbackSuccess(profiles::kProfileStatisticsPasswords, | 143 parent_->StatisticsCallbackSuccess(profiles::kProfileStatisticsPasswords, |
106 results.size()); | 144 results.size()); |
107 } | 145 } |
108 | 146 |
109 private: | 147 private: |
110 ProfileStatisticsAggregator* parent_ = nullptr; | 148 ProfileStatisticsAggregator* parent_ = nullptr; |
111 | 149 |
112 DISALLOW_COPY_AND_ASSIGN(PasswordStoreConsumerHelper); | 150 DISALLOW_COPY_AND_ASSIGN(PasswordStoreConsumerHelper); |
113 }; | 151 }; |
| 152 |
| 153 // Preference counting. |
| 154 ProfileStatValue CountPrefs() const; |
| 155 |
| 156 Profile* profile_; |
| 157 profiles::ProfileCategoryStats profile_category_stats_; |
| 158 |
| 159 // Callback function to be called when results arrive. Will be called |
| 160 // multiple times (once for each statistics). |
| 161 const profiles::ProfileStatisticsCallback callback_; |
| 162 |
| 163 base::CancelableTaskTracker* tracker_; |
| 164 scoped_ptr<base::CancelableTaskTracker> default_tracker_; |
| 165 |
| 166 // Bookmark counting |
| 167 scoped_ptr<BookmarkModelHelper> bookmark_model_helper_; |
| 168 |
| 169 // Password counting. |
114 PasswordStoreConsumerHelper password_store_consumer_helper_; | 170 PasswordStoreConsumerHelper password_store_consumer_helper_; |
115 | 171 |
116 DISALLOW_COPY_AND_ASSIGN(ProfileStatisticsAggregator); | 172 DISALLOW_COPY_AND_ASSIGN(ProfileStatisticsAggregator); |
117 }; | 173 }; |
118 | 174 |
119 ProfileStatisticsAggregator::ProfileStatisticsAggregator( | 175 ProfileStatisticsAggregator::ProfileStatisticsAggregator( |
120 Profile* profile, | 176 Profile* profile, |
121 const profiles::ProfileStatisticsCallback& callback, | 177 const profiles::ProfileStatisticsCallback& callback, |
122 base::CancelableTaskTracker* tracker) | 178 base::CancelableTaskTracker* tracker) |
123 : profile_(profile), | 179 : profile_(profile), |
124 callback_(callback), | 180 callback_(callback), |
125 tracker_(tracker), | 181 tracker_(tracker), |
126 password_store_consumer_helper_(this) { | 182 password_store_consumer_helper_(this) { |
| 183 if (!tracker_) { |
| 184 default_tracker_.reset(new base::CancelableTaskTracker); |
| 185 tracker_ = default_tracker_.get(); |
| 186 } |
127 Init(); | 187 Init(); |
128 } | 188 } |
129 | 189 |
130 void ProfileStatisticsAggregator::Init() { | 190 void ProfileStatisticsAggregator::Init() { |
| 191 DCHECK(profile_); |
| 192 |
131 // Initiate bookmark counting (async). Post to UI thread. | 193 // Initiate bookmark counting (async). Post to UI thread. |
132 tracker_->PostTaskAndReplyWithResult( | 194 tracker_->PostTask( |
133 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(), | 195 content::BrowserThread::GetMessageLoopProxyForThread( |
134 FROM_HERE, | 196 content::BrowserThread::UI).get(), |
135 base::Bind(&ProfileStatisticsAggregator::CountBookmarks, this), | 197 FROM_HERE, |
136 base::Bind(&ProfileStatisticsAggregator::StatisticsCallback, | 198 base::Bind(&ProfileStatisticsAggregator::WaitOrCountBookmarks, this)); |
137 this, profiles::kProfileStatisticsBookmarks)); | |
138 | 199 |
139 // Initiate history counting (async). | 200 // Initiate history counting (async). |
140 history::HistoryService* history_service = | 201 history::HistoryService* history_service = |
141 HistoryServiceFactory::GetForProfileWithoutCreating(profile_); | 202 HistoryServiceFactory::GetForProfileWithoutCreating(profile_); |
142 | 203 |
143 if (history_service) { | 204 if (history_service) { |
144 history_service->GetHistoryCount( | 205 history_service->GetHistoryCount( |
145 base::Time(), | 206 base::Time(), |
146 base::Time::Max(), | 207 base::Time::Max(), |
147 base::Bind(&ProfileStatisticsAggregator::StatisticsCallbackHistory, | 208 base::Bind(&ProfileStatisticsAggregator::StatisticsCallbackHistory, |
148 this), | 209 this), |
149 tracker_); | 210 tracker_); |
150 } else { | 211 } else { |
151 StatisticsCallbackFailure(profiles::kProfileStatisticsBrowsingHistory); | 212 StatisticsCallbackFailure(profiles::kProfileStatisticsBrowsingHistory); |
152 } | 213 } |
153 | 214 |
154 // Initiate stored password counting (async). | 215 // Initiate stored password counting (async). |
155 // TODO(anthonyvd): make password task cancellable. | 216 // TODO(anthonyvd): make password task cancellable. |
156 scoped_refptr<password_manager::PasswordStore> password_store = | 217 scoped_refptr<password_manager::PasswordStore> password_store = |
157 PasswordStoreFactory::GetForProfile( | 218 PasswordStoreFactory::GetForProfile( |
158 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 219 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
159 if (password_store) { | 220 if (password_store) { |
160 password_store->GetAutofillableLogins(&password_store_consumer_helper_); | 221 password_store->GetAutofillableLogins(&password_store_consumer_helper_); |
161 } else { | 222 } else { |
162 StatisticsCallbackFailure(profiles::kProfileStatisticsPasswords); | 223 StatisticsCallbackFailure(profiles::kProfileStatisticsPasswords); |
163 } | 224 } |
164 | 225 |
165 // Initiate preference counting (async). Post to UI thread. | 226 // Initiate preference counting (async). Post to UI thread. |
166 tracker_->PostTaskAndReplyWithResult( | 227 tracker_->PostTaskAndReplyWithResult( |
167 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(), | 228 content::BrowserThread::GetMessageLoopProxyForThread( |
168 FROM_HERE, | 229 content::BrowserThread::UI).get(), |
169 base::Bind(&ProfileStatisticsAggregator::CountPrefs, this), | 230 FROM_HERE, |
170 base::Bind(&ProfileStatisticsAggregator::StatisticsCallback, | 231 base::Bind(&ProfileStatisticsAggregator::CountPrefs, this), |
171 this, profiles::kProfileStatisticsSettings)); | 232 base::Bind(&ProfileStatisticsAggregator::StatisticsCallback, |
| 233 this, profiles::kProfileStatisticsSettings)); |
172 } | 234 } |
173 | 235 |
174 void ProfileStatisticsAggregator::StatisticsCallback( | 236 void ProfileStatisticsAggregator::StatisticsCallback( |
175 const char* category, ProfileStatValue result) { | 237 const char* category, ProfileStatValue result) { |
176 profiles::ProfileCategoryStat datum; | 238 profiles::ProfileCategoryStat datum; |
177 datum.category = category; | 239 datum.category = category; |
178 datum.count = result.count; | 240 datum.count = result.count; |
179 datum.success = result.success; | 241 datum.success = result.success; |
180 profile_category_stats_.push_back(datum); | 242 profile_category_stats_.push_back(datum); |
181 callback_.Run(profile_category_stats_); | 243 if (!callback_.is_null()) |
| 244 callback_.Run(profile_category_stats_); |
| 245 |
| 246 if (result.success) { |
| 247 profiles::SetProfileStatisticsInCache(profile_->GetPath(), datum.category, |
| 248 result.count); |
| 249 } |
182 } | 250 } |
183 | 251 |
184 void ProfileStatisticsAggregator::StatisticsCallbackSuccess( | 252 void ProfileStatisticsAggregator::StatisticsCallbackSuccess( |
185 const char* category, int count) { | 253 const char* category, int count) { |
186 ProfileStatValue result; | 254 ProfileStatValue result; |
187 result.count = count; | 255 result.count = count; |
188 result.success = true; | 256 result.success = true; |
189 StatisticsCallback(category, result); | 257 StatisticsCallback(category, result); |
190 } | 258 } |
191 | 259 |
192 void ProfileStatisticsAggregator::StatisticsCallbackFailure( | 260 void ProfileStatisticsAggregator::StatisticsCallbackFailure( |
193 const char* category) { | 261 const char* category) { |
194 ProfileStatValue result; | 262 ProfileStatValue result; |
195 result.count = 0; | 263 result.count = 0; |
196 result.success = false; | 264 result.success = false; |
197 StatisticsCallback(category, result); | 265 StatisticsCallback(category, result); |
198 } | 266 } |
199 | 267 |
200 void ProfileStatisticsAggregator::StatisticsCallbackHistory( | 268 void ProfileStatisticsAggregator::StatisticsCallbackHistory( |
201 history::HistoryCountResult result) { | 269 history::HistoryCountResult result) { |
202 ProfileStatValue result_converted; | 270 ProfileStatValue result_converted; |
203 result_converted.count = result.count; | 271 result_converted.count = result.count; |
204 result_converted.success = result.success; | 272 result_converted.success = result.success; |
205 StatisticsCallback(profiles::kProfileStatisticsBrowsingHistory, | 273 StatisticsCallback(profiles::kProfileStatisticsBrowsingHistory, |
206 result_converted); | 274 result_converted); |
207 } | 275 } |
208 | 276 |
209 ProfileStatValue ProfileStatisticsAggregator::CountBookmarks() const { | 277 void ProfileStatisticsAggregator::CountBookmarks( |
| 278 bookmarks::BookmarkModel* bookmark_model) { |
| 279 int count = CountBookmarksFromNode(bookmark_model->bookmark_bar_node()) + |
| 280 CountBookmarksFromNode(bookmark_model->other_node()) + |
| 281 CountBookmarksFromNode(bookmark_model->mobile_node()); |
| 282 |
| 283 StatisticsCallbackSuccess(profiles::kProfileStatisticsBookmarks, count); |
| 284 } |
| 285 |
| 286 void ProfileStatisticsAggregator::WaitOrCountBookmarks() { |
210 bookmarks::BookmarkModel* bookmark_model = | 287 bookmarks::BookmarkModel* bookmark_model = |
211 BookmarkModelFactory::GetForProfileIfExists(profile_); | 288 BookmarkModelFactory::GetForProfileIfExists(profile_); |
212 | 289 |
213 ProfileStatValue result; | |
214 if (bookmark_model) { | 290 if (bookmark_model) { |
215 result.count = CountBookmarksFromNode(bookmark_model->bookmark_bar_node()) + | 291 if (bookmark_model->loaded()) { |
216 CountBookmarksFromNode(bookmark_model->other_node()) + | 292 CountBookmarks(bookmark_model); |
217 CountBookmarksFromNode(bookmark_model->mobile_node()); | 293 } else { |
218 result.success = true; | 294 AddRef(); |
| 295 bookmark_model_helper_.reset(new BookmarkModelHelper(this)); |
| 296 bookmark_model->AddObserver(bookmark_model_helper_.get()); |
| 297 } |
219 } else { | 298 } else { |
220 result.count = 0; | 299 StatisticsCallbackFailure(profiles::kProfileStatisticsBookmarks); |
221 result.success = false; | |
222 } | 300 } |
223 return result; | |
224 } | 301 } |
225 | 302 |
226 ProfileStatValue ProfileStatisticsAggregator::CountPrefs() const { | 303 ProfileStatValue ProfileStatisticsAggregator::CountPrefs() const { |
227 const PrefService* pref_service = profile_->GetPrefs(); | 304 const PrefService* pref_service = profile_->GetPrefs(); |
228 | 305 |
229 ProfileStatValue result; | 306 ProfileStatValue result; |
230 if (pref_service) { | 307 if (pref_service) { |
231 scoped_ptr<base::DictionaryValue> prefs = | 308 scoped_ptr<base::DictionaryValue> prefs = |
232 pref_service->GetPreferenceValuesWithoutPathExpansion(); | 309 pref_service->GetPreferenceValuesWithoutPathExpansion(); |
233 | 310 |
(...skipping 21 matching lines...) Expand all Loading... |
255 } // namespace | 332 } // namespace |
256 | 333 |
257 namespace profiles { | 334 namespace profiles { |
258 | 335 |
259 // Constants for the categories in ProfileCategoryStats | 336 // Constants for the categories in ProfileCategoryStats |
260 const char kProfileStatisticsBrowsingHistory[] = "BrowsingHistory"; | 337 const char kProfileStatisticsBrowsingHistory[] = "BrowsingHistory"; |
261 const char kProfileStatisticsPasswords[] = "Passwords"; | 338 const char kProfileStatisticsPasswords[] = "Passwords"; |
262 const char kProfileStatisticsBookmarks[] = "Bookmarks"; | 339 const char kProfileStatisticsBookmarks[] = "Bookmarks"; |
263 const char kProfileStatisticsSettings[] = "Settings"; | 340 const char kProfileStatisticsSettings[] = "Settings"; |
264 | 341 |
265 void GetProfileStatistics(Profile* profile, | 342 void GatherProfileStatistics(Profile* profile, |
266 const ProfileStatisticsCallback& callback, | 343 const ProfileStatisticsCallback& callback, |
267 base::CancelableTaskTracker* tracker) { | 344 base::CancelableTaskTracker* tracker) { |
| 345 DCHECK(profile); |
| 346 if (profile->IsOffTheRecord() || profile->IsSystemProfile()) { |
| 347 NOTREACHED(); |
| 348 return; |
| 349 } |
| 350 |
268 scoped_refptr<ProfileStatisticsAggregator> aggregator = | 351 scoped_refptr<ProfileStatisticsAggregator> aggregator = |
269 new ProfileStatisticsAggregator(profile, callback, tracker); | 352 new ProfileStatisticsAggregator(profile, callback, tracker); |
270 } | 353 } |
271 | 354 |
272 ProfileCategoryStats GetProfileStatisticsFromCache( | 355 ProfileCategoryStats GetProfileStatisticsFromCache( |
273 const base::FilePath& profile_path) { | 356 const base::FilePath& profile_path) { |
274 ProfileInfoCache& profile_info_cache = | 357 ProfileInfoCache& profile_info_cache = |
275 g_browser_process->profile_manager()->GetProfileInfoCache(); | 358 g_browser_process->profile_manager()->GetProfileInfoCache(); |
276 ProfileAttributesEntry* entry = nullptr; | 359 ProfileAttributesEntry* entry = nullptr; |
277 bool has_entry = profile_info_cache. | 360 bool has_entry = profile_info_cache. |
(...skipping 24 matching lines...) Expand all Loading... |
302 | 385 |
303 return stats; | 386 return stats; |
304 } | 387 } |
305 | 388 |
306 void SetProfileStatisticsInCache(const base::FilePath& profile_path, | 389 void SetProfileStatisticsInCache(const base::FilePath& profile_path, |
307 const std::string& category, int count) { | 390 const std::string& category, int count) { |
308 // If local_state() is null, profile_manager() will seg-fault. | 391 // If local_state() is null, profile_manager() will seg-fault. |
309 if (!g_browser_process || !g_browser_process->local_state()) | 392 if (!g_browser_process || !g_browser_process->local_state()) |
310 return; | 393 return; |
311 | 394 |
312 ProfileInfoCache& profile_info_cache = | 395 // profile_manager() may return a null pointer. |
313 g_browser_process->profile_manager()->GetProfileInfoCache(); | 396 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 397 if (!profile_manager) |
| 398 return; |
| 399 |
| 400 ProfileInfoCache& profile_info_cache = profile_manager->GetProfileInfoCache(); |
314 ProfileAttributesEntry* entry = nullptr; | 401 ProfileAttributesEntry* entry = nullptr; |
315 if (!profile_info_cache.GetProfileAttributesWithPath(profile_path, &entry)) | 402 if (!profile_info_cache.GetProfileAttributesWithPath(profile_path, &entry)) |
316 return; | 403 return; |
317 | 404 |
318 if (category == kProfileStatisticsBrowsingHistory) { | 405 if (category == kProfileStatisticsBrowsingHistory) { |
319 entry->SetStatsBrowsingHistory(count); | 406 entry->SetStatsBrowsingHistory(count); |
320 } else if (category == kProfileStatisticsPasswords) { | 407 } else if (category == kProfileStatisticsPasswords) { |
321 entry->SetStatsPasswords(count); | 408 entry->SetStatsPasswords(count); |
322 } else if (category == kProfileStatisticsBookmarks) { | 409 } else if (category == kProfileStatisticsBookmarks) { |
323 entry->SetStatsBookmarks(count); | 410 entry->SetStatsBookmarks(count); |
324 } else if (category == kProfileStatisticsSettings) { | 411 } else if (category == kProfileStatisticsSettings) { |
325 entry->SetStatsSettings(count); | 412 entry->SetStatsSettings(count); |
326 } else { | 413 } else { |
327 NOTREACHED(); | 414 NOTREACHED(); |
328 } | 415 } |
329 } | 416 } |
330 | 417 |
331 } // namespace profiles | 418 } // namespace profiles |
OLD | NEW |