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

Side by Side Diff: content/browser/service_worker/service_worker_storage.cc

Issue 275103004: ServiceWorker: Database functions should return status code instead of boolean (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_storage.h" 5 #include "content/browser/service_worker/service_worker_storage.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
12 #include "base/task_runner_util.h" 12 #include "base/task_runner_util.h"
13 #include "content/browser/service_worker/service_worker_context_core.h" 13 #include "content/browser/service_worker/service_worker_context_core.h"
14 #include "content/browser/service_worker/service_worker_disk_cache.h" 14 #include "content/browser/service_worker/service_worker_disk_cache.h"
15 #include "content/browser/service_worker/service_worker_info.h" 15 #include "content/browser/service_worker/service_worker_info.h"
16 #include "content/browser/service_worker/service_worker_registration.h" 16 #include "content/browser/service_worker/service_worker_registration.h"
17 #include "content/browser/service_worker/service_worker_utils.h" 17 #include "content/browser/service_worker/service_worker_utils.h"
18 #include "content/browser/service_worker/service_worker_version.h" 18 #include "content/browser/service_worker/service_worker_version.h"
19 #include "content/common/service_worker/service_worker_types.h" 19 #include "content/common/service_worker/service_worker_types.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
22 #include "webkit/browser/quota/quota_manager_proxy.h" 22 #include "webkit/browser/quota/quota_manager_proxy.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 namespace { 26 namespace {
27 27
28 typedef base::Callback<void( 28 typedef base::Callback<void(
29 ServiceWorkerStorage::InitialData* data, 29 ServiceWorkerStorage::InitialData* data,
30 bool success)> InitializeCallback; 30 ServiceWorkerStatusCode status)> InitializeCallback;
31 typedef base::Callback<void( 31 typedef base::Callback<void(
32 const ServiceWorkerDatabase::RegistrationData& data, 32 const ServiceWorkerDatabase::RegistrationData& data,
33 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources, 33 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources,
34 ServiceWorkerStatusCode status)> ReadRegistrationCallback; 34 ServiceWorkerStatusCode status)> ReadRegistrationCallback;
35 typedef base::Callback<void( 35 typedef base::Callback<void(
36 bool origin_is_deletable, 36 bool origin_is_deletable,
37 ServiceWorkerStatusCode status)> DeleteRegistrationCallback; 37 ServiceWorkerStatusCode status)> DeleteRegistrationCallback;
38 38
39 void RunSoon(const tracked_objects::Location& from_here, 39 void RunSoon(const tracked_objects::Location& from_here,
40 const base::Closure& closure) { 40 const base::Closure& closure) {
(...skipping 22 matching lines...) Expand all
63 63
64 const int kMaxMemDiskCacheSize = 10 * 1024 * 1024; 64 const int kMaxMemDiskCacheSize = 10 * 1024 * 1024;
65 65
66 void EmptyCompletionCallback(int) {} 66 void EmptyCompletionCallback(int) {}
67 67
68 void ReadInitialDataFromDB( 68 void ReadInitialDataFromDB(
69 ServiceWorkerDatabase* database, 69 ServiceWorkerDatabase* database,
70 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 70 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
71 const InitializeCallback& callback) { 71 const InitializeCallback& callback) {
72 DCHECK(database); 72 DCHECK(database);
73 ServiceWorkerStorage::InitialData* data = 73 scoped_ptr<ServiceWorkerStorage::InitialData> data(
74 new ServiceWorkerStorage::InitialData(); 74 new ServiceWorkerStorage::InitialData());
75 bool success = 75
76 ServiceWorkerStatusCode status =
76 database->GetNextAvailableIds(&data->next_registration_id, 77 database->GetNextAvailableIds(&data->next_registration_id,
77 &data->next_version_id, 78 &data->next_version_id,
78 &data->next_resource_id) && 79 &data->next_resource_id);
79 database->GetOriginsWithRegistrations(&data->origins); 80 if (status != SERVICE_WORKER_OK) {
81 original_task_runner->PostTask(
82 FROM_HERE, base::Bind(callback, base::Owned(data.release()), status));
83 return;
84 }
85
86 status = database->GetOriginsWithRegistrations(&data->origins);
80 original_task_runner->PostTask( 87 original_task_runner->PostTask(
81 FROM_HERE, base::Bind(callback, base::Owned(data), success)); 88 FROM_HERE, base::Bind(callback, base::Owned(data.release()), status));
82 } 89 }
83 90
84 void ReadRegistrationFromDB( 91 void ReadRegistrationFromDB(
85 ServiceWorkerDatabase* database, 92 ServiceWorkerDatabase* database,
86 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 93 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
87 int64 registration_id, 94 int64 registration_id,
88 const GURL& origin, 95 const GURL& origin,
89 const ReadRegistrationCallback& callback) { 96 const ReadRegistrationCallback& callback) {
90 DCHECK(database); 97 DCHECK(database);
91 ServiceWorkerDatabase::RegistrationData data; 98 ServiceWorkerDatabase::RegistrationData data;
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 base::Bind(&ReadInitialDataFromDB, 492 base::Bind(&ReadInitialDataFromDB,
486 database_.get(), 493 database_.get(),
487 base::MessageLoopProxy::current(), 494 base::MessageLoopProxy::current(),
488 base::Bind(&ServiceWorkerStorage::DidReadInitialData, 495 base::Bind(&ServiceWorkerStorage::DidReadInitialData,
489 weak_factory_.GetWeakPtr()))); 496 weak_factory_.GetWeakPtr())));
490 return false; 497 return false;
491 } 498 }
492 499
493 void ServiceWorkerStorage::DidReadInitialData( 500 void ServiceWorkerStorage::DidReadInitialData(
494 InitialData* data, 501 InitialData* data,
495 bool success) { 502 ServiceWorkerStatusCode status) {
496 DCHECK(data); 503 DCHECK(data);
497 DCHECK_EQ(INITIALIZING, state_); 504 DCHECK_EQ(INITIALIZING, state_);
498 505
499 if (success) { 506 if (status == SERVICE_WORKER_OK) {
500 next_registration_id_ = data->next_registration_id; 507 next_registration_id_ = data->next_registration_id;
501 next_version_id_ = data->next_version_id; 508 next_version_id_ = data->next_version_id;
502 next_resource_id_ = data->next_resource_id; 509 next_resource_id_ = data->next_resource_id;
503 registered_origins_.swap(data->origins); 510 registered_origins_.swap(data->origins);
504 state_ = INITIALIZED; 511 state_ = INITIALIZED;
505 } else { 512 } else {
506 DLOG(WARNING) << "Failed to initialize."; 513 // TODO(nhiroki): If status==SERVICE_WORKER_ERROR_DB_CORRUPTED, do
514 // corruption recovery (http://crbug.com/371675).
515 DLOG(WARNING) << "Failed to initialize: "
516 << ServiceWorkerStatusToString(status);
507 state_ = DISABLED; 517 state_ = DISABLED;
508 } 518 }
509 519
510 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); 520 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin();
511 it != pending_tasks_.end(); ++it) { 521 it != pending_tasks_.end(); ++it) {
512 RunSoon(FROM_HERE, *it); 522 RunSoon(FROM_HERE, *it);
513 } 523 }
514 pending_tasks_.clear(); 524 pending_tasks_.clear();
515 } 525 }
516 526
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 // TODO(michaeln): Store data on disk and do error checking. 770 // TODO(michaeln): Store data on disk and do error checking.
761 disk_cache_.reset(new ServiceWorkerDiskCache); 771 disk_cache_.reset(new ServiceWorkerDiskCache);
762 int rv = disk_cache_->InitWithMemBackend( 772 int rv = disk_cache_->InitWithMemBackend(
763 kMaxMemDiskCacheSize, 773 kMaxMemDiskCacheSize,
764 base::Bind(&EmptyCompletionCallback)); 774 base::Bind(&EmptyCompletionCallback));
765 DCHECK_EQ(net::OK, rv); 775 DCHECK_EQ(net::OK, rv);
766 return disk_cache_.get(); 776 return disk_cache_.get();
767 } 777 }
768 778
769 } // namespace content 779 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_storage.h ('k') | content/common/service_worker/service_worker_status_code.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698