| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/settings/cros_settings.h" | 5 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const std::string& path, | 193 const std::string& path, |
| 194 const base::DictionaryValue** out_value) const { | 194 const base::DictionaryValue** out_value) const { |
| 195 DCHECK(CalledOnValidThread()); | 195 DCHECK(CalledOnValidThread()); |
| 196 const base::Value* value = GetPref(path); | 196 const base::Value* value = GetPref(path); |
| 197 if (value) | 197 if (value) |
| 198 return value->GetAsDictionary(out_value); | 198 return value->GetAsDictionary(out_value); |
| 199 return false; | 199 return false; |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool CrosSettings::FindEmailInList(const std::string& path, | 202 bool CrosSettings::FindEmailInList(const std::string& path, |
| 203 const std::string& email) const { | 203 const std::string& email, |
| 204 bool* wildcard_match) const { |
| 204 DCHECK(CalledOnValidThread()); | 205 DCHECK(CalledOnValidThread()); |
| 205 std::string canonicalized_email( | 206 std::string canonicalized_email( |
| 206 gaia::CanonicalizeEmail(gaia::SanitizeEmail(email))); | 207 gaia::CanonicalizeEmail(gaia::SanitizeEmail(email))); |
| 207 std::string wildcard_email; | 208 std::string wildcard_email; |
| 208 std::string::size_type at_pos = canonicalized_email.find('@'); | 209 std::string::size_type at_pos = canonicalized_email.find('@'); |
| 209 if (at_pos != std::string::npos) { | 210 if (at_pos != std::string::npos) { |
| 210 wildcard_email = | 211 wildcard_email = |
| 211 std::string("*").append(canonicalized_email.substr(at_pos)); | 212 std::string("*").append(canonicalized_email.substr(at_pos)); |
| 212 } | 213 } |
| 213 | 214 |
| 215 if (wildcard_match) |
| 216 *wildcard_match = false; |
| 217 |
| 214 const base::ListValue* list; | 218 const base::ListValue* list; |
| 215 if (!GetList(path, &list)) | 219 if (!GetList(path, &list)) |
| 216 return false; | 220 return false; |
| 221 |
| 222 bool found_wildcard_match = false; |
| 217 for (base::ListValue::const_iterator entry(list->begin()); | 223 for (base::ListValue::const_iterator entry(list->begin()); |
| 218 entry != list->end(); | 224 entry != list->end(); |
| 219 ++entry) { | 225 ++entry) { |
| 220 std::string entry_string; | 226 std::string entry_string; |
| 221 if (!(*entry)->GetAsString(&entry_string)) { | 227 if (!(*entry)->GetAsString(&entry_string)) { |
| 222 NOTREACHED(); | 228 NOTREACHED(); |
| 223 continue; | 229 continue; |
| 224 } | 230 } |
| 225 std::string canonicalized_entry( | 231 std::string canonicalized_entry( |
| 226 gaia::CanonicalizeEmail(gaia::SanitizeEmail(entry_string))); | 232 gaia::CanonicalizeEmail(gaia::SanitizeEmail(entry_string))); |
| 227 | 233 |
| 228 if (canonicalized_entry == canonicalized_email || | 234 if (canonicalized_entry == canonicalized_email) |
| 229 canonicalized_entry == wildcard_email) { | |
| 230 return true; | 235 return true; |
| 231 } | 236 |
| 237 // If there is a wildcard match, don't exit early. There might be an exact |
| 238 // match further down the list that should take precedence if present. |
| 239 if (canonicalized_entry == wildcard_email) |
| 240 found_wildcard_match = true; |
| 232 } | 241 } |
| 233 return false; | 242 |
| 243 if (wildcard_match) |
| 244 *wildcard_match = found_wildcard_match; |
| 245 |
| 246 return found_wildcard_match; |
| 234 } | 247 } |
| 235 | 248 |
| 236 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { | 249 bool CrosSettings::AddSettingsProvider(CrosSettingsProvider* provider) { |
| 237 DCHECK(CalledOnValidThread()); | 250 DCHECK(CalledOnValidThread()); |
| 238 providers_.push_back(provider); | 251 providers_.push_back(provider); |
| 239 | 252 |
| 240 // Allow the provider to notify this object when settings have changed. | 253 // Allow the provider to notify this object when settings have changed. |
| 241 // Providers instantiated inside this class will have the same callback | 254 // Providers instantiated inside this class will have the same callback |
| 242 // passed to their constructor, but doing it here allows for providers | 255 // passed to their constructor, but doing it here allows for providers |
| 243 // to be instantiated outside this class. | 256 // to be instantiated outside this class. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 319 |
| 307 ScopedTestCrosSettings::ScopedTestCrosSettings() { | 320 ScopedTestCrosSettings::ScopedTestCrosSettings() { |
| 308 CrosSettings::Initialize(); | 321 CrosSettings::Initialize(); |
| 309 } | 322 } |
| 310 | 323 |
| 311 ScopedTestCrosSettings::~ScopedTestCrosSettings() { | 324 ScopedTestCrosSettings::~ScopedTestCrosSettings() { |
| 312 CrosSettings::Shutdown(); | 325 CrosSettings::Shutdown(); |
| 313 } | 326 } |
| 314 | 327 |
| 315 } // namespace chromeos | 328 } // namespace chromeos |
| OLD | NEW |