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/web_resource/promo_resource_service.h" | 21 #include "chrome/browser/web_resource/promo_resource_service.h" |
22 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "components/user_prefs/pref_registry_syncable.h" | 24 #include "components/user_prefs/pref_registry_syncable.h" |
25 #include "content/public/browser/user_metrics.h" | 25 #include "content/public/browser/user_metrics.h" |
26 #include "net/base/url_util.h" | 26 #include "net/base/url_util.h" |
27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
28 | 28 |
29 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
Alexei Svitkine (slow)
2013/10/31 14:52:32
Same comment as for device_info.cc.
yao
2013/11/01 14:37:59
Done.
| |
30 #include "base/command_line.h" | 30 #include "chrome/common/device_form_factor.h" |
31 #include "chrome/common/chrome_switches.h" | |
32 #endif // defined(OS_ANDROID) | 31 #endif // defined(OS_ANDROID) |
33 | 32 |
34 using content::UserMetricsAction; | 33 using content::UserMetricsAction; |
35 | 34 |
36 namespace { | 35 namespace { |
37 | 36 |
38 const int kDefaultGroupSize = 100; | 37 const int kDefaultGroupSize = 100; |
39 | 38 |
40 const char promo_server_url[] = "https://clients3.google.com/crsignal/client"; | 39 const char promo_server_url[] = "https://clients3.google.com/crsignal/client"; |
41 | 40 |
(...skipping 13 matching lines...) Expand all Loading... | |
55 const char kPrefPromoMaxViews[] = "max_views"; | 54 const char kPrefPromoMaxViews[] = "max_views"; |
56 const char kPrefPromoGroup[] = "group"; | 55 const char kPrefPromoGroup[] = "group"; |
57 const char kPrefPromoViews[] = "views"; | 56 const char kPrefPromoViews[] = "views"; |
58 const char kPrefPromoClosed[] = "closed"; | 57 const char kPrefPromoClosed[] = "closed"; |
59 | 58 |
60 // Returns a string suitable for the Promo Server URL 'osname' value. | 59 // Returns a string suitable for the Promo Server URL 'osname' value. |
61 std::string PlatformString() { | 60 std::string PlatformString() { |
62 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
63 return "win"; | 62 return "win"; |
64 #elif defined(OS_IOS) | 63 #elif defined(OS_IOS) |
65 // TODO(noyau): add iOS-specific implementation | 64 // TODO(noyau): add iOS-specific implementation |
Alexei Svitkine (slow)
2013/10/31 14:52:32
Nit: Address this TODO using the new API.
yao
2013/11/01 14:37:59
Done.
| |
66 const bool isTablet = false; | 65 const bool isTablet = false; |
67 return std::string("ios-") + (isTablet ? "tablet" : "phone"); | 66 return std::string("ios-") + (isTablet ? "tablet" : "phone"); |
68 #elif defined(OS_MACOSX) | 67 #elif defined(OS_MACOSX) |
69 return "mac"; | 68 return "mac"; |
70 #elif defined(OS_CHROMEOS) | 69 #elif defined(OS_CHROMEOS) |
71 return "chromeos"; | 70 return "chromeos"; |
72 #elif defined(OS_LINUX) | 71 #elif defined(OS_LINUX) |
73 return "linux"; | 72 return "linux"; |
74 #elif defined(OS_ANDROID) | 73 #elif defined(OS_ANDROID) |
75 const bool isTablet = | 74 DeviceFormFactor device = GetDeviceFormFactor(); |
Alexei Svitkine (slow)
2013/10/31 14:52:32
Nit: remove to |form_factor|.
yao
2013/11/01 14:37:59
Done.
| |
76 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTabletUI); | 75 return (std::string("android-") + |
77 return std::string("android-") + (isTablet ? "tablet" : "phone"); | 76 (device == DEVICE_FORM_FACTOR_TABLET? "tablet" : "phone")); |
Alexei Svitkine (slow)
2013/10/31 14:52:32
Nit: Space before ?
yao
2013/11/01 14:37:59
Done.
| |
78 #else | 77 #else |
79 return "none"; | 78 return "none"; |
80 #endif | 79 #endif |
81 } | 80 } |
82 | 81 |
83 // Returns a string suitable for the Promo Server URL 'dist' value. | 82 // Returns a string suitable for the Promo Server URL 'dist' value. |
84 const char* ChannelString() { | 83 const char* ChannelString() { |
85 #if defined (OS_WIN) | 84 #if defined (OS_WIN) |
86 // GetChannel hits the registry on Windows. See http://crbug.com/70898. | 85 // GetChannel hits the registry on Windows. See http://crbug.com/70898. |
87 // TODO(achuith): Move NotificationPromo::PromoServerURL to the blocking pool. | 86 // TODO(achuith): Move NotificationPromo::PromoServerURL to the blocking pool. |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 if (group_ < initial_segment_) | 463 if (group_ < initial_segment_) |
465 return start_; | 464 return start_; |
466 return start_ + | 465 return start_ + |
467 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 466 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
468 * time_slice_; | 467 * time_slice_; |
469 } | 468 } |
470 | 469 |
471 double NotificationPromo::EndTime() const { | 470 double NotificationPromo::EndTime() const { |
472 return end_; | 471 return end_; |
473 } | 472 } |
OLD | NEW |