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

Side by Side Diff: components/ntp_snippets/ntp_snippet.cc

Issue 2110393004: Parse snippet times properly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | components/ntp_snippets/ntp_snippet_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/ntp_snippets/ntp_snippet.h" 5 #include "components/ntp_snippets/ntp_snippet.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "components/ntp_snippets/content_suggestion.h" 11 #include "components/ntp_snippets/content_suggestion.h"
12 #include "components/ntp_snippets/content_suggestion_category.h" 12 #include "components/ntp_snippets/content_suggestion_category.h"
13 #include "components/ntp_snippets/content_suggestions_provider_type.h" 13 #include "components/ntp_snippets/content_suggestions_provider_type.h"
14 #include "components/ntp_snippets/proto/ntp_snippets.pb.h" 14 #include "components/ntp_snippets/proto/ntp_snippets.pb.h"
15 15
16 namespace { 16 namespace {
17 17
18 // dict.Get() specialization for base::Time values 18 // dict.Get() specialization for base::Time values
19 bool GetTimeValue(const base::DictionaryValue& dict, 19 bool GetTimeValue(const base::DictionaryValue& dict,
20 const std::string& key, 20 const std::string& key,
21 base::Time* time) { 21 base::Time* time) {
22 const base::DictionaryValue* time_value; 22 std::string time_value;
23 int seconds = 0, nanos = 0; 23 return dict.GetString(key, &time_value) &&
24 if (!(dict.GetDictionary(key, &time_value) && 24 base::Time::FromString(time_value.c_str(), time);
25 time_value->GetInteger("seconds", &seconds) &&
26 time_value->GetInteger("nanos", &nanos))) {
27 return false;
28 }
29 *time = base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(seconds) +
30 base::TimeDelta::FromMicroseconds(nanos / 1000); // No nano support.
31 return true;
32 } 25 }
33 26
34 // dict.Get() specialization for GURL values 27 // dict.Get() specialization for GURL values
35 bool GetURLValue(const base::DictionaryValue& dict, 28 bool GetURLValue(const base::DictionaryValue& dict,
36 const std::string& key, 29 const std::string& key,
37 GURL* url) { 30 GURL* url) {
38 std::string spec; 31 std::string spec;
39 if (!dict.GetString(key, &spec)) { 32 if (!dict.GetString(key, &spec)) {
40 return false; 33 return false;
41 } 34 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 best_source_index_ = i; 291 best_source_index_ = i;
299 if (!source.amp_url.is_empty()) { 292 if (!source.amp_url.is_empty()) {
300 // This is the best possible source, stop looking. 293 // This is the best possible source, stop looking.
301 break; 294 break;
302 } 295 }
303 } 296 }
304 } 297 }
305 } 298 }
306 299
307 } // namespace ntp_snippets 300 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippet_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698