OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_resource/notification_promo.h" | 5 #include "chrome/browser/web_resource/notification_promo.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/prefs/pref_registry_simple.h" | 19 #include "chrome/browser/prefs/pref_registry_simple.h" |
| 20 #include "chrome/browser/prefs/pref_registry_syncable.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/prefs/pref_service_syncable.h" | |
22 #include "chrome/browser/web_resource/promo_resource_service.h" | 22 #include "chrome/browser/web_resource/promo_resource_service.h" |
23 #include "chrome/common/chrome_version_info.h" | 23 #include "chrome/common/chrome_version_info.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
27 #include "net/base/url_util.h" | 27 #include "net/base/url_util.h" |
28 | 28 |
29 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
30 #include "base/command_line.h" | 30 #include "base/command_line.h" |
31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 group_ = base::RandInt(0, num_groups_ - 1); | 308 group_ = base::RandInt(0, num_groups_ - 1); |
309 WritePrefs(); | 309 WritePrefs(); |
310 } | 310 } |
311 | 311 |
312 // static | 312 // static |
313 void NotificationPromo::RegisterPrefs(PrefRegistrySimple* registry) { | 313 void NotificationPromo::RegisterPrefs(PrefRegistrySimple* registry) { |
314 registry->RegisterDictionaryPref(kPrefPromoObject); | 314 registry->RegisterDictionaryPref(kPrefPromoObject); |
315 } | 315 } |
316 | 316 |
317 // static | 317 // static |
318 void NotificationPromo::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 318 void NotificationPromo::RegisterUserPrefs(PrefService* prefs, |
| 319 PrefRegistrySyncable* registry) { |
319 // TODO(dbeam): Remove in M28 when we're reasonably sure all prefs are gone. | 320 // TODO(dbeam): Remove in M28 when we're reasonably sure all prefs are gone. |
320 // http://crbug.com/168887 | 321 // http://crbug.com/168887 |
321 prefs->RegisterDictionaryPref(kPrefPromoObject, | 322 // TODO(joi): Remove PrefService parameter; move this to migration code. |
322 PrefServiceSyncable::UNSYNCABLE_PREF); | 323 registry->RegisterDictionaryPref(kPrefPromoObject, |
| 324 PrefRegistrySyncable::UNSYNCABLE_PREF); |
323 prefs->ClearPref(kPrefPromoObject); | 325 prefs->ClearPref(kPrefPromoObject); |
324 } | 326 } |
325 | 327 |
326 void NotificationPromo::WritePrefs() { | 328 void NotificationPromo::WritePrefs() { |
327 base::DictionaryValue* ntp_promo = new base::DictionaryValue; | 329 base::DictionaryValue* ntp_promo = new base::DictionaryValue; |
328 ntp_promo->SetString(kPrefPromoText, promo_text_); | 330 ntp_promo->SetString(kPrefPromoText, promo_text_); |
329 ntp_promo->Set(kPrefPromoPayload, promo_payload_->DeepCopy()); | 331 ntp_promo->Set(kPrefPromoPayload, promo_payload_->DeepCopy()); |
330 ntp_promo->SetDouble(kPrefPromoStart, start_); | 332 ntp_promo->SetDouble(kPrefPromoStart, start_); |
331 ntp_promo->SetDouble(kPrefPromoEnd, end_); | 333 ntp_promo->SetDouble(kPrefPromoEnd, end_); |
332 | 334 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 if (group_ < initial_segment_) | 446 if (group_ < initial_segment_) |
445 return start_; | 447 return start_; |
446 return start_ + | 448 return start_ + |
447 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 449 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
448 * time_slice_; | 450 * time_slice_; |
449 } | 451 } |
450 | 452 |
451 double NotificationPromo::EndTime() const { | 453 double NotificationPromo::EndTime() const { |
452 return end_; | 454 return end_; |
453 } | 455 } |
OLD | NEW |