Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: components/offline_pages/offline_page_metadata_store_sql.cc

Issue 2353393002: [Offline pages] Extracting and templatizing types for store callbacks (Closed)
Patch Set: Removing offline_store_types_impl.h Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_metadata_store_sql.h" 5 #include "components/offline_pages/offline_page_metadata_store_sql.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 ItemActionStatus status = Insert(db, offline_page); 324 ItemActionStatus status = Insert(db, offline_page);
325 runner->PostTask(FROM_HERE, base::Bind(callback, status)); 325 runner->PostTask(FROM_HERE, base::Bind(callback, status));
326 } 326 }
327 327
328 void PostStoreUpdateResultForIds( 328 void PostStoreUpdateResultForIds(
329 scoped_refptr<base::SingleThreadTaskRunner> runner, 329 scoped_refptr<base::SingleThreadTaskRunner> runner,
330 StoreState store_state, 330 StoreState store_state,
331 const std::vector<int64_t>& offline_ids, 331 const std::vector<int64_t>& offline_ids,
332 ItemActionStatus action_status, 332 ItemActionStatus action_status,
333 const OfflinePageMetadataStore::UpdateCallback& callback) { 333 const OfflinePageMetadataStore::UpdateCallback& callback) {
334 std::unique_ptr<StoreUpdateResult> result(new StoreUpdateResult(store_state)); 334 std::unique_ptr<OfflinePagesUpdateResult> result(
335 new OfflinePagesUpdateResult(store_state));
335 for (const auto& offline_id : offline_ids) 336 for (const auto& offline_id : offline_ids)
336 result->item_statuses.push_back(std::make_pair(offline_id, action_status)); 337 result->item_statuses.push_back(std::make_pair(offline_id, action_status));
337 runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&result))); 338 runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&result)));
338 } 339 }
339 340
340 void PostStoreErrorForAllPages( 341 void PostStoreErrorForAllPages(
341 scoped_refptr<base::SingleThreadTaskRunner> runner, 342 scoped_refptr<base::SingleThreadTaskRunner> runner,
342 const std::vector<OfflinePageItem>& pages, 343 const std::vector<OfflinePageItem>& pages,
343 const OfflinePageMetadataStore::UpdateCallback& callback) { 344 const OfflinePageMetadataStore::UpdateCallback& callback) {
344 std::vector<int64_t> offline_ids; 345 std::vector<int64_t> offline_ids;
345 for (const auto& page : pages) 346 for (const auto& page : pages)
346 offline_ids.push_back(page.offline_id); 347 offline_ids.push_back(page.offline_id);
347 PostStoreUpdateResultForIds(runner, StoreState::LOADED, offline_ids, 348 PostStoreUpdateResultForIds(runner, StoreState::LOADED, offline_ids,
348 ItemActionStatus::STORE_ERROR, callback); 349 ItemActionStatus::STORE_ERROR, callback);
349 } 350 }
350 351
351 void PostStoreErrorForAllIds( 352 void PostStoreErrorForAllIds(
352 scoped_refptr<base::SingleThreadTaskRunner> runner, 353 scoped_refptr<base::SingleThreadTaskRunner> runner,
353 const std::vector<int64_t>& offline_ids, 354 const std::vector<int64_t>& offline_ids,
354 const OfflinePageMetadataStore::UpdateCallback& callback) { 355 const OfflinePageMetadataStore::UpdateCallback& callback) {
355 PostStoreUpdateResultForIds(runner, StoreState::LOADED, offline_ids, 356 PostStoreUpdateResultForIds(runner, StoreState::LOADED, offline_ids,
356 ItemActionStatus::STORE_ERROR, callback); 357 ItemActionStatus::STORE_ERROR, callback);
357 } 358 }
358 359
359 void UpdateOfflinePagesSync( 360 void UpdateOfflinePagesSync(
360 sql::Connection* db, 361 sql::Connection* db,
361 scoped_refptr<base::SingleThreadTaskRunner> runner, 362 scoped_refptr<base::SingleThreadTaskRunner> runner,
362 const std::vector<OfflinePageItem>& pages, 363 const std::vector<OfflinePageItem>& pages,
363 const OfflinePageMetadataStore::UpdateCallback& callback) { 364 const OfflinePageMetadataStore::UpdateCallback& callback) {
364 std::unique_ptr<StoreUpdateResult> result( 365 std::unique_ptr<OfflinePagesUpdateResult> result(
365 new StoreUpdateResult(StoreState::LOADED)); 366 new OfflinePagesUpdateResult(StoreState::LOADED));
366 367
367 sql::Transaction transaction(db); 368 sql::Transaction transaction(db);
368 if (!transaction.Begin()) { 369 if (!transaction.Begin()) {
369 PostStoreErrorForAllPages(runner, pages, callback); 370 PostStoreErrorForAllPages(runner, pages, callback);
370 return; 371 return;
371 } 372 }
372 373
373 for (const auto& page : pages) { 374 for (const auto& page : pages) {
374 if (Update(db, page)) { 375 if (Update(db, page)) {
375 result->updated_items.push_back(page); 376 result->updated_items.push_back(page);
(...skipping 11 matching lines...) Expand all
387 } 388 }
388 runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&result))); 389 runner->PostTask(FROM_HERE, base::Bind(callback, base::Passed(&result)));
389 } 390 }
390 391
391 void RemoveOfflinePagesSync( 392 void RemoveOfflinePagesSync(
392 const std::vector<int64_t>& offline_ids, 393 const std::vector<int64_t>& offline_ids,
393 sql::Connection* db, 394 sql::Connection* db,
394 scoped_refptr<base::SingleThreadTaskRunner> runner, 395 scoped_refptr<base::SingleThreadTaskRunner> runner,
395 const OfflinePageMetadataStore::UpdateCallback& callback) { 396 const OfflinePageMetadataStore::UpdateCallback& callback) {
396 // TODO(fgorski): Perhaps add metrics here. 397 // TODO(fgorski): Perhaps add metrics here.
397 std::unique_ptr<StoreUpdateResult> result( 398 std::unique_ptr<OfflinePagesUpdateResult> result(
398 new StoreUpdateResult(StoreState::LOADED)); 399 new OfflinePagesUpdateResult(StoreState::LOADED));
399 400
400 // If you create a transaction but don't Commit() it is automatically 401 // If you create a transaction but don't Commit() it is automatically
401 // rolled back by its destructor when it falls out of scope. 402 // rolled back by its destructor when it falls out of scope.
402 sql::Transaction transaction(db); 403 sql::Transaction transaction(db);
403 if (!transaction.Begin()) { 404 if (!transaction.Begin()) {
404 PostStoreErrorForAllIds(runner, offline_ids, callback); 405 PostStoreErrorForAllIds(runner, offline_ids, callback);
405 return; 406 return;
406 } 407 }
407 408
408 for (int64_t offline_id : offline_ids) { 409 for (int64_t offline_id : offline_ids) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 bool OfflinePageMetadataStoreSQL::CheckDb(const base::Closure& callback) { 579 bool OfflinePageMetadataStoreSQL::CheckDb(const base::Closure& callback) {
579 if (!db_.get() || state_ != StoreState::LOADED) { 580 if (!db_.get() || state_ != StoreState::LOADED) {
580 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 581 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
581 base::Bind(callback)); 582 base::Bind(callback));
582 return false; 583 return false;
583 } 584 }
584 return true; 585 return true;
585 } 586 }
586 587
587 } // namespace offline_pages 588 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698