| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/banners/app_banner_settings_helper.h" | 5 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 base::ListValue* could_show_list = nullptr; | 347 base::ListValue* could_show_list = nullptr; |
| 348 if (!app_dict->GetList(event_key, &could_show_list)) { | 348 if (!app_dict->GetList(event_key, &could_show_list)) { |
| 349 could_show_list = new base::ListValue(); | 349 could_show_list = new base::ListValue(); |
| 350 app_dict->Set(event_key, base::WrapUnique(could_show_list)); | 350 app_dict->Set(event_key, base::WrapUnique(could_show_list)); |
| 351 } | 351 } |
| 352 | 352 |
| 353 // Trim any items that are older than we should care about. For comparisons | 353 // Trim any items that are older than we should care about. For comparisons |
| 354 // the times are converted to local dates. | 354 // the times are converted to local dates. |
| 355 base::Time date = BucketTimeToResolution(time, gMinimumMinutesBetweenVisits); | 355 base::Time date = BucketTimeToResolution(time, gMinimumMinutesBetweenVisits); |
| 356 for (auto it = could_show_list->begin(); it != could_show_list->end();) { | 356 for (auto it = could_show_list->begin(); it != could_show_list->end();) { |
| 357 if ((*it)->IsType(base::Value::TYPE_DICTIONARY)) { | 357 if ((*it)->IsType(base::Value::Type::DICTIONARY)) { |
| 358 base::DictionaryValue* internal_value; | 358 base::DictionaryValue* internal_value; |
| 359 double internal_date; | 359 double internal_date; |
| 360 (*it)->GetAsDictionary(&internal_value); | 360 (*it)->GetAsDictionary(&internal_value); |
| 361 | 361 |
| 362 if (internal_value->GetDouble(kBannerTimeKey, &internal_date)) { | 362 if (internal_value->GetDouble(kBannerTimeKey, &internal_date)) { |
| 363 base::Time other_date = | 363 base::Time other_date = |
| 364 BucketTimeToResolution(base::Time::FromInternalValue(internal_date), | 364 BucketTimeToResolution(base::Time::FromInternalValue(internal_date), |
| 365 gMinimumMinutesBetweenVisits); | 365 gMinimumMinutesBetweenVisits); |
| 366 if (other_date == date) { | 366 if (other_date == date) { |
| 367 double other_engagement = 0; | 367 double other_engagement = 0; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 GetAppDict(origin_dict.get(), package_name_or_start_url); | 489 GetAppDict(origin_dict.get(), package_name_or_start_url); |
| 490 if (!app_dict) | 490 if (!app_dict) |
| 491 return result; | 491 return result; |
| 492 | 492 |
| 493 std::string event_key(kBannerEventKeys[APP_BANNER_EVENT_COULD_SHOW]); | 493 std::string event_key(kBannerEventKeys[APP_BANNER_EVENT_COULD_SHOW]); |
| 494 base::ListValue* could_show_list = nullptr; | 494 base::ListValue* could_show_list = nullptr; |
| 495 if (!app_dict->GetList(event_key, &could_show_list)) | 495 if (!app_dict->GetList(event_key, &could_show_list)) |
| 496 return result; | 496 return result; |
| 497 | 497 |
| 498 for (const auto& value : *could_show_list) { | 498 for (const auto& value : *could_show_list) { |
| 499 if (value->IsType(base::Value::TYPE_DICTIONARY)) { | 499 if (value->IsType(base::Value::Type::DICTIONARY)) { |
| 500 base::DictionaryValue* internal_value; | 500 base::DictionaryValue* internal_value; |
| 501 double internal_date = 0; | 501 double internal_date = 0; |
| 502 value->GetAsDictionary(&internal_value); | 502 value->GetAsDictionary(&internal_value); |
| 503 double engagement = 0; | 503 double engagement = 0; |
| 504 | 504 |
| 505 if (internal_value->GetDouble(kBannerTimeKey, &internal_date) && | 505 if (internal_value->GetDouble(kBannerTimeKey, &internal_date) && |
| 506 internal_value->GetDouble(kBannerEngagementKey, &engagement)) { | 506 internal_value->GetDouble(kBannerEngagementKey, &engagement)) { |
| 507 base::Time date = base::Time::FromInternalValue(internal_date); | 507 base::Time date = base::Time::FromInternalValue(internal_date); |
| 508 result.push_back({date, engagement}); | 508 result.push_back({date, engagement}); |
| 509 } | 509 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 GetOriginDict(settings, origin_url); | 574 GetOriginDict(settings, origin_url); |
| 575 | 575 |
| 576 if (!origin_dict) | 576 if (!origin_dict) |
| 577 return false; | 577 return false; |
| 578 | 578 |
| 579 // Iterate over everything in the content setting, which should be a set of | 579 // Iterate over everything in the content setting, which should be a set of |
| 580 // dictionaries per app path. If we find one that has been added to | 580 // dictionaries per app path. If we find one that has been added to |
| 581 // homescreen recently, return true. | 581 // homescreen recently, return true. |
| 582 for (base::DictionaryValue::Iterator it(*origin_dict); !it.IsAtEnd(); | 582 for (base::DictionaryValue::Iterator it(*origin_dict); !it.IsAtEnd(); |
| 583 it.Advance()) { | 583 it.Advance()) { |
| 584 if (it.value().IsType(base::Value::TYPE_DICTIONARY)) { | 584 if (it.value().IsType(base::Value::Type::DICTIONARY)) { |
| 585 const base::DictionaryValue* value; | 585 const base::DictionaryValue* value; |
| 586 it.value().GetAsDictionary(&value); | 586 it.value().GetAsDictionary(&value); |
| 587 | 587 |
| 588 std::string event_key( | 588 std::string event_key( |
| 589 kBannerEventKeys[APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN]); | 589 kBannerEventKeys[APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN]); |
| 590 double internal_time; | 590 double internal_time; |
| 591 if (it.key() == kInstantAppsKey || | 591 if (it.key() == kInstantAppsKey || |
| 592 !value->GetDouble(event_key, &internal_time)) { | 592 !value->GetDouble(event_key, &internal_time)) { |
| 593 continue; | 593 continue; |
| 594 } | 594 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 return true; | 696 return true; |
| 697 } | 697 } |
| 698 | 698 |
| 699 // Assume any value which is not "0" or "false" indicates that we should use | 699 // Assume any value which is not "0" or "false" indicates that we should use |
| 700 // site engagement. | 700 // site engagement. |
| 701 std::string param = variations::GetVariationParamValue( | 701 std::string param = variations::GetVariationParamValue( |
| 702 kBannerParamsKey, kBannerSiteEngagementParamsKey); | 702 kBannerParamsKey, kBannerSiteEngagementParamsKey); |
| 703 | 703 |
| 704 return (!param.empty() && param != "0" && param != "false"); | 704 return (!param.empty() && param != "0" && param != "false"); |
| 705 } | 705 } |
| OLD | NEW |