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 "components/offline_pages/offline_page_model.h" | 5 #include "components/offline_pages/offline_page_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 for (const auto& file_path : paths_to_delete) { | 78 for (const auto& file_path : paths_to_delete) { |
79 // Make sure delete happens on the left of || so that it is always executed. | 79 // Make sure delete happens on the left of || so that it is always executed. |
80 *success = base::DeleteFile(file_path, false) || *success; | 80 *success = base::DeleteFile(file_path, false) || *success; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void EmptyDeleteCallback(OfflinePageModel::DeletePageResult /* result */) { | 84 void EmptyDeleteCallback(OfflinePageModel::DeletePageResult /* result */) { |
85 } | 85 } |
86 | 86 |
87 void FindPagesMissingArchiveFile( | 87 void FindPagesMissingArchiveFile( |
88 const std::vector<std::pair<int64, base::FilePath>>& id_path_pairs, | 88 const std::vector<std::pair<int64_t, base::FilePath>>& id_path_pairs, |
89 std::vector<int64>* ids_of_pages_missing_archive_file) { | 89 std::vector<int64_t>* ids_of_pages_missing_archive_file) { |
90 DCHECK(ids_of_pages_missing_archive_file); | 90 DCHECK(ids_of_pages_missing_archive_file); |
91 | 91 |
92 for (const auto& id_path : id_path_pairs) { | 92 for (const auto& id_path : id_path_pairs) { |
93 if (!base::PathExists(id_path.second) || | 93 if (!base::PathExists(id_path.second) || |
94 base::DirectoryExists(id_path.second)) { | 94 base::DirectoryExists(id_path.second)) { |
95 ids_of_pages_missing_archive_file->push_back(id_path.first); | 95 ids_of_pages_missing_archive_file->push_back(id_path.first); |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 void OfflinePageModel::AddObserver(Observer* observer) { | 143 void OfflinePageModel::AddObserver(Observer* observer) { |
144 observers_.AddObserver(observer); | 144 observers_.AddObserver(observer); |
145 } | 145 } |
146 | 146 |
147 void OfflinePageModel::RemoveObserver(Observer* observer) { | 147 void OfflinePageModel::RemoveObserver(Observer* observer) { |
148 observers_.RemoveObserver(observer); | 148 observers_.RemoveObserver(observer); |
149 } | 149 } |
150 | 150 |
151 void OfflinePageModel::SavePage(const GURL& url, | 151 void OfflinePageModel::SavePage(const GURL& url, |
152 int64 bookmark_id, | 152 int64_t bookmark_id, |
153 scoped_ptr<OfflinePageArchiver> archiver, | 153 scoped_ptr<OfflinePageArchiver> archiver, |
154 const SavePageCallback& callback) { | 154 const SavePageCallback& callback) { |
155 DCHECK(is_loaded_); | 155 DCHECK(is_loaded_); |
156 | 156 |
157 // Skip saving the page that is not intended to be saved, like local file | 157 // Skip saving the page that is not intended to be saved, like local file |
158 // page. | 158 // page. |
159 if (!CanSavePage(url)) { | 159 if (!CanSavePage(url)) { |
160 InformSavePageDone(callback, SavePageResult::SKIPPED); | 160 InformSavePageDone(callback, SavePageResult::SKIPPED); |
161 return; | 161 return; |
162 } | 162 } |
163 | 163 |
164 DCHECK(archiver.get()); | 164 DCHECK(archiver.get()); |
165 archiver->CreateArchive(archives_dir_, | 165 archiver->CreateArchive(archives_dir_, |
166 base::Bind(&OfflinePageModel::OnCreateArchiveDone, | 166 base::Bind(&OfflinePageModel::OnCreateArchiveDone, |
167 weak_ptr_factory_.GetWeakPtr(), url, | 167 weak_ptr_factory_.GetWeakPtr(), url, |
168 bookmark_id, base::Time::Now(), callback)); | 168 bookmark_id, base::Time::Now(), callback)); |
169 pending_archivers_.push_back(archiver.Pass()); | 169 pending_archivers_.push_back(archiver.Pass()); |
170 } | 170 } |
171 | 171 |
172 void OfflinePageModel::MarkPageAccessed(int64 bookmark_id) { | 172 void OfflinePageModel::MarkPageAccessed(int64_t bookmark_id) { |
173 DCHECK(is_loaded_); | 173 DCHECK(is_loaded_); |
174 auto iter = offline_pages_.find(bookmark_id); | 174 auto iter = offline_pages_.find(bookmark_id); |
175 if (iter == offline_pages_.end()) | 175 if (iter == offline_pages_.end()) |
176 return; | 176 return; |
177 | 177 |
178 // MarkPageAccessed should not be called for a page that is being marked for | 178 // MarkPageAccessed should not be called for a page that is being marked for |
179 // deletion. | 179 // deletion. |
180 DCHECK(!iter->second.IsMarkedForDeletion()); | 180 DCHECK(!iter->second.IsMarkedForDeletion()); |
181 | 181 |
182 // Make a copy of the cached item and update it. The cached item should only | 182 // Make a copy of the cached item and update it. The cached item should only |
183 // be updated upon the successful store operation. | 183 // be updated upon the successful store operation. |
184 OfflinePageItem offline_page_item = iter->second; | 184 OfflinePageItem offline_page_item = iter->second; |
185 offline_page_item.last_access_time = base::Time::Now(); | 185 offline_page_item.last_access_time = base::Time::Now(); |
186 offline_page_item.access_count++; | 186 offline_page_item.access_count++; |
187 store_->AddOrUpdateOfflinePage( | 187 store_->AddOrUpdateOfflinePage( |
188 offline_page_item, | 188 offline_page_item, |
189 base::Bind(&OfflinePageModel::OnMarkPageAccesseDone, | 189 base::Bind(&OfflinePageModel::OnMarkPageAccesseDone, |
190 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); | 190 weak_ptr_factory_.GetWeakPtr(), offline_page_item)); |
191 } | 191 } |
192 | 192 |
193 void OfflinePageModel::MarkPageForDeletion(int64 bookmark_id, | 193 void OfflinePageModel::MarkPageForDeletion(int64_t bookmark_id, |
194 const DeletePageCallback& callback) { | 194 const DeletePageCallback& callback) { |
195 DCHECK(is_loaded_); | 195 DCHECK(is_loaded_); |
196 auto iter = offline_pages_.find(bookmark_id); | 196 auto iter = offline_pages_.find(bookmark_id); |
197 if (iter == offline_pages_.end()) { | 197 if (iter == offline_pages_.end()) { |
198 InformDeletePageDone(callback, DeletePageResult::NOT_FOUND); | 198 InformDeletePageDone(callback, DeletePageResult::NOT_FOUND); |
199 return; | 199 return; |
200 } | 200 } |
201 | 201 |
202 // Make a copy of the cached item and update it. The cached item should only | 202 // Make a copy of the cached item and update it. The cached item should only |
203 // be updated upon the successful store operation. | 203 // be updated upon the successful store operation. |
204 OfflinePageItem offline_page_item = iter->second; | 204 OfflinePageItem offline_page_item = iter->second; |
205 offline_page_item.MarkForDeletion(); | 205 offline_page_item.MarkForDeletion(); |
206 store_->AddOrUpdateOfflinePage( | 206 store_->AddOrUpdateOfflinePage( |
207 offline_page_item, | 207 offline_page_item, |
208 base::Bind(&OfflinePageModel::OnMarkPageForDeletionDone, | 208 base::Bind(&OfflinePageModel::OnMarkPageForDeletionDone, |
209 weak_ptr_factory_.GetWeakPtr(), offline_page_item, callback)); | 209 weak_ptr_factory_.GetWeakPtr(), offline_page_item, callback)); |
210 } | 210 } |
211 | 211 |
212 void OfflinePageModel::DeletePageByBookmarkId( | 212 void OfflinePageModel::DeletePageByBookmarkId( |
213 int64 bookmark_id, | 213 int64_t bookmark_id, |
214 const DeletePageCallback& callback) { | 214 const DeletePageCallback& callback) { |
215 DCHECK(is_loaded_); | 215 DCHECK(is_loaded_); |
216 std::vector<int64> bookmark_ids_to_delete; | 216 std::vector<int64_t> bookmark_ids_to_delete; |
217 bookmark_ids_to_delete.push_back(bookmark_id); | 217 bookmark_ids_to_delete.push_back(bookmark_id); |
218 DeletePagesByBookmarkId(bookmark_ids_to_delete, callback); | 218 DeletePagesByBookmarkId(bookmark_ids_to_delete, callback); |
219 } | 219 } |
220 | 220 |
221 void OfflinePageModel::DeletePagesByBookmarkId( | 221 void OfflinePageModel::DeletePagesByBookmarkId( |
222 const std::vector<int64>& bookmark_ids, | 222 const std::vector<int64_t>& bookmark_ids, |
223 const DeletePageCallback& callback) { | 223 const DeletePageCallback& callback) { |
224 DCHECK(is_loaded_); | 224 DCHECK(is_loaded_); |
225 | 225 |
226 std::vector<base::FilePath> paths_to_delete; | 226 std::vector<base::FilePath> paths_to_delete; |
227 for (const auto& bookmark_id : bookmark_ids) { | 227 for (const auto& bookmark_id : bookmark_ids) { |
228 auto iter = offline_pages_.find(bookmark_id); | 228 auto iter = offline_pages_.find(bookmark_id); |
229 if (iter != offline_pages_.end()) { | 229 if (iter != offline_pages_.end()) { |
230 paths_to_delete.push_back(iter->second.file_path); | 230 paths_to_delete.push_back(iter->second.file_path); |
231 } | 231 } |
232 } | 232 } |
(...skipping 10 matching lines...) Expand all Loading... |
243 base::Bind(&OfflinePageModel::OnDeleteArchiveFilesDone, | 243 base::Bind(&OfflinePageModel::OnDeleteArchiveFilesDone, |
244 weak_ptr_factory_.GetWeakPtr(), | 244 weak_ptr_factory_.GetWeakPtr(), |
245 bookmark_ids, | 245 bookmark_ids, |
246 callback, | 246 callback, |
247 base::Owned(success))); | 247 base::Owned(success))); |
248 } | 248 } |
249 | 249 |
250 void OfflinePageModel::ClearAll(const base::Closure& callback) { | 250 void OfflinePageModel::ClearAll(const base::Closure& callback) { |
251 DCHECK(is_loaded_); | 251 DCHECK(is_loaded_); |
252 | 252 |
253 std::vector<int64> bookmark_ids; | 253 std::vector<int64_t> bookmark_ids; |
254 for (const auto& id_page_pair : offline_pages_) | 254 for (const auto& id_page_pair : offline_pages_) |
255 bookmark_ids.push_back(id_page_pair.first); | 255 bookmark_ids.push_back(id_page_pair.first); |
256 DeletePagesByBookmarkId( | 256 DeletePagesByBookmarkId( |
257 bookmark_ids, | 257 bookmark_ids, |
258 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, | 258 base::Bind(&OfflinePageModel::OnRemoveAllFilesDoneForClearAll, |
259 weak_ptr_factory_.GetWeakPtr(), | 259 weak_ptr_factory_.GetWeakPtr(), |
260 callback)); | 260 callback)); |
261 } | 261 } |
262 | 262 |
263 bool OfflinePageModel::HasOfflinePages() const { | 263 bool OfflinePageModel::HasOfflinePages() const { |
(...skipping 25 matching lines...) Expand all Loading... |
289 for (const auto& id_page_pair : offline_pages_) { | 289 for (const auto& id_page_pair : offline_pages_) { |
290 if (!id_page_pair.second.IsMarkedForDeletion() && | 290 if (!id_page_pair.second.IsMarkedForDeletion() && |
291 now - id_page_pair.second.last_access_time > kPageCleanUpThreshold) { | 291 now - id_page_pair.second.last_access_time > kPageCleanUpThreshold) { |
292 offline_pages.push_back(id_page_pair.second); | 292 offline_pages.push_back(id_page_pair.second); |
293 } | 293 } |
294 } | 294 } |
295 return offline_pages; | 295 return offline_pages; |
296 } | 296 } |
297 | 297 |
298 const OfflinePageItem* OfflinePageModel::GetPageByBookmarkId( | 298 const OfflinePageItem* OfflinePageModel::GetPageByBookmarkId( |
299 int64 bookmark_id) const { | 299 int64_t bookmark_id) const { |
300 const auto iter = offline_pages_.find(bookmark_id); | 300 const auto iter = offline_pages_.find(bookmark_id); |
301 return iter != offline_pages_.end() && !iter->second.IsMarkedForDeletion() | 301 return iter != offline_pages_.end() && !iter->second.IsMarkedForDeletion() |
302 ? &(iter->second) | 302 ? &(iter->second) |
303 : nullptr; | 303 : nullptr; |
304 } | 304 } |
305 | 305 |
306 const OfflinePageItem* OfflinePageModel::GetPageByOfflineURL( | 306 const OfflinePageItem* OfflinePageModel::GetPageByOfflineURL( |
307 const GURL& offline_url) const { | 307 const GURL& offline_url) const { |
308 for (auto iter = offline_pages_.begin(); | 308 for (auto iter = offline_pages_.begin(); |
309 iter != offline_pages_.end(); | 309 iter != offline_pages_.end(); |
(...skipping 12 matching lines...) Expand all Loading... |
322 ++iter) { | 322 ++iter) { |
323 if (iter->second.url == online_url && !iter->second.IsMarkedForDeletion()) | 323 if (iter->second.url == online_url && !iter->second.IsMarkedForDeletion()) |
324 return &(iter->second); | 324 return &(iter->second); |
325 } | 325 } |
326 return nullptr; | 326 return nullptr; |
327 } | 327 } |
328 | 328 |
329 void OfflinePageModel::CheckForExternalFileDeletion() { | 329 void OfflinePageModel::CheckForExternalFileDeletion() { |
330 DCHECK(is_loaded_); | 330 DCHECK(is_loaded_); |
331 | 331 |
332 std::vector<std::pair<int64, base::FilePath>> id_path_pairs; | 332 std::vector<std::pair<int64_t, base::FilePath>> id_path_pairs; |
333 for (const auto& id_page_pair : offline_pages_) { | 333 for (const auto& id_page_pair : offline_pages_) { |
334 id_path_pairs.push_back( | 334 id_path_pairs.push_back( |
335 std::make_pair(id_page_pair.first, id_page_pair.second.file_path)); | 335 std::make_pair(id_page_pair.first, id_page_pair.second.file_path)); |
336 } | 336 } |
337 | 337 |
338 std::vector<int64>* ids_of_pages_missing_archive_file = | 338 std::vector<int64_t>* ids_of_pages_missing_archive_file = |
339 new std::vector<int64>(); | 339 new std::vector<int64_t>(); |
340 task_runner_->PostTaskAndReply( | 340 task_runner_->PostTaskAndReply( |
341 FROM_HERE, base::Bind(&FindPagesMissingArchiveFile, id_path_pairs, | 341 FROM_HERE, base::Bind(&FindPagesMissingArchiveFile, id_path_pairs, |
342 ids_of_pages_missing_archive_file), | 342 ids_of_pages_missing_archive_file), |
343 base::Bind(&OfflinePageModel::OnFindPagesMissingArchiveFile, | 343 base::Bind(&OfflinePageModel::OnFindPagesMissingArchiveFile, |
344 weak_ptr_factory_.GetWeakPtr(), | 344 weak_ptr_factory_.GetWeakPtr(), |
345 base::Owned(ids_of_pages_missing_archive_file))); | 345 base::Owned(ids_of_pages_missing_archive_file))); |
346 } | 346 } |
347 | 347 |
348 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { | 348 OfflinePageMetadataStore* OfflinePageModel::GetStoreForTesting() { |
349 return store_.get(); | 349 return store_.get(); |
350 } | 350 } |
351 | 351 |
352 void OfflinePageModel::OnCreateArchiveDone(const GURL& requested_url, | 352 void OfflinePageModel::OnCreateArchiveDone(const GURL& requested_url, |
353 int64 bookmark_id, | 353 int64_t bookmark_id, |
354 const base::Time& start_time, | 354 const base::Time& start_time, |
355 const SavePageCallback& callback, | 355 const SavePageCallback& callback, |
356 OfflinePageArchiver* archiver, | 356 OfflinePageArchiver* archiver, |
357 ArchiverResult archiver_result, | 357 ArchiverResult archiver_result, |
358 const GURL& url, | 358 const GURL& url, |
359 const base::FilePath& file_path, | 359 const base::FilePath& file_path, |
360 int64 file_size) { | 360 int64_t file_size) { |
361 if (requested_url != url) { | 361 if (requested_url != url) { |
362 DVLOG(1) << "Saved URL does not match requested URL."; | 362 DVLOG(1) << "Saved URL does not match requested URL."; |
363 // TODO(fgorski): We have created an archive for a wrong URL. It should be | 363 // TODO(fgorski): We have created an archive for a wrong URL. It should be |
364 // deleted from here, once archiver has the right functionality. | 364 // deleted from here, once archiver has the right functionality. |
365 InformSavePageDone(callback, SavePageResult::ARCHIVE_CREATION_FAILED); | 365 InformSavePageDone(callback, SavePageResult::ARCHIVE_CREATION_FAILED); |
366 DeletePendingArchiver(archiver); | 366 DeletePendingArchiver(archiver); |
367 return; | 367 return; |
368 } | 368 } |
369 | 369 |
370 if (archiver_result != ArchiverResult::SUCCESSFULLY_CREATED) { | 370 if (archiver_result != ArchiverResult::SUCCESSFULLY_CREATED) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 void OfflinePageModel::OnUndoOfflinePageDone( | 443 void OfflinePageModel::OnUndoOfflinePageDone( |
444 const OfflinePageItem& offline_page, bool success) { | 444 const OfflinePageItem& offline_page, bool success) { |
445 if (!success) | 445 if (!success) |
446 return; | 446 return; |
447 offline_pages_[offline_page.bookmark_id] = offline_page; | 447 offline_pages_[offline_page.bookmark_id] = offline_page; |
448 | 448 |
449 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); | 449 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageModelChanged(this)); |
450 } | 450 } |
451 | 451 |
452 void OfflinePageModel::FinalizePageDeletion() { | 452 void OfflinePageModel::FinalizePageDeletion() { |
453 std::vector<int64> bookmark_ids_pending_deletion; | 453 std::vector<int64_t> bookmark_ids_pending_deletion; |
454 for (const auto& id_page_pair : offline_pages_) { | 454 for (const auto& id_page_pair : offline_pages_) { |
455 if (!id_page_pair.second.IsMarkedForDeletion()) | 455 if (!id_page_pair.second.IsMarkedForDeletion()) |
456 continue; | 456 continue; |
457 bookmark_ids_pending_deletion.push_back(id_page_pair.second.bookmark_id); | 457 bookmark_ids_pending_deletion.push_back(id_page_pair.second.bookmark_id); |
458 } | 458 } |
459 DeletePagesByBookmarkId(bookmark_ids_pending_deletion, DeletePageCallback()); | 459 DeletePagesByBookmarkId(bookmark_ids_pending_deletion, DeletePageCallback()); |
460 } | 460 } |
461 | 461 |
462 void OfflinePageModel::UndoPageDeletion(int64 bookmark_id) { | 462 void OfflinePageModel::UndoPageDeletion(int64_t bookmark_id) { |
463 auto iter = offline_pages_.find(bookmark_id); | 463 auto iter = offline_pages_.find(bookmark_id); |
464 if (iter == offline_pages_.end()) | 464 if (iter == offline_pages_.end()) |
465 return; | 465 return; |
466 | 466 |
467 // Make a copy of the cached item and update it. The cached item should only | 467 // Make a copy of the cached item and update it. The cached item should only |
468 // be updated upon the successful store operation. | 468 // be updated upon the successful store operation. |
469 OfflinePageItem offline_page_item = iter->second; | 469 OfflinePageItem offline_page_item = iter->second; |
470 if (!offline_page_item.IsMarkedForDeletion()) | 470 if (!offline_page_item.IsMarkedForDeletion()) |
471 return; | 471 return; |
472 | 472 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 static_cast<int>(SavePageResult::RESULT_COUNT)); | 554 static_cast<int>(SavePageResult::RESULT_COUNT)); |
555 callback.Run(result); | 555 callback.Run(result); |
556 } | 556 } |
557 | 557 |
558 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { | 558 void OfflinePageModel::DeletePendingArchiver(OfflinePageArchiver* archiver) { |
559 pending_archivers_.erase(std::find( | 559 pending_archivers_.erase(std::find( |
560 pending_archivers_.begin(), pending_archivers_.end(), archiver)); | 560 pending_archivers_.begin(), pending_archivers_.end(), archiver)); |
561 } | 561 } |
562 | 562 |
563 void OfflinePageModel::OnDeleteArchiveFilesDone( | 563 void OfflinePageModel::OnDeleteArchiveFilesDone( |
564 const std::vector<int64>& bookmark_ids, | 564 const std::vector<int64_t>& bookmark_ids, |
565 const DeletePageCallback& callback, | 565 const DeletePageCallback& callback, |
566 const bool* success) { | 566 const bool* success) { |
567 DCHECK(success); | 567 DCHECK(success); |
568 | 568 |
569 if (!*success) { | 569 if (!*success) { |
570 InformDeletePageDone(callback, DeletePageResult::DEVICE_FAILURE); | 570 InformDeletePageDone(callback, DeletePageResult::DEVICE_FAILURE); |
571 return; | 571 return; |
572 } | 572 } |
573 | 573 |
574 store_->RemoveOfflinePages( | 574 store_->RemoveOfflinePages( |
575 bookmark_ids, | 575 bookmark_ids, |
576 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone, | 576 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone, |
577 weak_ptr_factory_.GetWeakPtr(), bookmark_ids, callback)); | 577 weak_ptr_factory_.GetWeakPtr(), bookmark_ids, callback)); |
578 } | 578 } |
579 | 579 |
580 void OfflinePageModel::OnRemoveOfflinePagesDone( | 580 void OfflinePageModel::OnRemoveOfflinePagesDone( |
581 const std::vector<int64>& bookmark_ids, | 581 const std::vector<int64_t>& bookmark_ids, |
582 const DeletePageCallback& callback, | 582 const DeletePageCallback& callback, |
583 bool success) { | 583 bool success) { |
584 // Delete the offline page from the in memory cache regardless of success in | 584 // Delete the offline page from the in memory cache regardless of success in |
585 // store. | 585 // store. |
586 base::Time now = base::Time::Now(); | 586 base::Time now = base::Time::Now(); |
587 int64 total_size = 0; | 587 int64_t total_size = 0; |
588 for (int64 bookmark_id : bookmark_ids) { | 588 for (int64_t bookmark_id : bookmark_ids) { |
589 auto iter = offline_pages_.find(bookmark_id); | 589 auto iter = offline_pages_.find(bookmark_id); |
590 if (iter == offline_pages_.end()) | 590 if (iter == offline_pages_.end()) |
591 continue; | 591 continue; |
592 total_size += iter->second.file_size; | 592 total_size += iter->second.file_size; |
593 UMA_HISTOGRAM_CUSTOM_COUNTS( | 593 UMA_HISTOGRAM_CUSTOM_COUNTS( |
594 "OfflinePages.PageLifetime", | 594 "OfflinePages.PageLifetime", |
595 (now - iter->second.creation_time).InMinutes(), | 595 (now - iter->second.creation_time).InMinutes(), |
596 1, | 596 1, |
597 base::TimeDelta::FromDays(365).InMinutes(), | 597 base::TimeDelta::FromDays(365).InMinutes(), |
598 100); | 598 100); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 DeletePageResult result) { | 638 DeletePageResult result) { |
639 UMA_HISTOGRAM_ENUMERATION( | 639 UMA_HISTOGRAM_ENUMERATION( |
640 "OfflinePages.DeletePageResult", | 640 "OfflinePages.DeletePageResult", |
641 static_cast<int>(result), | 641 static_cast<int>(result), |
642 static_cast<int>(DeletePageResult::RESULT_COUNT)); | 642 static_cast<int>(DeletePageResult::RESULT_COUNT)); |
643 if (!callback.is_null()) | 643 if (!callback.is_null()) |
644 callback.Run(result); | 644 callback.Run(result); |
645 } | 645 } |
646 | 646 |
647 void OfflinePageModel::OnFindPagesMissingArchiveFile( | 647 void OfflinePageModel::OnFindPagesMissingArchiveFile( |
648 const std::vector<int64>* ids_of_pages_missing_archive_file) { | 648 const std::vector<int64_t>* ids_of_pages_missing_archive_file) { |
649 DCHECK(ids_of_pages_missing_archive_file); | 649 DCHECK(ids_of_pages_missing_archive_file); |
650 if (ids_of_pages_missing_archive_file->empty()) | 650 if (ids_of_pages_missing_archive_file->empty()) |
651 return; | 651 return; |
652 | 652 |
653 DeletePageCallback done_callback( | 653 DeletePageCallback done_callback( |
654 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone, | 654 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone, |
655 weak_ptr_factory_.GetWeakPtr(), | 655 weak_ptr_factory_.GetWeakPtr(), |
656 *ids_of_pages_missing_archive_file)); | 656 *ids_of_pages_missing_archive_file)); |
657 | 657 |
658 store_->RemoveOfflinePages( | 658 store_->RemoveOfflinePages( |
659 *ids_of_pages_missing_archive_file, | 659 *ids_of_pages_missing_archive_file, |
660 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone, | 660 base::Bind(&OfflinePageModel::OnRemoveOfflinePagesDone, |
661 weak_ptr_factory_.GetWeakPtr(), | 661 weak_ptr_factory_.GetWeakPtr(), |
662 *ids_of_pages_missing_archive_file, | 662 *ids_of_pages_missing_archive_file, |
663 done_callback)); | 663 done_callback)); |
664 } | 664 } |
665 | 665 |
666 void OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone( | 666 void OfflinePageModel::OnRemoveOfflinePagesMissingArchiveFileDone( |
667 const std::vector<int64>& bookmark_ids, | 667 const std::vector<int64_t>& bookmark_ids, |
668 OfflinePageModel::DeletePageResult /* result */) { | 668 OfflinePageModel::DeletePageResult /* result */) { |
669 for (int64 bookmark_id : bookmark_ids) { | 669 for (int64_t bookmark_id : bookmark_ids) { |
670 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageDeleted(bookmark_id)); | 670 FOR_EACH_OBSERVER(Observer, observers_, OfflinePageDeleted(bookmark_id)); |
671 } | 671 } |
672 } | 672 } |
673 | 673 |
674 void OfflinePageModel::OnRemoveAllFilesDoneForClearAll( | 674 void OfflinePageModel::OnRemoveAllFilesDoneForClearAll( |
675 const base::Closure& callback, | 675 const base::Closure& callback, |
676 DeletePageResult result) { | 676 DeletePageResult result) { |
677 store_->Reset(base::Bind(&OfflinePageModel::OnResetStoreDoneForClearAll, | 677 store_->Reset(base::Bind(&OfflinePageModel::OnResetStoreDoneForClearAll, |
678 weak_ptr_factory_.GetWeakPtr(), | 678 weak_ptr_factory_.GetWeakPtr(), |
679 callback)); | 679 callback)); |
(...skipping 28 matching lines...) Expand all Loading... |
708 } | 708 } |
709 | 709 |
710 void OfflinePageModel::CacheLoadedData( | 710 void OfflinePageModel::CacheLoadedData( |
711 const std::vector<OfflinePageItem>& offline_pages) { | 711 const std::vector<OfflinePageItem>& offline_pages) { |
712 offline_pages_.clear(); | 712 offline_pages_.clear(); |
713 for (const auto& offline_page : offline_pages) | 713 for (const auto& offline_page : offline_pages) |
714 offline_pages_[offline_page.bookmark_id] = offline_page; | 714 offline_pages_[offline_page.bookmark_id] = offline_page; |
715 } | 715 } |
716 | 716 |
717 } // namespace offline_pages | 717 } // namespace offline_pages |
OLD | NEW |