| 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 "chrome/browser/background_sync/background_sync_controller_impl.h" | 5 #include "chrome/browser/background_sync/background_sync_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/features.h" | 11 #include "chrome/common/features.h" |
| 12 #include "components/rappor/rappor_utils.h" | 12 #include "components/rappor/rappor_utils.h" |
| 13 #include "components/variations/variations_associated_data.h" | 13 #include "components/variations/variations_associated_data.h" |
| 14 #include "content/public/browser/background_sync_parameters.h" | 14 #include "content/public/browser/background_sync_parameters.h" |
| 15 | 15 |
| 16 #if BUILDFLAG(ANDROID_JAVA_UI) | 16 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 17 #include "chrome/browser/android/background_sync_launcher_android.h" | 17 #include "chrome/browser/android/background_sync_launcher_android.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 const char BackgroundSyncControllerImpl::kFieldTrialName[] = "BackgroundSync"; | 21 const char BackgroundSyncControllerImpl::kFieldTrialName[] = "BackgroundSync"; |
| 22 const char BackgroundSyncControllerImpl::kDisabledParameterName[] = "disabled"; | 22 const char BackgroundSyncControllerImpl::kDisabledParameterName[] = "disabled"; |
| 23 const char BackgroundSyncControllerImpl::kMaxAttemptsParameterName[] = | 23 const char BackgroundSyncControllerImpl::kMaxAttemptsParameterName[] = |
| 24 "max_sync_attempts"; | 24 "max_sync_attempts"; |
| 25 const char BackgroundSyncControllerImpl::kInitialRetryParameterName[] = | 25 const char BackgroundSyncControllerImpl::kInitialRetryParameterName[] = |
| 26 "initial_retry_delay_mins"; | 26 "initial_retry_delay_sec"; |
| 27 const char BackgroundSyncControllerImpl::kRetryDelayFactorParameterName[] = | 27 const char BackgroundSyncControllerImpl::kRetryDelayFactorParameterName[] = |
| 28 "retry_delay_factor"; | 28 "retry_delay_factor"; |
| 29 const char BackgroundSyncControllerImpl::kMinSyncRecoveryTimeName[] = | 29 const char BackgroundSyncControllerImpl::kMinSyncRecoveryTimeName[] = |
| 30 "min_recovery_time_ms"; | 30 "min_recovery_time_sec"; |
| 31 const char BackgroundSyncControllerImpl::kMaxSyncEventDurationName[] = |
| 32 "max_sync_event_duration_sec"; |
| 31 | 33 |
| 32 BackgroundSyncControllerImpl::BackgroundSyncControllerImpl(Profile* profile) | 34 BackgroundSyncControllerImpl::BackgroundSyncControllerImpl(Profile* profile) |
| 33 : profile_(profile) {} | 35 : profile_(profile) {} |
| 34 | 36 |
| 35 BackgroundSyncControllerImpl::~BackgroundSyncControllerImpl() = default; | 37 BackgroundSyncControllerImpl::~BackgroundSyncControllerImpl() = default; |
| 36 | 38 |
| 37 void BackgroundSyncControllerImpl::GetParameterOverrides( | 39 void BackgroundSyncControllerImpl::GetParameterOverrides( |
| 38 content::BackgroundSyncParameters* parameters) const { | 40 content::BackgroundSyncParameters* parameters) const { |
| 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 40 | 42 |
| 41 std::map<std::string, std::string> field_params; | 43 std::map<std::string, std::string> field_params; |
| 42 if (!variations::GetVariationParams(kFieldTrialName, &field_params)) | 44 if (!variations::GetVariationParams(kFieldTrialName, &field_params)) |
| 43 return; | 45 return; |
| 44 | 46 |
| 45 if (base::LowerCaseEqualsASCII(field_params[kDisabledParameterName], | 47 if (base::LowerCaseEqualsASCII(field_params[kDisabledParameterName], |
| 46 "true")) { | 48 "true")) { |
| 47 parameters->disable = true; | 49 parameters->disable = true; |
| 48 } | 50 } |
| 49 | 51 |
| 50 if (ContainsKey(field_params, kMaxAttemptsParameterName)) { | 52 if (ContainsKey(field_params, kMaxAttemptsParameterName)) { |
| 51 int max_attempts; | 53 int max_attempts; |
| 52 if (base::StringToInt(field_params[kMaxAttemptsParameterName], | 54 if (base::StringToInt(field_params[kMaxAttemptsParameterName], |
| 53 &max_attempts)) { | 55 &max_attempts)) { |
| 54 parameters->max_sync_attempts = max_attempts; | 56 parameters->max_sync_attempts = max_attempts; |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 | 59 |
| 58 if (ContainsKey(field_params, kInitialRetryParameterName)) { | 60 if (ContainsKey(field_params, kInitialRetryParameterName)) { |
| 59 int initial_retry_delay_min; | 61 int initial_retry_delay_sec; |
| 60 if (base::StringToInt(field_params[kInitialRetryParameterName], | 62 if (base::StringToInt(field_params[kInitialRetryParameterName], |
| 61 &initial_retry_delay_min)) { | 63 &initial_retry_delay_sec)) { |
| 62 parameters->initial_retry_delay = | 64 parameters->initial_retry_delay = |
| 63 base::TimeDelta::FromMinutes(initial_retry_delay_min); | 65 base::TimeDelta::FromSeconds(initial_retry_delay_sec); |
| 64 } | 66 } |
| 65 } | 67 } |
| 66 | 68 |
| 67 if (ContainsKey(field_params, kRetryDelayFactorParameterName)) { | 69 if (ContainsKey(field_params, kRetryDelayFactorParameterName)) { |
| 68 int retry_delay_factor; | 70 int retry_delay_factor; |
| 69 if (base::StringToInt(field_params[kRetryDelayFactorParameterName], | 71 if (base::StringToInt(field_params[kRetryDelayFactorParameterName], |
| 70 &retry_delay_factor)) { | 72 &retry_delay_factor)) { |
| 71 parameters->retry_delay_factor = retry_delay_factor; | 73 parameters->retry_delay_factor = retry_delay_factor; |
| 72 } | 74 } |
| 73 } | 75 } |
| 74 | 76 |
| 75 if (ContainsKey(field_params, kMinSyncRecoveryTimeName)) { | 77 if (ContainsKey(field_params, kMinSyncRecoveryTimeName)) { |
| 76 int64_t min_sync_recovery_time_ms; | 78 int min_sync_recovery_time_sec; |
| 77 if (base::StringToInt64(field_params[kMinSyncRecoveryTimeName], | 79 if (base::StringToInt(field_params[kMinSyncRecoveryTimeName], |
| 78 &min_sync_recovery_time_ms)) { | 80 &min_sync_recovery_time_sec)) { |
| 79 parameters->min_sync_recovery_time = | 81 parameters->min_sync_recovery_time = |
| 80 base::TimeDelta::FromMilliseconds(min_sync_recovery_time_ms); | 82 base::TimeDelta::FromSeconds(min_sync_recovery_time_sec); |
| 81 } | 83 } |
| 82 } | 84 } |
| 83 | 85 |
| 86 if (ContainsKey(field_params, kMaxSyncEventDurationName)) { |
| 87 int max_sync_event_duration_sec; |
| 88 if (base::StringToInt(field_params[kMaxSyncEventDurationName], |
| 89 &max_sync_event_duration_sec)) { |
| 90 parameters->max_sync_event_duration = |
| 91 base::TimeDelta::FromSeconds(max_sync_event_duration_sec); |
| 92 } |
| 93 } |
| 94 |
| 84 return; | 95 return; |
| 85 } | 96 } |
| 86 | 97 |
| 87 void BackgroundSyncControllerImpl::NotifyBackgroundSyncRegistered( | 98 void BackgroundSyncControllerImpl::NotifyBackgroundSyncRegistered( |
| 88 const GURL& origin) { | 99 const GURL& origin) { |
| 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 90 DCHECK_EQ(origin, origin.GetOrigin()); | 101 DCHECK_EQ(origin, origin.GetOrigin()); |
| 91 | 102 |
| 92 if (profile_->IsOffTheRecord()) | 103 if (profile_->IsOffTheRecord()) |
| 93 return; | 104 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 BackgroundSyncLauncherAndroid::LaunchBrowserIfStopped(enabled, min_ms); | 117 BackgroundSyncLauncherAndroid::LaunchBrowserIfStopped(enabled, min_ms); |
| 107 #else | 118 #else |
| 108 // TODO(jkarlin): Use BackgroundModeManager to enter background mode. See | 119 // TODO(jkarlin): Use BackgroundModeManager to enter background mode. See |
| 109 // https://crbug.com/484201. | 120 // https://crbug.com/484201. |
| 110 #endif | 121 #endif |
| 111 } | 122 } |
| 112 | 123 |
| 113 rappor::RapporService* BackgroundSyncControllerImpl::GetRapporService() { | 124 rappor::RapporService* BackgroundSyncControllerImpl::GetRapporService() { |
| 114 return g_browser_process->rappor_service(); | 125 return g_browser_process->rappor_service(); |
| 115 } | 126 } |
| OLD | NEW |