summaryrefslogtreecommitdiffstats
path: root/content/browser/background_sync
diff options
context:
space:
mode:
authorjkarlin <jkarlin@chromium.org>2015-08-05 07:36:47 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-05 14:39:35 +0000
commit14cdd78ff464b2dd899f014a7414d896175df0f1 (patch)
treebc436c7f7ca26bbcfbf7c17c1d89ebb1178d1d40 /content/browser/background_sync
parent4929a4fddac08397e9b6c8860520e5f43c188f38 (diff)
downloadchromium_src-14cdd78ff464b2dd899f014a7414d896175df0f1.zip
chromium_src-14cdd78ff464b2dd899f014a7414d896175df0f1.tar.gz
chromium_src-14cdd78ff464b2dd899f014a7414d896175df0f1.tar.bz2
Reland of Move BackgroundSyncManager::ErrorType to BackgroundSyncStatus
https://codereview.chromium.org/1246483002/ broke the tree due to a conflict with another CL landing at the same time. Move BackgroundSyncManager::ErrorType to BackgroundSyncStatus This needs to be in its own file to prevent dependency loop issues. And it's more of a status than an error code so renaming. TBR=iclelland@chromium.org,mvanouwerkerk@chromium.org BUG=511278 Review URL: https://codereview.chromium.org/1274573003 Cr-Commit-Position: refs/heads/master@{#341895}
Diffstat (limited to 'content/browser/background_sync')
-rw-r--r--content/browser/background_sync/background_sync_browsertest.cc5
-rw-r--r--content/browser/background_sync/background_sync_manager.cc104
-rw-r--r--content/browser/background_sync/background_sync_manager.h34
-rw-r--r--content/browser/background_sync/background_sync_manager_unittest.cc42
-rw-r--r--content/browser/background_sync/background_sync_metrics.cc16
-rw-r--r--content/browser/background_sync/background_sync_metrics.h6
-rw-r--r--content/browser/background_sync/background_sync_service_impl.cc27
-rw-r--r--content/browser/background_sync/background_sync_service_impl.h6
-rw-r--r--content/browser/background_sync/background_sync_status.h24
9 files changed, 148 insertions, 116 deletions
diff --git a/content/browser/background_sync/background_sync_browsertest.cc b/content/browser/background_sync/background_sync_browsertest.cc
index 72f37d5..ed09304 100644
--- a/content/browser/background_sync/background_sync_browsertest.cc
+++ b/content/browser/background_sync/background_sync_browsertest.cc
@@ -11,6 +11,7 @@
#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
#include "content/browser/background_sync/background_sync_manager.h"
+#include "content/browser/background_sync/background_sync_status.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/public/browser/background_sync_context.h"
@@ -58,9 +59,9 @@ void OneShotPendingCallback(
void OneShotPendingDidGetSyncRegistration(
const base::Callback<void(bool)>& callback,
- BackgroundSyncManager::ErrorType error_type,
+ BackgroundSyncStatus error_type,
const BackgroundSyncRegistration& registration) {
- ASSERT_EQ(BackgroundSyncManager::ERROR_TYPE_OK, error_type);
+ ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type);
callback.Run(registration.sync_state() == SYNC_STATE_PENDING);
}
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index 6c33d51..018bbae 100644
--- a/content/browser/background_sync/background_sync_manager.cc
+++ b/content/browser/background_sync/background_sync_manager.cc
@@ -86,10 +86,10 @@ void BackgroundSyncManager::Register(
BackgroundSyncMetrics::CountRegister(
options.periodicity, registration_could_fire,
BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
- ERROR_TYPE_STORAGE);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(callback, ERROR_TYPE_STORAGE, BackgroundSyncRegistration()));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ BackgroundSyncRegistration()));
return;
}
@@ -108,9 +108,10 @@ void BackgroundSyncManager::Unregister(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (disabled_) {
- BackgroundSyncMetrics::CountUnregister(periodicity, ERROR_TYPE_STORAGE);
+ BackgroundSyncMetrics::CountUnregister(
+ periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_STORAGE));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
return;
}
@@ -131,8 +132,8 @@ void BackgroundSyncManager::GetRegistration(
if (disabled_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(callback, ERROR_TYPE_STORAGE, BackgroundSyncRegistration()));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ BackgroundSyncRegistration()));
return;
}
@@ -152,7 +153,7 @@ void BackgroundSyncManager::GetRegistrations(
if (disabled_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_STORAGE,
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
std::vector<BackgroundSyncRegistration>()));
return;
}
@@ -313,10 +314,10 @@ void BackgroundSyncManager::RegisterImpl(
BackgroundSyncMetrics::CountRegister(
options.periodicity, registration_could_fire,
BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
- ERROR_TYPE_STORAGE);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(callback, ERROR_TYPE_STORAGE, BackgroundSyncRegistration()));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ BackgroundSyncRegistration()));
return;
}
@@ -326,16 +327,17 @@ void BackgroundSyncManager::RegisterImpl(
BackgroundSyncMetrics::CountRegister(
options.periodicity, registration_could_fire,
BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
- ERROR_TYPE_NO_SERVICE_WORKER);
+ BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_NO_SERVICE_WORKER,
- BackgroundSyncRegistration()));
+ FROM_HERE,
+ base::Bind(callback, BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER,
+ BackgroundSyncRegistration()));
return;
}
if (!sw_registration->active_version()->HasWindowClients()) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_ALLOWED,
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_NOT_ALLOWED,
BackgroundSyncRegistration()));
return;
}
@@ -357,10 +359,12 @@ void BackgroundSyncManager::RegisterImpl(
// Record the duplicated registration
BackgroundSyncMetrics::CountRegister(
existing_registration->options()->periodicity, registration_could_fire,
- BackgroundSyncMetrics::REGISTRATION_IS_DUPLICATE, ERROR_TYPE_OK);
+ BackgroundSyncMetrics::REGISTRATION_IS_DUPLICATE,
+ BACKGROUND_SYNC_STATUS_OK);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_OK, *existing_registration));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_OK,
+ *existing_registration));
return;
}
@@ -511,11 +515,11 @@ void BackgroundSyncManager::RegisterDidStore(
BackgroundSyncMetrics::CountRegister(
new_registration.options()->periodicity, registration_could_fire,
BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
- ERROR_TYPE_STORAGE);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
sw_to_registrations_map_.erase(sw_registration_id);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(callback, ERROR_TYPE_STORAGE, BackgroundSyncRegistration()));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ BackgroundSyncRegistration()));
return;
}
@@ -525,18 +529,21 @@ void BackgroundSyncManager::RegisterDidStore(
BackgroundSyncMetrics::CountRegister(
new_registration.options()->periodicity, registration_could_fire,
BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
- ERROR_TYPE_STORAGE);
- DisableAndClearManager(
- base::Bind(callback, ERROR_TYPE_STORAGE, BackgroundSyncRegistration()));
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
+ DisableAndClearManager(base::Bind(callback,
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ BackgroundSyncRegistration()));
return;
}
BackgroundSyncMetrics::CountRegister(
new_registration.options()->periodicity, registration_could_fire,
- BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, ERROR_TYPE_OK);
+ BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
+ BACKGROUND_SYNC_STATUS_OK);
FireReadyEvents();
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_OK, new_registration));
+ FROM_HERE,
+ base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, new_registration));
}
void BackgroundSyncManager::RemoveRegistrationFromMap(
@@ -607,9 +614,10 @@ void BackgroundSyncManager::UnregisterImpl(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (disabled_) {
- BackgroundSyncMetrics::CountUnregister(periodicity, ERROR_TYPE_STORAGE);
+ BackgroundSyncMetrics::CountUnregister(
+ periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_STORAGE));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
return;
}
@@ -617,9 +625,10 @@ void BackgroundSyncManager::UnregisterImpl(
LookupRegistration(sw_registration_id, registration_key);
if (!existing_registration ||
existing_registration->id() != sync_registration_id) {
- BackgroundSyncMetrics::CountUnregister(periodicity, ERROR_TYPE_NOT_FOUND);
+ BackgroundSyncMetrics::CountUnregister(periodicity,
+ BACKGROUND_SYNC_STATUS_NOT_FOUND);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_FOUND));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_NOT_FOUND));
return;
}
@@ -639,23 +648,27 @@ void BackgroundSyncManager::UnregisterDidStore(int64 sw_registration_id,
if (status == SERVICE_WORKER_ERROR_NOT_FOUND) {
// ServiceWorker was unregistered.
- BackgroundSyncMetrics::CountUnregister(periodicity, ERROR_TYPE_STORAGE);
+ BackgroundSyncMetrics::CountUnregister(
+ periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
sw_to_registrations_map_.erase(sw_registration_id);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_STORAGE));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
return;
}
if (status != SERVICE_WORKER_OK) {
LOG(ERROR) << "BackgroundSync failed to unregister due to backend failure.";
- BackgroundSyncMetrics::CountUnregister(periodicity, ERROR_TYPE_STORAGE);
- DisableAndClearManager(base::Bind(callback, ERROR_TYPE_STORAGE));
+ BackgroundSyncMetrics::CountUnregister(
+ periodicity, BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
+ DisableAndClearManager(
+ base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR));
return;
}
- BackgroundSyncMetrics::CountUnregister(periodicity, ERROR_TYPE_OK);
+ BackgroundSyncMetrics::CountUnregister(periodicity,
+ BACKGROUND_SYNC_STATUS_OK);
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_OK));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_OK));
}
void BackgroundSyncManager::GetRegistrationImpl(
@@ -666,8 +679,8 @@ void BackgroundSyncManager::GetRegistrationImpl(
if (disabled_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE,
- base::Bind(callback, ERROR_TYPE_STORAGE, BackgroundSyncRegistration()));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ BackgroundSyncRegistration()));
return;
}
@@ -675,13 +688,14 @@ void BackgroundSyncManager::GetRegistrationImpl(
LookupRegistration(sw_registration_id, registration_key);
if (!out_registration) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_FOUND,
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_NOT_FOUND,
BackgroundSyncRegistration()));
return;
}
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_OK, *out_registration));
+ FROM_HERE,
+ base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, *out_registration));
}
void BackgroundSyncManager::GetRegistrationsImpl(
@@ -694,7 +708,8 @@ void BackgroundSyncManager::GetRegistrationsImpl(
if (disabled_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_STORAGE, out_registrations));
+ FROM_HERE, base::Bind(callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ out_registrations));
return;
}
@@ -712,7 +727,8 @@ void BackgroundSyncManager::GetRegistrationsImpl(
}
base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_OK, out_registrations));
+ FROM_HERE,
+ base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, out_registrations));
}
bool BackgroundSyncManager::AreOptionConditionsMet(
@@ -1037,7 +1053,7 @@ BackgroundSyncManager::MakeStatusAndRegistrationCompletion(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
return base::Bind(&BackgroundSyncManager::CompleteOperationCallback<
- StatusAndRegistrationCallback, ErrorType,
+ StatusAndRegistrationCallback, BackgroundSyncStatus,
const BackgroundSyncRegistration&>,
weak_ptr_factory_.GetWeakPtr(), callback);
}
@@ -1048,7 +1064,7 @@ BackgroundSyncManager::MakeStatusAndRegistrationsCompletion(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
return base::Bind(&BackgroundSyncManager::CompleteOperationCallback<
- StatusAndRegistrationsCallback, ErrorType,
+ StatusAndRegistrationsCallback, BackgroundSyncStatus,
const std::vector<BackgroundSyncRegistration>&>,
weak_ptr_factory_.GetWeakPtr(), callback);
}
@@ -1059,7 +1075,7 @@ BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) {
return base::Bind(
&BackgroundSyncManager::CompleteOperationCallback<StatusCallback,
- ErrorType>,
+ BackgroundSyncStatus>,
weak_ptr_factory_.GetWeakPtr(), callback);
}
diff --git a/content/browser/background_sync/background_sync_manager.h b/content/browser/background_sync/background_sync_manager.h
index 49f2c92..84353f9 100644
--- a/content/browser/background_sync/background_sync_manager.h
+++ b/content/browser/background_sync/background_sync_manager.h
@@ -6,6 +6,8 @@
#define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_MANAGER_H_
#include <map>
+#include <string>
+#include <utility>
#include <vector>
#include "base/callback_forward.h"
@@ -13,6 +15,7 @@
#include "base/memory/weak_ptr.h"
#include "content/browser/background_sync/background_sync.pb.h"
#include "content/browser/background_sync/background_sync_registration.h"
+#include "content/browser/background_sync/background_sync_status.h"
#include "content/browser/cache_storage/cache_storage_scheduler.h"
#include "content/browser/service_worker/service_worker_context_observer.h"
#include "content/browser/service_worker/service_worker_storage.h"
@@ -44,20 +47,12 @@ class ServiceWorkerContextWrapper;
class CONTENT_EXPORT BackgroundSyncManager
: NON_EXPORTED_BASE(public ServiceWorkerContextObserver) {
public:
- enum ErrorType {
- ERROR_TYPE_OK = 0,
- ERROR_TYPE_STORAGE,
- ERROR_TYPE_NOT_FOUND,
- ERROR_TYPE_NO_SERVICE_WORKER,
- ERROR_TYPE_NOT_ALLOWED,
- ERROR_TYPE_MAX = ERROR_TYPE_NOT_ALLOWED
- };
-
- using StatusCallback = base::Callback<void(ErrorType)>;
+ using StatusCallback = base::Callback<void(BackgroundSyncStatus)>;
using StatusAndRegistrationCallback =
- base::Callback<void(ErrorType, const BackgroundSyncRegistration&)>;
+ base::Callback<void(BackgroundSyncStatus,
+ const BackgroundSyncRegistration&)>;
using StatusAndRegistrationsCallback =
- base::Callback<void(ErrorType,
+ base::Callback<void(BackgroundSyncStatus,
const std::vector<BackgroundSyncRegistration>&)>;
static scoped_ptr<BackgroundSyncManager> Create(
@@ -67,17 +62,18 @@ class CONTENT_EXPORT BackgroundSyncManager
// Stores the given background sync registration and adds it to the scheduling
// queue. It will overwrite an existing registration with the same tag and
// periodicity unless they're identical (save for the id). Calls |callback|
- // with ErrorTypeOK and the accepted registration on success. The accepted
- // registration will have a unique id. It may also have altered parameters if
- // the user or UA chose different parameters than those supplied.
+ // with BACKGROUND_SYNC_STATUS_OK and the accepted registration on success.
+ // The accepted registration will have a unique id. It may also have altered
+ // parameters if the user or UA chose different parameters than those
+ // supplied.
void Register(int64 sw_registration_id,
const BackgroundSyncRegistrationOptions& options,
const StatusAndRegistrationCallback& callback);
// Removes the background sync with tag |sync_registration_tag|, periodicity
// |periodicity|, and id |sync_registration_id|. Calls |callback| with
- // ErrorTypeNotFound if no match is found. Calls |callback| with ErrorTypeOK
- // on success.
+ // BACKGROUND_SYNC_STATUS_NOT_FOUND if no match is found. Calls |callback|
+ // with BACKGROUND_SYNC_STATUS_OK on success.
void Unregister(
int64 sw_registration_id,
const std::string& sync_registration_tag,
@@ -87,8 +83,8 @@ class CONTENT_EXPORT BackgroundSyncManager
// Finds the background sync registration associated with
// |sw_registration_id| with periodicity |periodicity|. Calls
- // |callback| with ErrorTypeNotFound if it doesn't exist. Calls |callback|
- // with ErrorTypeOK on success.
+ // |callback| with BACKGROUND_SYNC_STATUS_NOT_FOUND if it doesn't exist. Calls
+ // |callback| with BACKGROUND_SYNC_STATUS_OK on success.
void GetRegistration(int64 sw_registration_id,
const std::string& sync_registration_tag,
SyncPeriodicity periodicity,
diff --git a/content/browser/background_sync/background_sync_manager_unittest.cc b/content/browser/background_sync/background_sync_manager_unittest.cc
index 362238b..e80881c 100644
--- a/content/browser/background_sync/background_sync_manager_unittest.cc
+++ b/content/browser/background_sync/background_sync_manager_unittest.cc
@@ -12,6 +12,7 @@
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
+#include "content/browser/background_sync/background_sync_status.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/service_worker_context_core.h"
@@ -207,7 +208,7 @@ class BackgroundSyncManagerTest : public testing::Test {
: browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
network_change_notifier_(net::NetworkChangeNotifier::CreateMock()),
test_background_sync_manager_(nullptr),
- callback_error_(BackgroundSyncManager::ERROR_TYPE_OK),
+ callback_status_(BACKGROUND_SYNC_STATUS_OK),
callback_sw_status_code_(SERVICE_WORKER_OK),
sync_events_called_(0) {
sync_options_1_.tag = "foo";
@@ -303,26 +304,25 @@ class BackgroundSyncManagerTest : public testing::Test {
void StatusAndRegistrationCallback(
bool* was_called,
- BackgroundSyncManager::ErrorType error,
+ BackgroundSyncStatus status,
const BackgroundSyncRegistration& registration) {
*was_called = true;
- callback_error_ = error;
+ callback_status_ = status;
callback_registration_ = registration;
}
void StatusAndRegistrationsCallback(
bool* was_called,
- BackgroundSyncManager::ErrorType error,
+ BackgroundSyncStatus status,
const std::vector<BackgroundSyncRegistration>& registrations) {
*was_called = true;
- callback_error_ = error;
+ callback_status_ = status;
callback_registrations_ = registrations;
}
- void StatusCallback(bool* was_called,
- BackgroundSyncManager::ErrorType error) {
+ void StatusCallback(bool* was_called, BackgroundSyncStatus status) {
*was_called = true;
- callback_error_ = error;
+ callback_status_ = status;
}
protected:
@@ -379,7 +379,7 @@ class BackgroundSyncManagerTest : public testing::Test {
base::Unretained(this), &was_called));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(was_called);
- return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
+ return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
}
bool Unregister(const BackgroundSyncRegistration& sync_registration) {
@@ -398,7 +398,7 @@ class BackgroundSyncManagerTest : public testing::Test {
base::Unretained(this), &was_called));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(was_called);
- return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
+ return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
}
bool GetRegistration(const BackgroundSyncRegistrationOptions& sync_options) {
@@ -417,12 +417,12 @@ class BackgroundSyncManagerTest : public testing::Test {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(was_called);
- if (callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK) {
+ if (callback_status_ == BACKGROUND_SYNC_STATUS_OK) {
EXPECT_STREQ(sync_options.tag.c_str(),
callback_registration_.options()->tag.c_str());
}
- return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
+ return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
}
bool GetRegistrations(SyncPeriodicity periodicity) {
@@ -440,7 +440,7 @@ class BackgroundSyncManagerTest : public testing::Test {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(was_called);
- return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK;
+ return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
}
void StorageRegistrationCallback(ServiceWorkerStatusCode result) {
@@ -513,7 +513,7 @@ class BackgroundSyncManagerTest : public testing::Test {
BackgroundSyncRegistrationOptions sync_options_2_;
// Callback values.
- BackgroundSyncManager::ErrorType callback_error_;
+ BackgroundSyncStatus callback_status_;
BackgroundSyncRegistration callback_registration_;
std::vector<BackgroundSyncRegistration> callback_registrations_;
ServiceWorkerStatusCode callback_sw_status_code_;
@@ -535,15 +535,13 @@ TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) {
sw_registration_1_ = nullptr;
EXPECT_FALSE(Register(sync_options_1_));
- EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_NO_SERVICE_WORKER,
- callback_error_);
+ EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
}
TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {
sw_registration_1_->UnsetVersion(sw_registration_1_->active_version());
EXPECT_FALSE(Register(sync_options_1_));
- EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_NO_SERVICE_WORKER,
- callback_error_);
+ EXPECT_EQ(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback_status_);
}
TEST_F(BackgroundSyncManagerTest, RegisterExistingKeepsId) {
@@ -688,7 +686,7 @@ TEST_F(BackgroundSyncManagerTest, UnregisterNonExisting) {
BackgroundSyncRegistration nonexistant_registration;
nonexistant_registration.set_id(1);
EXPECT_FALSE(Unregister(nonexistant_registration));
- EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_NOT_FOUND, callback_error_);
+ EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback_status_);
}
TEST_F(BackgroundSyncManagerTest, UnregisterSecond) {
@@ -813,7 +811,7 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(register_called);
EXPECT_EQ(kExpectedInitialId, callback_registration_.id());
- EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_OK, callback_error_);
+ EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_status_);
// Unregister should be blocked while storing to the backend.
EXPECT_FALSE(unregister_called);
EXPECT_FALSE(get_registration_called);
@@ -822,7 +820,7 @@ TEST_F(BackgroundSyncManagerTest, SequentialOperations) {
base::RunLoop().RunUntilIdle();
// Unregister should be done and since GetRegistration doesn't require the
// backend it should be done too.
- EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_NOT_FOUND, callback_error_);
+ EXPECT_EQ(BACKGROUND_SYNC_STATUS_NOT_FOUND, callback_status_);
EXPECT_TRUE(unregister_called);
EXPECT_TRUE(get_registration_called);
}
@@ -851,7 +849,7 @@ TEST_F(BackgroundSyncManagerTest,
test_background_sync_manager_->Continue();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_called);
- EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_STORAGE, callback_error_);
+ EXPECT_EQ(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback_status_);
test_background_sync_manager_->set_delay_backend(false);
EXPECT_FALSE(GetRegistration(sync_options_1_));
diff --git a/content/browser/background_sync/background_sync_metrics.cc b/content/browser/background_sync/background_sync_metrics.cc
index 7701798..d52bf03 100644
--- a/content/browser/background_sync/background_sync_metrics.cc
+++ b/content/browser/background_sync/background_sync_metrics.cc
@@ -38,11 +38,11 @@ void BackgroundSyncMetrics::CountRegister(
SyncPeriodicity periodicity,
RegistrationCouldFire registration_could_fire,
RegistrationIsDuplicate registration_is_duplicate,
- BackgroundSyncManager::ErrorType result) {
+ BackgroundSyncStatus result) {
switch (periodicity) {
case SYNC_ONE_SHOT:
UMA_HISTOGRAM_ENUMERATION("BackgroundSync.Registration.OneShot", result,
- BackgroundSyncManager::ERROR_TYPE_MAX + 1);
+ BACKGROUND_SYNC_STATUS_MAX + 1);
UMA_HISTOGRAM_BOOLEAN("BackgroundSync.Registration.OneShot.CouldFire",
registration_could_fire == REGISTRATION_COULD_FIRE);
UMA_HISTOGRAM_BOOLEAN(
@@ -51,7 +51,7 @@ void BackgroundSyncMetrics::CountRegister(
return;
case SYNC_PERIODIC:
UMA_HISTOGRAM_ENUMERATION("BackgroundSync.Registration.Periodic", result,
- BackgroundSyncManager::ERROR_TYPE_MAX + 1);
+ BACKGROUND_SYNC_STATUS_MAX + 1);
UMA_HISTOGRAM_BOOLEAN(
"BackgroundSync.Registration.Periodic.IsDuplicate",
registration_is_duplicate == REGISTRATION_IS_DUPLICATE);
@@ -60,18 +60,16 @@ void BackgroundSyncMetrics::CountRegister(
NOTREACHED();
}
-void BackgroundSyncMetrics::CountUnregister(
- SyncPeriodicity periodicity,
- BackgroundSyncManager::ErrorType result) {
+void BackgroundSyncMetrics::CountUnregister(SyncPeriodicity periodicity,
+ BackgroundSyncStatus result) {
switch (periodicity) {
case SYNC_ONE_SHOT:
UMA_HISTOGRAM_ENUMERATION("BackgroundSync.Unregistration.OneShot", result,
- BackgroundSyncManager::ERROR_TYPE_MAX + 1);
+ BACKGROUND_SYNC_STATUS_MAX + 1);
return;
case SYNC_PERIODIC:
UMA_HISTOGRAM_ENUMERATION("BackgroundSync.Unregistration.Periodic",
- result,
- BackgroundSyncManager::ERROR_TYPE_MAX + 1);
+ result, BACKGROUND_SYNC_STATUS_MAX + 1);
return;
}
NOTREACHED();
diff --git a/content/browser/background_sync/background_sync_metrics.h b/content/browser/background_sync/background_sync_metrics.h
index 290d9f9..d8c26da 100644
--- a/content/browser/background_sync/background_sync_metrics.h
+++ b/content/browser/background_sync/background_sync_metrics.h
@@ -8,7 +8,7 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "content/browser/background_sync/background_sync.pb.h"
-#include "content/browser/background_sync/background_sync_manager.h"
+#include "content/browser/background_sync/background_sync_status.h"
namespace content {
@@ -42,11 +42,11 @@ class BackgroundSyncMetrics {
static void CountRegister(SyncPeriodicity periodicity,
RegistrationCouldFire could_fire,
RegistrationIsDuplicate registration_is_duplicate,
- BackgroundSyncManager::ErrorType result);
+ BackgroundSyncStatus result);
// Records the result of trying to unregister a sync.
static void CountUnregister(SyncPeriodicity periodicity,
- BackgroundSyncManager::ErrorType result);
+ BackgroundSyncStatus result);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BackgroundSyncMetrics);
diff --git a/content/browser/background_sync/background_sync_service_impl.cc b/content/browser/background_sync/background_sync_service_impl.cc
index 2aac6c0..0fb81a4 100644
--- a/content/browser/background_sync/background_sync_service_impl.cc
+++ b/content/browser/background_sync/background_sync_service_impl.cc
@@ -51,18 +51,17 @@ SyncRegistrationPtr ToMojoRegistration(const BackgroundSyncRegistration& in) {
// TODO(iclelland): Move these tests somewhere else
COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NONE,
- BackgroundSyncManager::ERROR_TYPE_OK);
+ BACKGROUND_SYNC_STATUS_OK);
COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_STORAGE,
- BackgroundSyncManager::ERROR_TYPE_STORAGE);
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NOT_FOUND,
- BackgroundSyncManager::ERROR_TYPE_NOT_FOUND);
-COMPILE_ASSERT_MATCHING_ENUM(
- BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER,
- BackgroundSyncManager::ERROR_TYPE_NO_SERVICE_WORKER);
+ BACKGROUND_SYNC_STATUS_NOT_FOUND);
+COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER,
+ BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER);
COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_NOT_ALLOWED,
- BackgroundSyncManager::ERROR_TYPE_NOT_ALLOWED);
+ BACKGROUND_SYNC_STATUS_NOT_ALLOWED);
COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_ERROR_MAX,
- BackgroundSyncManager::ERROR_TYPE_NOT_ALLOWED);
+ BACKGROUND_SYNC_STATUS_NOT_ALLOWED);
COMPILE_ASSERT_MATCHING_ENUM(BACKGROUND_SYNC_NETWORK_STATE_ANY,
SyncNetworkState::NETWORK_STATE_ANY);
@@ -197,30 +196,30 @@ void BackgroundSyncServiceImpl::GetPermissionStatus(
void BackgroundSyncServiceImpl::OnRegisterResult(
const RegisterCallback& callback,
- BackgroundSyncManager::ErrorType error,
+ BackgroundSyncStatus status,
const BackgroundSyncRegistration& result) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
SyncRegistrationPtr mojoResult = ToMojoRegistration(result);
- callback.Run(static_cast<content::BackgroundSyncError>(error),
+ callback.Run(static_cast<content::BackgroundSyncError>(status),
mojoResult.Pass());
}
void BackgroundSyncServiceImpl::OnUnregisterResult(
const UnregisterCallback& callback,
- BackgroundSyncManager::ErrorType error) {
+ BackgroundSyncStatus status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- callback.Run(static_cast<content::BackgroundSyncError>(error));
+ callback.Run(static_cast<content::BackgroundSyncError>(status));
}
void BackgroundSyncServiceImpl::OnGetRegistrationsResult(
const GetRegistrationsCallback& callback,
- BackgroundSyncManager::ErrorType error,
+ BackgroundSyncStatus status,
const std::vector<BackgroundSyncRegistration>& result_registrations) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
mojo::Array<content::SyncRegistrationPtr> mojo_registrations(0);
for (const auto& registration : result_registrations)
mojo_registrations.push_back(ToMojoRegistration(registration));
- callback.Run(static_cast<content::BackgroundSyncError>(error),
+ callback.Run(static_cast<content::BackgroundSyncError>(status),
mojo_registrations.Pass());
}
diff --git a/content/browser/background_sync/background_sync_service_impl.h b/content/browser/background_sync/background_sync_service_impl.h
index 8a28714..6d23ea0 100644
--- a/content/browser/background_sync/background_sync_service_impl.h
+++ b/content/browser/background_sync/background_sync_service_impl.h
@@ -58,13 +58,13 @@ class CONTENT_EXPORT BackgroundSyncServiceImpl
const GetPermissionStatusCallback& callback) override;
void OnRegisterResult(const RegisterCallback& callback,
- BackgroundSyncManager::ErrorType error,
+ BackgroundSyncStatus status,
const BackgroundSyncRegistration& result);
void OnUnregisterResult(const UnregisterCallback& callback,
- BackgroundSyncManager::ErrorType error);
+ BackgroundSyncStatus status);
void OnGetRegistrationsResult(
const GetRegistrationsCallback& callback,
- BackgroundSyncManager::ErrorType error,
+ BackgroundSyncStatus status,
const std::vector<BackgroundSyncRegistration>& result);
scoped_refptr<BackgroundSyncContextImpl> background_sync_context_;
diff --git a/content/browser/background_sync/background_sync_status.h b/content/browser/background_sync/background_sync_status.h
new file mode 100644
index 0000000..3faee99
--- /dev/null
+++ b/content/browser/background_sync/background_sync_status.h
@@ -0,0 +1,24 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_STATUS_H_
+#define CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_STATUS_H_
+
+namespace content {
+
+// The status of BackgroundSyncManager actions. These are recorded in histograms
+// (as BackgroundSyncResult) so don't remove any entries and always append to
+// the end.
+enum BackgroundSyncStatus {
+ BACKGROUND_SYNC_STATUS_OK = 0,
+ BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
+ BACKGROUND_SYNC_STATUS_NOT_FOUND,
+ BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER,
+ BACKGROUND_SYNC_STATUS_NOT_ALLOWED,
+ BACKGROUND_SYNC_STATUS_MAX = BACKGROUND_SYNC_STATUS_NOT_ALLOWED
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_BACKGROUND_SYNC_BACKGROUND_SYNC_STATUS_H_