Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: components/physical_web/data_source/fake_physical_web_data_source.cc

Issue 2643453002: Replace deprecated calls to GetMetadata in Physical Web Zine provider (Closed)
Patch Set: changes for vitaliii@ Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/physical_web/data_source/fake_physical_web_data_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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<Metadata> 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 const std::string& group_id,
21 int scan_timestamp, 21 int scan_timestamp,
22 const std::string& title, 22 const std::string& title,
23 const std::string& description, 23 const std::string& description,
24 const std::string& scanned_url) { 24 const std::string& scanned_url) {
25 auto page = base::MakeUnique<DictionaryValue>(); 25 auto page = base::MakeUnique<Metadata>();
26 page->SetString(kScannedUrlKey, scanned_url); 26 page->resolved_url = GURL(resolved_url);
27 page->SetDouble(kDistanceEstimateKey, distance_estimate); 27 page->distance_estimate = distance_estimate;
28 page->SetString(kGroupIdKey, group_id); 28 page->group_id = group_id;
29 // TODO(crbug.com/667722): Remove this integer workaround once timestamp is 29 page->scan_timestamp = base::Time::FromJavaTime(scan_timestamp);
30 // fixed. 30 page->title = title;
31 page->SetInteger(kScanTimestampKey, scan_timestamp); 31 page->description = description;
32 page->SetString(kResolvedUrlKey, resolved_url); 32 page->scanned_url = GURL(scanned_url);
33 page->SetString(kTitleKey, title);
34 page->SetString(kDescriptionKey, description);
35 return page; 33 return page;
36 } 34 }
37 35
38 std::unique_ptr<DictionaryValue> CreateDummyPhysicalWebPage(int id, 36 std::unique_ptr<Metadata> CreateDummyPhysicalWebPage(int id,
39 double distance, 37 double distance,
40 int timestamp) { 38 int timestamp) {
41 const std::string id_string = base::IntToString(id); 39 const std::string id_string = base::IntToString(id);
42 return CreatePhysicalWebPage("https://resolved_url.com/" + id_string, 40 return CreatePhysicalWebPage("https://resolved_url.com/" + id_string,
43 distance, /*group_id=*/std::string(), timestamp, 41 distance, /*group_id=*/std::string(), timestamp,
44 "title " + id_string, "description " + id_string, 42 "title " + id_string, "description " + id_string,
45 "https://scanned_url.com/" + id_string); 43 "https://scanned_url.com/" + id_string);
46 } 44 }
47 45
48 std::unique_ptr<ListValue> CreateDummyPhysicalWebPages( 46 std::unique_ptr<MetadataList> CreateDummyPhysicalWebPages(
49 const std::vector<int>& ids) { 47 const std::vector<int>& ids) {
50 int distance = 1; 48 int distance = 1;
51 int timestamp = static_cast<int>(ids.size()); 49 int timestamp = static_cast<int>(ids.size());
52 auto list = base::MakeUnique<ListValue>(); 50 auto list = base::MakeUnique<MetadataList>();
53 for (int id : ids) { 51 for (int id : ids) {
54 list->Append(CreateDummyPhysicalWebPage(id, distance, timestamp)); 52 std::unique_ptr<Metadata> page =
53 CreateDummyPhysicalWebPage(id, distance, timestamp);
54 list->push_back(*page);
55 ++distance; 55 ++distance;
56 --timestamp; 56 --timestamp;
57 } 57 }
58 return list; 58 return list;
59 } 59 }
60 60
61 FakePhysicalWebDataSource::FakePhysicalWebDataSource() 61 FakePhysicalWebDataSource::FakePhysicalWebDataSource()
62 : metadata_(base::MakeUnique<ListValue>()) {} 62 : metadata_(base::MakeUnique<base::ListValue>()) {}
63 63
64 FakePhysicalWebDataSource::~FakePhysicalWebDataSource() = default; 64 FakePhysicalWebDataSource::~FakePhysicalWebDataSource() = default;
65 65
66 void FakePhysicalWebDataSource::StartDiscovery(bool network_request_enabled) { 66 void FakePhysicalWebDataSource::StartDiscovery(bool network_request_enabled) {
67 // Ignored. 67 // Ignored.
68 } 68 }
69 69
70 void FakePhysicalWebDataSource::StopDiscovery() { 70 void FakePhysicalWebDataSource::StopDiscovery() {
71 // Ignored. 71 // Ignored.
72 } 72 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 void FakePhysicalWebDataSource::NotifyOnDistanceChanged( 116 void FakePhysicalWebDataSource::NotifyOnDistanceChanged(
117 const GURL& url, 117 const GURL& url,
118 double distance_estimate) { 118 double distance_estimate) {
119 for (PhysicalWebListener& observer : observer_list_) 119 for (PhysicalWebListener& observer : observer_list_)
120 observer.OnDistanceChanged(url, distance_estimate); 120 observer.OnDistanceChanged(url, distance_estimate);
121 } 121 }
122 122
123 } // namespace physical_web 123 } // namespace physical_web
OLDNEW
« no previous file with comments | « components/physical_web/data_source/fake_physical_web_data_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698