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

Side by Side Diff: content/browser/background_sync/background_sync_manager.cc

Issue 1376533002: [BackgroundSync] Add ability to disable Background Sync via Field Trial (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 5 years, 2 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
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/browser/background_sync/background_sync_manager.h" 5 #include "content/browser/background_sync/background_sync_manager.h"
6 6
7 #include "base/barrier_closure.h" 7 #include "base/barrier_closure.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/metrics/field_trial.h"
10 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
12 #include "content/browser/background_sync/background_sync_metrics.h" 13 #include "content/browser/background_sync/background_sync_metrics.h"
13 #include "content/browser/background_sync/background_sync_network_observer.h" 14 #include "content/browser/background_sync/background_sync_network_observer.h"
14 #include "content/browser/background_sync/background_sync_power_observer.h" 15 #include "content/browser/background_sync/background_sync_power_observer.h"
15 #include "content/browser/background_sync/background_sync_registration_handle.h" 16 #include "content/browser/background_sync/background_sync_registration_handle.h"
16 #include "content/browser/background_sync/background_sync_registration_options.h " 17 #include "content/browser/background_sync/background_sync_registration_options.h "
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" 18 #include "content/browser/service_worker/service_worker_context_wrapper.h"
18 #include "content/browser/service_worker/service_worker_storage.h" 19 #include "content/browser/service_worker/service_worker_storage.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
(...skipping 24 matching lines...) Expand all
44 void PostErrorResponse( 45 void PostErrorResponse(
45 BackgroundSyncStatus status, 46 BackgroundSyncStatus status,
46 const BackgroundSyncManager::StatusAndRegistrationCallback& callback) { 47 const BackgroundSyncManager::StatusAndRegistrationCallback& callback) {
47 base::ThreadTaskRunnerHandle::Get()->PostTask( 48 base::ThreadTaskRunnerHandle::Get()->PostTask(
48 FROM_HERE, 49 FROM_HERE,
49 base::Bind( 50 base::Bind(
50 callback, status, 51 callback, status,
51 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>().Pass()))); 52 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>().Pass())));
52 } 53 }
53 54
55 bool ShouldDisableForFieldTrial() {
56 std::string experiment = base::FieldTrialList::FindFullName("BackgroundSync");
57 return base::StartsWith(experiment, "ExperimentDisable",
58 base::CompareCase::INSENSITIVE_ASCII);
59 }
60
54 } // namespace 61 } // namespace
55 62
56 BackgroundSyncManager::BackgroundSyncRegistrations:: 63 BackgroundSyncManager::BackgroundSyncRegistrations::
57 BackgroundSyncRegistrations() 64 BackgroundSyncRegistrations()
58 : next_id(BackgroundSyncRegistration::kInitialId) { 65 : next_id(BackgroundSyncRegistration::kInitialId) {
59 } 66 }
60 67
61 BackgroundSyncManager::BackgroundSyncRegistrations:: 68 BackgroundSyncManager::BackgroundSyncRegistrations::
62 ~BackgroundSyncRegistrations() { 69 ~BackgroundSyncRegistrations() {
63 } 70 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 239
233 void BackgroundSyncManager::InitImpl(const base::Closure& callback) { 240 void BackgroundSyncManager::InitImpl(const base::Closure& callback) {
234 DCHECK_CURRENTLY_ON(BrowserThread::IO); 241 DCHECK_CURRENTLY_ON(BrowserThread::IO);
235 242
236 if (disabled_) { 243 if (disabled_) {
237 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 244 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
238 base::Bind(callback)); 245 base::Bind(callback));
239 return; 246 return;
240 } 247 }
241 248
249 if (ShouldDisableForFieldTrial()) {
250 DisableAndClearManager(callback);
251 return;
252 }
253
242 GetDataFromBackend( 254 GetDataFromBackend(
243 kBackgroundSyncUserDataKey, 255 kBackgroundSyncUserDataKey,
244 base::Bind(&BackgroundSyncManager::InitDidGetDataFromBackend, 256 base::Bind(&BackgroundSyncManager::InitDidGetDataFromBackend,
245 weak_ptr_factory_.GetWeakPtr(), callback)); 257 weak_ptr_factory_.GetWeakPtr(), callback));
246 } 258 }
247 259
248 void BackgroundSyncManager::InitDidGetDataFromBackend( 260 void BackgroundSyncManager::InitDidGetDataFromBackend(
249 const base::Closure& callback, 261 const base::Closure& callback,
250 const std::vector<std::pair<int64, std::string>>& user_data, 262 const std::vector<std::pair<int64, std::string>>& user_data,
251 ServiceWorkerStatusCode status) { 263 ServiceWorkerStatusCode status) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 338
327 if (disabled_) { 339 if (disabled_) {
328 BackgroundSyncMetrics::CountRegister( 340 BackgroundSyncMetrics::CountRegister(
329 options.periodicity, registration_could_fire, 341 options.periodicity, registration_could_fire,
330 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, 342 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
331 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); 343 BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
332 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback); 344 PostErrorResponse(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback);
333 return; 345 return;
334 } 346 }
335 347
348 if (ShouldDisableForFieldTrial()) {
349 DisableAndClearManager(base::Bind(
350 callback, BACKGROUND_SYNC_STATUS_STORAGE_ERROR,
351 base::Passed(scoped_ptr<BackgroundSyncRegistrationHandle>().Pass())));
352 return;
353 }
354
336 if (options.tag.length() > kMaxTagLength) { 355 if (options.tag.length() > kMaxTagLength) {
337 BackgroundSyncMetrics::CountRegister( 356 BackgroundSyncMetrics::CountRegister(
338 options.periodicity, registration_could_fire, 357 options.periodicity, registration_could_fire,
339 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE, 358 BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
340 BACKGROUND_SYNC_STATUS_NOT_ALLOWED); 359 BACKGROUND_SYNC_STATUS_NOT_ALLOWED);
341 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback); 360 PostErrorResponse(BACKGROUND_SYNC_STATUS_NOT_ALLOWED, callback);
342 return; 361 return;
343 } 362 }
344 363
345 ServiceWorkerRegistration* sw_registration = 364 ServiceWorkerRegistration* sw_registration =
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { 1291 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) {
1273 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1292 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1274 1293
1275 return base::Bind( 1294 return base::Bind(
1276 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, 1295 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback,
1277 BackgroundSyncStatus>, 1296 BackgroundSyncStatus>,
1278 weak_ptr_factory_.GetWeakPtr(), callback); 1297 weak_ptr_factory_.GetWeakPtr(), callback);
1279 } 1298 }
1280 1299
1281 } // namespace content 1300 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698