| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/physical_web/data_source/fake_physical_web_data_source.h" | 5 #include "components/physical_web/data_source/fake_physical_web_data_source.h" |
| 6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "components/physical_web/data_source/physical_web_listener.h" | 9 #include "components/physical_web/data_source/physical_web_listener.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| 11 | 11 |
| 12 using base::ListValue; | 12 using base::ListValue; |
| 13 using base::DictionaryValue; | 13 using base::DictionaryValue; |
| 14 | 14 |
| 15 namespace physical_web { | 15 namespace physical_web { |
| 16 | 16 |
| 17 std::unique_ptr<DictionaryValue> CreatePhysicalWebPage( | 17 std::unique_ptr<DictionaryValue> CreatePhysicalWebPage( |
| 18 const std::string& resolved_url, | 18 const std::string& resolved_url, |
| 19 double distance_estimate, | 19 double distance_estimate, |
| 20 const std::string& group_id, |
| 20 int scan_timestamp, | 21 int scan_timestamp, |
| 21 const std::string& title, | 22 const std::string& title, |
| 22 const std::string& description, | 23 const std::string& description, |
| 23 const std::string& scanned_url) { | 24 const std::string& scanned_url) { |
| 24 auto page = base::MakeUnique<DictionaryValue>(); | 25 auto page = base::MakeUnique<DictionaryValue>(); |
| 25 page->SetString(kScannedUrlKey, scanned_url); | 26 page->SetString(kScannedUrlKey, scanned_url); |
| 26 page->SetDouble(kDistanceEstimateKey, distance_estimate); | 27 page->SetDouble(kDistanceEstimateKey, distance_estimate); |
| 28 page->SetString(kGroupIdKey, group_id); |
| 27 // TODO(crbug.com/667722): Remove this integer workaround once timestamp is | 29 // TODO(crbug.com/667722): Remove this integer workaround once timestamp is |
| 28 // fixed. | 30 // fixed. |
| 29 page->SetInteger(kScanTimestampKey, scan_timestamp); | 31 page->SetInteger(kScanTimestampKey, scan_timestamp); |
| 30 page->SetString(kResolvedUrlKey, resolved_url); | 32 page->SetString(kResolvedUrlKey, resolved_url); |
| 31 page->SetString(kTitleKey, title); | 33 page->SetString(kTitleKey, title); |
| 32 page->SetString(kDescriptionKey, description); | 34 page->SetString(kDescriptionKey, description); |
| 33 return page; | 35 return page; |
| 34 } | 36 } |
| 35 | 37 |
| 36 std::unique_ptr<DictionaryValue> CreateDummyPhysicalWebPage(int id, | 38 std::unique_ptr<DictionaryValue> CreateDummyPhysicalWebPage(int id, |
| 37 double distance, | 39 double distance, |
| 38 int timestamp) { | 40 int timestamp) { |
| 39 const std::string id_string = base::IntToString(id); | 41 const std::string id_string = base::IntToString(id); |
| 40 return CreatePhysicalWebPage("https://resolved_url.com/" + id_string, | 42 return CreatePhysicalWebPage("https://resolved_url.com/" + id_string, |
| 41 distance, timestamp, "title " + id_string, | 43 distance, /*group_id=*/std::string(), timestamp, |
| 42 "description " + id_string, | 44 "title " + id_string, "description " + id_string, |
| 43 "https://scanned_url.com/" + id_string); | 45 "https://scanned_url.com/" + id_string); |
| 44 } | 46 } |
| 45 | 47 |
| 46 std::unique_ptr<ListValue> CreateDummyPhysicalWebPages( | 48 std::unique_ptr<ListValue> CreateDummyPhysicalWebPages( |
| 47 const std::vector<int>& ids) { | 49 const std::vector<int>& ids) { |
| 48 int distance = 1; | 50 int distance = 1; |
| 49 int timestamp = static_cast<int>(ids.size()); | 51 int timestamp = static_cast<int>(ids.size()); |
| 50 auto list = base::MakeUnique<ListValue>(); | 52 auto list = base::MakeUnique<ListValue>(); |
| 51 for (int id : ids) { | 53 for (int id : ids) { |
| 52 list->Append(CreateDummyPhysicalWebPage(id, distance, timestamp)); | 54 list->Append(CreateDummyPhysicalWebPage(id, distance, timestamp)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 114 } |
| 113 | 115 |
| 114 void FakePhysicalWebDataSource::NotifyOnDistanceChanged( | 116 void FakePhysicalWebDataSource::NotifyOnDistanceChanged( |
| 115 const GURL& url, | 117 const GURL& url, |
| 116 double distance_estimate) { | 118 double distance_estimate) { |
| 117 for (PhysicalWebListener& observer : observer_list_) | 119 for (PhysicalWebListener& observer : observer_list_) |
| 118 observer.OnDistanceChanged(url, distance_estimate); | 120 observer.OnDistanceChanged(url, distance_estimate); |
| 119 } | 121 } |
| 120 | 122 |
| 121 } // namespace physical_web | 123 } // namespace physical_web |
| OLD | NEW |