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 "ui/base/device_form_factor.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 #if defined(OS_ANDROID) | |
30 #include "base/command_line.h" | |
31 #include "chrome/common/chrome_switches.h" | |
32 #endif // defined(OS_ANDROID) | |
33 | |
34 using content::UserMetricsAction; | 30 using content::UserMetricsAction; |
35 | 31 |
36 namespace { | 32 namespace { |
37 | 33 |
38 const int kDefaultGroupSize = 100; | 34 const int kDefaultGroupSize = 100; |
39 | 35 |
40 const char promo_server_url[] = "https://clients3.google.com/crsignal/client"; | 36 const char promo_server_url[] = "https://clients3.google.com/crsignal/client"; |
41 | 37 |
42 // The name of the preference that stores the promotion object. | 38 // The name of the preference that stores the promotion object. |
43 const char kPrefPromoObject[] = "promo"; | 39 const char kPrefPromoObject[] = "promo"; |
(...skipping 12 matching lines...) Expand all Loading... |
56 const char kPrefPromoGroup[] = "group"; | 52 const char kPrefPromoGroup[] = "group"; |
57 const char kPrefPromoViews[] = "views"; | 53 const char kPrefPromoViews[] = "views"; |
58 const char kPrefPromoClosed[] = "closed"; | 54 const char kPrefPromoClosed[] = "closed"; |
59 | 55 |
60 // Returns a string suitable for the Promo Server URL 'osname' value. | 56 // Returns a string suitable for the Promo Server URL 'osname' value. |
61 std::string PlatformString() { | 57 std::string PlatformString() { |
62 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
63 return "win"; | 59 return "win"; |
64 #elif defined(OS_IOS) | 60 #elif defined(OS_IOS) |
65 // TODO(noyau): add iOS-specific implementation | 61 // TODO(noyau): add iOS-specific implementation |
66 const bool isTablet = false; | 62 DeviceFormFactor form_factor = GetDeviceFormFactor(); |
67 return std::string("ios-") + (isTablet ? "tablet" : "phone"); | 63 return std::string("ios-") + |
| 64 (form_factor == DEVICE_FORM_FACTOR_TABLET ? "tablet" : "phone"); |
68 #elif defined(OS_MACOSX) | 65 #elif defined(OS_MACOSX) |
69 return "mac"; | 66 return "mac"; |
70 #elif defined(OS_CHROMEOS) | 67 #elif defined(OS_CHROMEOS) |
71 return "chromeos"; | 68 return "chromeos"; |
72 #elif defined(OS_LINUX) | 69 #elif defined(OS_LINUX) |
73 return "linux"; | 70 return "linux"; |
74 #elif defined(OS_ANDROID) | 71 #elif defined(OS_ANDROID) |
75 const bool isTablet = | 72 DeviceFormFactor form_factor = GetDeviceFormFactor(); |
76 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTabletUI); | 73 return (std::string("android-") + |
77 return std::string("android-") + (isTablet ? "tablet" : "phone"); | 74 (form_factor == DEVICE_FORM_FACTOR_TABLET ? "tablet" : "phone")); |
78 #else | 75 #else |
79 return "none"; | 76 return "none"; |
80 #endif | 77 #endif |
81 } | 78 } |
82 | 79 |
83 // Returns a string suitable for the Promo Server URL 'dist' value. | 80 // Returns a string suitable for the Promo Server URL 'dist' value. |
84 const char* ChannelString() { | 81 const char* ChannelString() { |
85 #if defined (OS_WIN) | 82 #if defined (OS_WIN) |
86 // GetChannel hits the registry on Windows. See http://crbug.com/70898. | 83 // GetChannel hits the registry on Windows. See http://crbug.com/70898. |
87 // TODO(achuith): Move NotificationPromo::PromoServerURL to the blocking pool. | 84 // 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_) | 461 if (group_ < initial_segment_) |
465 return start_; | 462 return start_; |
466 return start_ + | 463 return start_ + |
467 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 464 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
468 * time_slice_; | 465 * time_slice_; |
469 } | 466 } |
470 | 467 |
471 double NotificationPromo::EndTime() const { | 468 double NotificationPromo::EndTime() const { |
472 return end_; | 469 return end_; |
473 } | 470 } |
OLD | NEW |