| 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 10 matching lines...) Expand all Loading... |
| 54 const char kPrefPromoIncrementMax[] = "increment_max"; | 50 const char kPrefPromoIncrementMax[] = "increment_max"; |
| 55 const char kPrefPromoMaxViews[] = "max_views"; | 51 const char kPrefPromoMaxViews[] = "max_views"; |
| 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"; |
| 60 #elif defined(OS_ANDROID) |
| 61 ui::DeviceFormFactor form_factor = ui::GetDeviceFormFactor(); |
| 62 return std::string("android-") + |
| 63 (form_factor == ui::DEVICE_FORM_FACTOR_TABLET ? "tablet" : "phone"); |
| 64 #elif defined(OS_IOS) | 64 #elif defined(OS_IOS) |
| 65 // TODO(noyau): add iOS-specific implementation | 65 ui::DeviceFormFactor form_factor = ui::GetDeviceFormFactor(); |
| 66 const bool isTablet = false; | 66 return std::string("ios-") + |
| 67 return std::string("ios-") + (isTablet ? "tablet" : "phone"); | 67 (form_factor == ui::DEVICE_FORM_FACTOR_TABLET ? "tablet" : "phone"); |
| 68 #elif defined(OS_MACOSX) | 68 #elif defined(OS_MACOSX) |
| 69 return "mac"; | 69 return "mac"; |
| 70 #elif defined(OS_CHROMEOS) | 70 #elif defined(OS_CHROMEOS) |
| 71 return "chromeos"; | 71 return "chromeos"; |
| 72 #elif defined(OS_LINUX) | 72 #elif defined(OS_LINUX) |
| 73 return "linux"; | 73 return "linux"; |
| 74 #elif defined(OS_ANDROID) | |
| 75 const bool isTablet = | |
| 76 CommandLine::ForCurrentProcess()->HasSwitch(switches::kTabletUI); | |
| 77 return std::string("android-") + (isTablet ? "tablet" : "phone"); | |
| 78 #else | 74 #else |
| 79 return "none"; | 75 return "none"; |
| 80 #endif | 76 #endif |
| 81 } | 77 } |
| 82 | 78 |
| 83 // Returns a string suitable for the Promo Server URL 'dist' value. | 79 // Returns a string suitable for the Promo Server URL 'dist' value. |
| 84 const char* ChannelString() { | 80 const char* ChannelString() { |
| 85 #if defined (OS_WIN) | 81 #if defined (OS_WIN) |
| 86 // GetChannel hits the registry on Windows. See http://crbug.com/70898. | 82 // GetChannel hits the registry on Windows. See http://crbug.com/70898. |
| 87 // TODO(achuith): Move NotificationPromo::PromoServerURL to the blocking pool. | 83 // 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_) | 460 if (group_ < initial_segment_) |
| 465 return start_; | 461 return start_; |
| 466 return start_ + | 462 return start_ + |
| 467 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) | 463 std::ceil(static_cast<float>(group_ - initial_segment_ + 1) / increment_) |
| 468 * time_slice_; | 464 * time_slice_; |
| 469 } | 465 } |
| 470 | 466 |
| 471 double NotificationPromo::EndTime() const { | 467 double NotificationPromo::EndTime() const { |
| 472 return end_; | 468 return end_; |
| 473 } | 469 } |
| OLD | NEW |