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/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/ui/app_list/app_list_util.h" | 21 #include "chrome/browser/ui/app_list/app_list_util.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/channel_info.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
| 26 #include "components/version_info/version_info.h" |
26 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
27 #include "net/base/url_util.h" | 28 #include "net/base/url_util.h" |
28 #include "ui/base/device_form_factor.h" | 29 #include "ui/base/device_form_factor.h" |
29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
30 | 31 |
31 using base::UserMetricsAction; | 32 using base::UserMetricsAction; |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 const int kDefaultGroupSize = 100; | 36 const int kDefaultGroupSize = 100; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 #endif | 80 #endif |
80 } | 81 } |
81 | 82 |
82 // Returns a string suitable for the Promo Server URL 'dist' value. | 83 // Returns a string suitable for the Promo Server URL 'dist' value. |
83 const char* ChannelString() { | 84 const char* ChannelString() { |
84 #if defined (OS_WIN) | 85 #if defined (OS_WIN) |
85 // GetChannel hits the registry on Windows. See http://crbug.com/70898. | 86 // GetChannel hits the registry on Windows. See http://crbug.com/70898. |
86 // TODO(achuith): Move NotificationPromo::PromoServerURL to the blocking pool. | 87 // TODO(achuith): Move NotificationPromo::PromoServerURL to the blocking pool. |
87 base::ThreadRestrictions::ScopedAllowIO allow_io; | 88 base::ThreadRestrictions::ScopedAllowIO allow_io; |
88 #endif | 89 #endif |
89 const version_info::Channel channel = | 90 const version_info::Channel channel = chrome::GetChannel(); |
90 chrome::VersionInfo::GetChannel(); | |
91 switch (channel) { | 91 switch (channel) { |
92 case version_info::Channel::CANARY: | 92 case version_info::Channel::CANARY: |
93 return "canary"; | 93 return "canary"; |
94 case version_info::Channel::DEV: | 94 case version_info::Channel::DEV: |
95 return "dev"; | 95 return "dev"; |
96 case version_info::Channel::BETA: | 96 case version_info::Channel::BETA: |
97 return "beta"; | 97 return "beta"; |
98 case version_info::Channel::STABLE: | 98 case version_info::Channel::STABLE: |
99 return "stable"; | 99 return "stable"; |
100 default: | 100 default: |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 const base::Time last_view_time = base::Time::FromDoubleT(first_view_time_) + | 463 const base::Time last_view_time = base::Time::FromDoubleT(first_view_time_) + |
464 base::TimeDelta::FromSeconds(max_seconds_); | 464 base::TimeDelta::FromSeconds(max_seconds_); |
465 return last_view_time < base::Time::Now(); | 465 return last_view_time < base::Time::Now(); |
466 } | 466 } |
467 | 467 |
468 // static | 468 // static |
469 GURL NotificationPromo::PromoServerURL() { | 469 GURL NotificationPromo::PromoServerURL() { |
470 GURL url(promo_server_url); | 470 GURL url(promo_server_url); |
471 AppendQueryParameter(&url, "dist", ChannelString()); | 471 AppendQueryParameter(&url, "dist", ChannelString()); |
472 AppendQueryParameter(&url, "osname", PlatformString()); | 472 AppendQueryParameter(&url, "osname", PlatformString()); |
473 AppendQueryParameter(&url, "branding", chrome::VersionInfo().Version()); | 473 AppendQueryParameter(&url, "branding", version_info::GetVersionNumber()); |
474 AppendQueryParameter(&url, "osver", base::SysInfo::OperatingSystemVersion()); | 474 AppendQueryParameter(&url, "osver", base::SysInfo::OperatingSystemVersion()); |
475 DVLOG(1) << "PromoServerURL=" << url.spec(); | 475 DVLOG(1) << "PromoServerURL=" << url.spec(); |
476 // Note that locale param is added by WebResourceService. | 476 // Note that locale param is added by WebResourceService. |
477 return url; | 477 return url; |
478 } | 478 } |
479 | 479 |
480 double NotificationPromo::StartTimeForGroup() const { | 480 double NotificationPromo::StartTimeForGroup() const { |
481 if (group_ < initial_segment_) | 481 if (group_ < initial_segment_) |
482 return start_; | 482 return start_; |
483 return start_ + | 483 return start_ + |
484 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 484 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
485 * time_slice_; | 485 * time_slice_; |
486 } | 486 } |
487 | 487 |
488 double NotificationPromo::EndTime() const { | 488 double NotificationPromo::EndTime() const { |
489 return end_; | 489 return end_; |
490 } | 490 } |
OLD | NEW |