| OLD | NEW |
| 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_snippets_service.h" | 5 #include "components/ntp_snippets/ntp_snippets_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 << snippets_json; | 247 << snippets_json; |
| 248 } | 248 } |
| 249 | 249 |
| 250 void NTPSnippetsService::OnJsonError(const std::string& snippets_json, | 250 void NTPSnippetsService::OnJsonError(const std::string& snippets_json, |
| 251 const std::string& error) { | 251 const std::string& error) { |
| 252 LOG(WARNING) << "Received invalid JSON (" << error << "): " << snippets_json; | 252 LOG(WARNING) << "Received invalid JSON (" << error << "): " << snippets_json; |
| 253 } | 253 } |
| 254 | 254 |
| 255 void NTPSnippetsService::FetchSnippetsImpl( | 255 void NTPSnippetsService::FetchSnippetsImpl( |
| 256 const std::vector<std::string>& hosts) { | 256 const std::vector<std::string>& hosts) { |
| 257 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 258 switches::kDontRestrict)) { |
| 259 snippets_fetcher_->FetchSnippets(std::vector<std::string>()); |
| 260 return; |
| 261 } |
| 257 if (!hosts.empty()) | 262 if (!hosts.empty()) |
| 258 snippets_fetcher_->FetchSnippets(hosts); | 263 snippets_fetcher_->FetchSnippets(hosts); |
| 259 } | 264 } |
| 260 | 265 |
| 261 bool NTPSnippetsService::LoadFromValue(const base::Value& value) { | 266 bool NTPSnippetsService::LoadFromValue(const base::Value& value) { |
| 262 const base::DictionaryValue* top_dict = nullptr; | 267 const base::DictionaryValue* top_dict = nullptr; |
| 263 if (!value.GetAsDictionary(&top_dict)) | 268 if (!value.GetAsDictionary(&top_dict)) |
| 264 return false; | 269 return false; |
| 265 | 270 |
| 266 const base::ListValue* list = nullptr; | 271 const base::ListValue* list = nullptr; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 if (snippet->expiry_date() < next_expiry) | 379 if (snippet->expiry_date() < next_expiry) |
| 375 next_expiry = snippet->expiry_date(); | 380 next_expiry = snippet->expiry_date(); |
| 376 } | 381 } |
| 377 DCHECK_GT(next_expiry, expiry); | 382 DCHECK_GT(next_expiry, expiry); |
| 378 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, | 383 expiry_timer_.Start(FROM_HERE, next_expiry - expiry, |
| 379 base::Bind(&NTPSnippetsService::RemoveExpiredSnippets, | 384 base::Bind(&NTPSnippetsService::RemoveExpiredSnippets, |
| 380 base::Unretained(this))); | 385 base::Unretained(this))); |
| 381 } | 386 } |
| 382 | 387 |
| 383 } // namespace ntp_snippets | 388 } // namespace ntp_snippets |
| OLD | NEW |