OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/app_list/search/people/person.h" | 5 #include "chrome/browser/ui/app_list/search/people/person.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 namespace app_list { | 63 namespace app_list { |
64 | 64 |
65 // static | 65 // static |
66 scoped_ptr<Person> Person::Create(const base::DictionaryValue& dict) { | 66 scoped_ptr<Person> Person::Create(const base::DictionaryValue& dict) { |
67 scoped_ptr<Person> person(new Person()); | 67 scoped_ptr<Person> person(new Person()); |
68 | 68 |
69 // Person id's. | 69 // Person id's. |
70 if (!dict.GetString(kKeyId, &person->id) || | 70 if (!dict.GetString(kKeyId, &person->id) || |
71 !dict.GetString(kKeyOwnerId, &person->owner_id)) { | 71 !dict.GetString(kKeyOwnerId, &person->owner_id)) { |
72 person.reset(); | 72 person.reset(); |
73 return person.Pass(); | 73 return person; |
74 } | 74 } |
75 | 75 |
76 // Interaction rank. | 76 // Interaction rank. |
77 std::string interaction_rank_string; | 77 std::string interaction_rank_string; |
78 if (!dict.GetString(kKeyInteractionRank, &interaction_rank_string) || | 78 if (!dict.GetString(kKeyInteractionRank, &interaction_rank_string) || |
79 !base::StringToDouble( | 79 !base::StringToDouble( |
80 interaction_rank_string, &person->interaction_rank)) { | 80 interaction_rank_string, &person->interaction_rank)) { |
81 person.reset(); | 81 person.reset(); |
82 return person.Pass(); | 82 return person; |
83 } | 83 } |
84 | 84 |
85 person->display_name = GetTargetValue(dict, kKeyNames, kKeyDisplayName); | 85 person->display_name = GetTargetValue(dict, kKeyNames, kKeyDisplayName); |
86 person->email = GetTargetValue(dict, kKeyEmails, kKeyEmailValue); | 86 person->email = GetTargetValue(dict, kKeyEmails, kKeyEmailValue); |
87 person->image_url = GURL(GetTargetValue(dict, kKeyImages, kKeyUrl)); | 87 person->image_url = GURL(GetTargetValue(dict, kKeyImages, kKeyUrl)); |
88 | 88 |
89 // If any of our values are invalid, null out our result. | 89 // If any of our values are invalid, null out our result. |
90 if (person->id.empty() || | 90 if (person->id.empty() || |
91 person->owner_id.empty() || | 91 person->owner_id.empty() || |
92 person->display_name.empty() || | 92 person->display_name.empty() || |
93 person->email.empty() || | 93 person->email.empty() || |
94 !person->image_url.is_valid() || | 94 !person->image_url.is_valid() || |
95 person->interaction_rank == 0.0) { | 95 person->interaction_rank == 0.0) { |
96 person.reset(); | 96 person.reset(); |
97 } | 97 } |
98 | 98 |
99 return person.Pass(); | 99 return person; |
100 } | 100 } |
101 | 101 |
102 Person::Person() : interaction_rank(0.0) { | 102 Person::Person() : interaction_rank(0.0) { |
103 } | 103 } |
104 | 104 |
105 Person::~Person() { | 105 Person::~Person() { |
106 } | 106 } |
107 | 107 |
108 scoped_ptr<Person> Person::Duplicate() { | 108 scoped_ptr<Person> Person::Duplicate() { |
109 scoped_ptr<Person> person(new Person()); | 109 scoped_ptr<Person> person(new Person()); |
110 *person = *this; | 110 *person = *this; |
111 return person.Pass(); | 111 return person; |
112 } | 112 } |
113 | 113 |
114 } // namespace app_list | 114 } // namespace app_list |
OLD | NEW |